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.

213 lines
6.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: index.cxx
  7. //
  8. // Contents: Methods used by all indexes.
  9. //
  10. // Classes: CIndex
  11. //
  12. // History: 06-Mar-91 KyleP Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include "index.hxx"
  18. #include "stat.hxx"
  19. #if DEVL == 1
  20. #define INPTR pfOut
  21. #define DEB_PRINTF( x ) fprintf x
  22. #endif
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Member: CIndex::DebugDump, public
  26. //
  27. // Synopsis: Formatted dump of CWordList contents.
  28. //
  29. // Arguments: [pfOut] -- File to dump data to.
  30. //
  31. // Requires: The AddEntry method cannot be called after DebugDump.
  32. //
  33. // Derivation: From base class CIndex, Always override in subclasses.
  34. //
  35. // History: 07-Mar-91 KyleP Created.
  36. // 27-Oct-93 DwightKr Increased size of PopularKeys so
  37. // that prop filtering could be tested
  38. //
  39. // Notes: This interface should at some point be changed to accept
  40. // a stream and write the contents of the CWordList to the
  41. // stream. Since C7 does not yet provide a stream interface
  42. // I'll just print to stdout (Ugh!);
  43. //
  44. //----------------------------------------------------------------------------
  45. void CIndex::DebugDump(FILE *pfOut, ULONG fSummaryOnly )
  46. {
  47. #if CIDBG == 1
  48. const CKeyBuf * pkey;
  49. CKeyCursor * pcur = QueryCursor();
  50. TRY
  51. {
  52. CStat KeyDelta;
  53. CStat WidCount;
  54. CStat OccCount;
  55. CKeyBuf LastKey;
  56. static ULONG aBucket[] = { 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 64,
  57. 96, 128, 192, 256, 284, 512, 768,
  58. 1024, 1536, 2048, 3072, 4096, 6144,
  59. 8192, 12288, 16384, 24576, 32768 };
  60. CDistrib WidDistrib( sizeof(aBucket) / sizeof(ULONG),
  61. 1,
  62. aBucket );
  63. CDistrib OccDistrib( sizeof(aBucket) / sizeof(ULONG),
  64. 1,
  65. aBucket );
  66. LastKey.SetCount(0);
  67. CPopularKeys PopularKeys(50);
  68. CPopularKeys BigOccKeys(50);
  69. int const cWidsToTrack = 50;
  70. CPopularKeys widKeys[ cWidsToTrack + 1 ];
  71. ciDebugOut(( DEB_ITRACE, "Scan on letter: " ));
  72. WCHAR FirstLetter = '@';
  73. for (pkey = pcur->GetKey(); pkey != NULL; pkey = pcur->GetNextKey())
  74. {
  75. //
  76. // Calculate the common prefix from the previous key.
  77. //
  78. UINT cPrefix;
  79. UINT mincb = __min( LastKey.Count(), pkey->Count() );
  80. for ( cPrefix = 0;
  81. (cPrefix < mincb) &&
  82. ((LastKey.GetBuf())[cPrefix] == pkey->GetBuf()[cPrefix]);
  83. cPrefix++ )
  84. continue; // NULL body
  85. UINT cSuffix = pkey->Count() - cPrefix;
  86. LastKey = *pkey;
  87. if ( cPrefix > 15 || cSuffix > 15 )
  88. cSuffix += 3; // 0 byte + prefix + suffix
  89. else
  90. cSuffix += 1; // prefix/suffix byte
  91. KeyDelta.Add( cSuffix );
  92. WidCount.Add( pcur->WorkIdCount() );
  93. WidDistrib.Add( pcur->WorkIdCount() );
  94. PopularKeys.Add( *pkey, pcur->WorkIdCount() );
  95. if ( *(pkey->GetStr()) != FirstLetter )
  96. {
  97. FirstLetter = *(pkey->GetStr());
  98. ciDebugOut (( DEB_NOCOMPNAME | DEB_ITRACE, "%c",
  99. FirstLetter ));
  100. }
  101. if ( !fSummaryOnly )
  102. {
  103. DEB_PRINTF((INPTR, "Key: "));
  104. DEB_PRINTF((INPTR, "%.*ws -- ", pkey->StrLen(), pkey->GetStr()));
  105. DEB_PRINTF((INPTR, " (PID = %lx)", pkey->Pid()));
  106. DEB_PRINTF((INPTR, " (CWID = %ld)\n", pcur->WorkIdCount()));
  107. }
  108. for (WORKID wid = pcur->WorkId();
  109. wid != widInvalid;
  110. wid = pcur->NextWorkId())
  111. {
  112. OccCount.Add( pcur->OccurrenceCount() );
  113. OccDistrib.Add( pcur->OccurrenceCount() );
  114. BigOccKeys.Add( *pkey, pcur->OccurrenceCount() );
  115. if ( wid <= cWidsToTrack )
  116. widKeys[wid].Add( *pkey, pcur->Rank() );
  117. if ( !fSummaryOnly )
  118. {
  119. DEB_PRINTF((INPTR, " (WID = %lx) ", wid));
  120. DEB_PRINTF((INPTR, "(COCC = %ld)\n\t",
  121. pcur->OccurrenceCount()));
  122. int i = 1;
  123. for (OCCURRENCE occ = pcur->Occurrence();
  124. occ != OCC_INVALID;
  125. occ = pcur->NextOccurrence(), i++ )
  126. {
  127. DEB_PRINTF((INPTR, " %6ld", occ));
  128. if ( i % 10 == 0 )
  129. {
  130. DEB_PRINTF((INPTR, "\n\t"));
  131. }
  132. }
  133. DEB_PRINTF((INPTR, "\n"));
  134. }
  135. }
  136. if ( !fSummaryOnly )
  137. {
  138. DEB_PRINTF((INPTR, "\n"));
  139. }
  140. }
  141. //
  142. // Print stats
  143. //
  144. KeyDelta.Print( pfOut, "Key size", 1, 1 );
  145. WidCount.Print( pfOut, "Wid count", 0, 1 );
  146. OccCount.Print( pfOut, "Occ count", 0, 1 );
  147. DEB_PRINTF(( INPTR, "\nMost popular keys (high work id count):\n\n" ));
  148. PopularKeys.Print( pfOut );
  149. DEB_PRINTF(( INPTR, "\nMost popular keys (high occurrence count):\n\n" ));
  150. BigOccKeys.Print( pfOut );
  151. DEB_PRINTF(( INPTR, "\n\nWorkid count distribution:\n\n" ));
  152. WidDistrib.Print( pfOut );
  153. DEB_PRINTF(( INPTR, "\n\nOccurrence count distribution:\n\n" ));
  154. OccDistrib.Print( pfOut );
  155. ciDebugOut (( DEB_NOCOMPNAME | DEB_ITRACE, "\n" ));
  156. for ( int i = 1; i <= cWidsToTrack; i++ )
  157. {
  158. DEB_PRINTF(( INPTR, "\n\nWid %u:\n", i ));
  159. widKeys[i].Print( pfOut );
  160. }
  161. }
  162. CATCH(CException, e)
  163. {
  164. delete pcur;
  165. RETHROW();
  166. }
  167. END_CATCH
  168. delete pcur;
  169. #endif // CIDBG == 1
  170. }