Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. [ThreadStatic]
  2. //tracks number of cache hits
  3. internal static int m_TotalHitsForSession;
  4.  
  5. [ThreadStatic]
  6. //tracks total writes
  7. internal static int m_TotalWritesForSession;
  8.  
  9. [ThreadStatic]
  10. //tracks total reads
  11. internal static int m_TotalReadsForSession;
  12.  
  13. cacheCounter1 = new PerformanceCounter();
  14.  
  15. public class PerformanceInfo
  16. {
  17. public static PerformanceInfo Instance { get{ return _instance.Value; } }
  18.  
  19. PerformanceCounter _totalHitsForSessionCounter = new PerformanceCounter("Total Hits",
  20. "Total Hits for this session",
  21. false);
  22.  
  23. [ThreadStatic]
  24. private static readonly Lazy<PerformanceInfo> _instance =
  25. new Lazy<PerformanceInfo>(()=> new PerformanceInfo(), true);
  26.  
  27. private PerformanceInfo() { }
  28.  
  29. private int _m_TotalHitsForSession;
  30. private int _m_TotalWritesForSession;
  31. private int _m_TotalReadsForSession;
  32.  
  33. public int m_TotalHitsForSession
  34. {
  35. get{ return _m_TotalHitsForSession;}
  36. set
  37. {
  38. _m_TotalHitsForSession=value;
  39. _totalHitsForSessionCounter.Increment();
  40.  
  41. }
  42. }
  43.  
  44. public int m_TotalWritesForSession { same as example above}
  45. public int m_TotalReadsForSession { same as example above }
  46.  
  47.  
  48.  
  49. public override ToString()
  50. {
  51. return // detailed Performance Info
  52. }
  53. }
  54.  
  55. PerformanceInfo.Instance.m_TotalWritesForSession++;
  56.  
  57. Console.WriteLine("This Thread had the following Performance");
  58. Console.WriteLine(PerformanceInfo.Instance.ToString());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement