Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.7 KiB

  1. //
  2. // tracelog.c
  3. //
  4. // Copyright (c) 1996 FORE Systems, Inc.
  5. // All rights reserved.
  6. //
  7. // THIS SOURCE CODE CONTAINS CONFIDENTIAL INFORMATION THAT IS OWNED BY FORE
  8. // SYSTEMS, INC. AND MAY NOT BE COPIED, DISCLOSED OR OTHERWISE USED WITHOUT
  9. // THE EXPRESS WRITTEN CONSENT OF FORE SYSTEMS, INC.
  10. //
  11. #include <precomp.h>
  12. #include <stdlib.h>
  13. #include <stdarg.h>
  14. #pragma hdrstop
  15. void
  16. InitTraceLog(PTRACELOG TraceLog, unsigned char *Storage,
  17. unsigned long StorageSizeBytes)
  18. {
  19. memset(TraceLog, 0, sizeof(TraceLog));
  20. if (Storage == NULL)
  21. return;
  22. TraceLog->Storage = Storage;
  23. TraceLog->StorageSizeBytes = StorageSizeBytes;
  24. TraceLog->First = (PTRACEENTRY)TraceLog->Storage;
  25. TraceLog->Last =
  26. (PTRACEENTRY) (TraceLog->Storage +
  27. ((TraceLog->StorageSizeBytes / sizeof(TRACEENTRY)) * sizeof(TRACEENTRY)) -
  28. sizeof(TRACEENTRY));
  29. TraceLog->Current = TraceLog->First;
  30. memset(TraceLog->Storage, 0, TraceLog->StorageSizeBytes);
  31. }
  32. void
  33. TraceLogWrite(PTRACELOG TraceLog, unsigned long EventId, ...)
  34. {
  35. PTRACEENTRY TraceEntry;
  36. unsigned long ParamCount;
  37. unsigned long i;
  38. va_list ap;
  39. if (TraceLog->Storage == NULL)
  40. return;
  41. ACQUIRE_GLOBAL_LOCK(pAtmLaneGlobalInfo);
  42. TraceEntry = TraceLog->Current;
  43. ParamCount = TL_GET_PARAM_COUNT(EventId);
  44. memset(TraceEntry, 0, sizeof(TRACEENTRY));
  45. TraceEntry->EventId = EventId;
  46. TraceEntry->Time = AtmLaneSystemTimeMs();
  47. if (ParamCount > 0)
  48. {
  49. va_start(ap, EventId);
  50. for(i = 0; i < ParamCount; i++)
  51. TraceEntry->Params[i] = va_arg(ap, unsigned long);
  52. }
  53. if (TraceLog->Current >= TraceLog->Last)
  54. TraceLog->Current = TraceLog->First;
  55. else
  56. TraceLog->Current++;
  57. RELEASE_GLOBAL_LOCK(pAtmLaneGlobalInfo);
  58. }