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.

126 lines
3.2 KiB

  1. //
  2. // Systrack - System resource tracking
  3. // Copyright (c) Microsoft Corporation, 1997
  4. //
  5. //
  6. // module: memory.cxx
  7. // author: silviuc
  8. // created: Fri Nov 20 19:41:38 1998
  9. //
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <stdarg.h>
  13. #include <time.h>
  14. extern "C" {
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. }
  19. #include <windows.h>
  20. #include "assert.hxx"
  21. #include "history.hxx"
  22. #include "table.hxx"
  23. #include "memory.hxx"
  24. #include "systrack.hxx"
  25. void TrackPerformanceCounter (
  26. char * Name,
  27. ULONG Id,
  28. ULONG Period,
  29. LONG Delta)
  30. {
  31. PSYSTEM_PERFORMANCE_INFORMATION Info;
  32. History<ULONG_PTR, 60> History;
  33. for ( ; ; )
  34. {
  35. //
  36. // SystemPerformanceInformation
  37. //
  38. Info = (PSYSTEM_PERFORMANCE_INFORMATION)QuerySystemPerformanceInformation();
  39. switch (Id) {
  40. case TRACK_AVAILABLE_PAGES: History.Add (Info->AvailablePages); break;
  41. case TRACK_COMMITTED_PAGES: History.Add (Info->CommittedPages); break;
  42. case TRACK_COMMIT_LIMIT: History.Add (Info->CommitLimit); break;
  43. case TRACK_PAGE_FAULT_COUNT: History.Add (Info->PageFaultCount); break;
  44. case TRACK_SYSTEM_CALLS: History.Add (Info->SystemCalls); break;
  45. case TRACK_TOTAL_SYSTEM_DRIVER_PAGES: History.Add (Info->TotalSystemDriverPages); break;
  46. case TRACK_TOTAL_SYSTEM_CODE_PAGES: History.Add (Info->TotalSystemCodePages); break;
  47. default: printf ("Invalid track performance Id \n"); exit (2); break;
  48. }
  49. if (Delta < 0) {
  50. //
  51. // We are looking for decreasing counters
  52. //
  53. if ((History.Last() < History.First()) &&
  54. ( (int)History.First() - (int)History.Last() > -Delta)) {
  55. printf ("%s: %u -%u \n",
  56. Name,
  57. History.Last(),
  58. History.First() - History.Last());
  59. fflush( stdout );
  60. DebugMessage ("systrack: %s: %u -%d \n",
  61. Name,
  62. History.Last(),
  63. History.First() - History.Last());
  64. History.Reset (History.Last ());
  65. }
  66. }
  67. else {
  68. //
  69. // We are looking for increasing counters
  70. //
  71. if ((History.Last() > History.First()) &&
  72. ( (int)History.Last() - (int)History.First() > Delta)) {
  73. printf ("%s: %u +%u \n",
  74. Name,
  75. History.Last(),
  76. History.Last() - History.First());
  77. fflush( stdout );
  78. DebugMessage ("systrack: %s: %u +%d \n",
  79. Name,
  80. History.Last(),
  81. History.Last() - History.First());
  82. History.Reset (History.Last ());
  83. }
  84. }
  85. //
  86. // Sleep a little bit.
  87. //
  88. Sleep (Period);
  89. }
  90. }
  91. //
  92. // end of module: memory.cxx
  93. //