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.

181 lines
5.2 KiB

  1. namespace UDDI.Diagnostics
  2. {
  3. using System;
  4. using System.Diagnostics;
  5. using System.Collections;
  6. using System.Text;
  7. /// <summary>
  8. /// This class provides support for publication of all of the
  9. /// UDDI performance counters
  10. /// </summary>
  11. public class Performance
  12. {
  13. //
  14. // suffix use to identify average base counters
  15. //
  16. private static string BaseSuffix = "b";
  17. public Performance()
  18. {
  19. }
  20. public static void DeleteCounters()
  21. {
  22. PerformanceCounterCategory.Delete( "UDDI.API.Times" );
  23. PerformanceCounterCategory.Delete( "UDDI.API.Counts" );
  24. }
  25. public static void InitializeCounters()
  26. {
  27. if( !PerformanceCounterCategory.Exists( "UDDI.API.Times" ) )
  28. {
  29. //
  30. // Create performance counters to measure the duration of message calls.
  31. //
  32. CounterCreationDataCollection times = new CounterCreationDataCollection();
  33. foreach( string messageName in MessageNames.Names )
  34. {
  35. AddAverageTimesCounter( ref times, messageName );
  36. }
  37. PerformanceCounterCategory.Create( "UDDI.API.Times", "UDDI.API.Times.Category.Help", times );
  38. }
  39. if( !PerformanceCounterCategory.Exists( "UDDI.API.Counts" ) )
  40. {
  41. //
  42. // Create performance counters to measure the number of times each message is called.
  43. //
  44. CounterCreationDataCollection counts = new CounterCreationDataCollection();
  45. foreach( string messageName in MessageNames.Names )
  46. {
  47. AddCumulativeAccessCountCounter(ref counts, messageName);
  48. }
  49. PerformanceCounterCategory.Create( "UDDI.API.Counts", "UDDI.API.Counts.Category.Help", counts );
  50. }
  51. }
  52. public static void PublishMessageData( string name, TimeSpan duration )
  53. {
  54. PerformanceCounter pc = new PerformanceCounter( "UDDI.API.Counts", name, false );
  55. pc.Increment();
  56. //
  57. // The milliseconds value is a double, IncrementBy accepts a long check to
  58. // avoid casting errors
  59. //
  60. if( duration.TotalMilliseconds <= long.MaxValue )
  61. {
  62. PerformanceCounter pcduration = new PerformanceCounter( "UDDI.API.Times", name, false );
  63. pcduration.IncrementBy( (long) duration.TotalMilliseconds );
  64. //
  65. // The RawFraction counter type multiplies by 100 to generate a percentage; we don't
  66. // want this, so increment by 100 to offset.
  67. //
  68. PerformanceCounter pcdurationbase = new PerformanceCounter( "UDDI.API.Times", name + BaseSuffix, false );
  69. pcdurationbase.IncrementBy( 100 );
  70. }
  71. }
  72. private static void AddAverageTimesCounter(ref CounterCreationDataCollection counters, string name)
  73. {
  74. string helpstr = string.Format( Localization.GetString( "AVERAGE_DURATION_COUNT_HELP" ), name );
  75. string avgstr = string.Format( Localization.GetString( "AVERAGE_DURATION_COUNT_BASE" ), name );
  76. CounterCreationData newCounter = new CounterCreationData( name,
  77. helpstr,
  78. PerformanceCounterType.RawFraction );
  79. CounterCreationData baseCounter = new CounterCreationData( name + BaseSuffix,
  80. avgstr,
  81. PerformanceCounterType.RawBase );
  82. //
  83. // RawFraction counter types must be followed by their corresponding base counter type in list of counters added to CounterCreationDataCollection.
  84. //
  85. counters.Add( newCounter );
  86. counters.Add( baseCounter );
  87. }
  88. private static void AddCumulativeAccessCountCounter(ref CounterCreationDataCollection counters, string name)
  89. {
  90. string helpstr = string.Format( Localization.GetString( "CUMULATIVE_ACCESS_COUNT_HELP" ), name );
  91. CounterCreationData newCounter = new CounterCreationData( name,
  92. helpstr,
  93. PerformanceCounterType.NumberOfItems64 );
  94. counters.Add( newCounter );
  95. }
  96. //
  97. // TODO: This class should probably go somewhere else. API is a likely choice, but do we want Core to have
  98. // a dependency on API?
  99. //
  100. // We can't, it would be a cyclical reference.
  101. //
  102. // SOAP message names. V2 API messages were added as part of bug# 1388
  103. //
  104. class MessageNames
  105. {
  106. public static string[] Names =
  107. {
  108. //
  109. // Inquire message names
  110. //
  111. "find_binding",
  112. "find_business",
  113. "find_relatedBusinesses",
  114. "find_service",
  115. "find_tModel",
  116. "get_bindingDetail",
  117. "get_businessDetail",
  118. "get_businessDetailExt",
  119. "get_serviceDetail",
  120. "get_tModelDetail",
  121. "validate_categorization",
  122. //
  123. // Publish message types
  124. //
  125. "add_publisherAssertions",
  126. "delete_binding",
  127. "delete_business",
  128. "delete_publisherAssertions",
  129. "delete_service",
  130. "delete_tModel",
  131. "discard_authToken",
  132. "get_assertionStatusReport",
  133. "get_authToken",
  134. "get_publisherAssertions",
  135. "get_registeredInfo",
  136. "save_binding",
  137. "save_business",
  138. "save_service",
  139. "save_tModel",
  140. "set_publisherAssertions",
  141. //
  142. // Replication message types
  143. //
  144. "get_changeRecords",
  145. "notify_changeRecordsAvailable",
  146. "do_ping",
  147. "get_highWaterMarks",
  148. //
  149. // MS Extensions
  150. //
  151. "get_relatedCategories"
  152. };
  153. }
  154. }
  155. }