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.

131 lines
4.5 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: timer.cxx
  3. *
  4. * For profiling
  5. *
  6. * Warning!
  7. *
  8. * In its present form, this profiler will work only for single
  9. * threads of execution.
  10. *
  11. * Created: 13-Oct-1994 10:01:42
  12. * Author: Kirk Olynyk [kirko]
  13. *
  14. * Copyright (c) 1994-1999 Microsoft Corporation
  15. *
  16. \**************************************************************************/
  17. #include "precomp.hxx"
  18. #if DBG
  19. FLONG TIMER::fl = 0; // set 0'th bit to start timing
  20. char *TIMER::pszRecordingFile = 0; // set to "c:\timer.txt" or whatever
  21. TIMER *TIMER::pCurrent = 0; // don't change this
  22. /******************************Member*Function*****************************\
  23. * TIMER::TIMER *
  24. * *
  25. * History: *
  26. * Fri 14-Oct-1994 06:59:29 by Kirk Olynyk [kirko] *
  27. * Wrote it. *
  28. \**************************************************************************/
  29. TIMER::TIMER(char *psz_)
  30. {
  31. if (fl & TIMER_MEASURE) {
  32. psz = psz_;
  33. pParent = pCurrent;
  34. pCurrent = this;
  35. NtQuerySystemTime((LARGE_INTEGER*)&llTick);
  36. }
  37. }
  38. /******************************Member*Function*****************************\
  39. * TIMER::~TIMER *
  40. * *
  41. * History: *
  42. * Fri 14-Oct-1994 06:59:08 by Kirk Olynyk [kirko] *
  43. * Wrote it. *
  44. \**************************************************************************/
  45. TIMER::~TIMER()
  46. {
  47. if (fl & TIMER_MEASURE) {
  48. if (psz) {
  49. TIMER *p;
  50. CHAR ach[200];
  51. LONGLONG ll;
  52. NtQuerySystemTime((LARGE_INTEGER*)&ll);
  53. // calculate the difference in 0.1 microsecond units
  54. ll -= llTick;
  55. // print the lowest 32 bits of ll -- this limits
  56. // function calls to less than 429 seconds
  57. // this time is placed on the far left of the screen
  58. DbgPrint("%7u\t", (unsigned) ll / 100);
  59. // CHAR *pch = ach + wsprintfA(ach, "%7u\t", (unsigned) ll / 100);
  60. // indent one space for each parent that you have
  61. for (p = pParent; p; p = p->pParent)
  62. DbgPrint(" ");
  63. //*pch++ = ' ';
  64. // write the string after the indentation
  65. DbgPrint(psz);
  66. //pch += wsprintf(pch, "%s\n", psz);
  67. // always write the result to the debugging screen
  68. // DbgPrint("%s", ach);
  69. // if a recording file has been specified then append
  70. // the same string at the end of that file
  71. if (pszRecordingFile) {
  72. HANDLE hf;
  73. ASSERTGDI(FALSE, "Timer Recording File broken for now\n");
  74. // if (
  75. // hf =
  76. // CreateFileA(
  77. // pszRecordingFile
  78. // , GENERIC_WRITE
  79. // , 0
  80. // , 0
  81. // , OPEN_ALWAYS
  82. // , FILE_ATTRIBUTE_NORMAL
  83. // , 0
  84. // )
  85. // ) {
  86. // LONG l = 0;
  87. // SetFilePointer(hf, 0, &l, FILE_END);
  88. // WriteFile(hf, ach, pch - ach, (DWORD*) &l, 0);
  89. // CloseHandle(hf);
  90. // }
  91. }
  92. // before this TIMER dies, change the current pointer
  93. // back to the parent
  94. pCurrent = pParent;
  95. // Put the parent TIMER's to sleep during the time that
  96. // this TIMER was in scope.
  97. // unfortunately this does not compensate the parents
  98. // for the this last little bit of copying .. oh well
  99. NtQuerySystemTime((LARGE_INTEGER*)&ll);
  100. ll -= llTick;
  101. for (p = pParent; p; p = p->pParent)
  102. p->llTick += ll;
  103. }
  104. }
  105. }
  106. #endif