public void Stop() { if (this.isRunning) { long timestamp = MyStopwatch.Timestamp; if (MyStopwatch.CpuTimeIsAvailable) { this.InternalGetElapsedCpuStatus(); } long num = timestamp - this.startTimeStamp; this.elapsed += num; this.isRunning = false; if (this.elapsed < 0L) { this.elapsed = 0L; } if (MyStopwatch.CpuTimeIsAvailable && this.elapsedCPU > 0L) { this.timerEndCPUID = (int)NativeMethods.GetCurrentProcessorNumber(); if (this.timerEndCPUID != this.timerStartCPUID) { this.cpuSwitchOccurred = true; } MyStopwatch.GetCurrentAndMaxMHz(this.timerEndCPUID, out this.timerEndCurrentMHz, out this.timerEndMaxMHz); if (this.timerStartCurrentMHz != this.timerEndCurrentMHz) { this.cpuspeedChangeOccurred = true; } } } }
public static MyStopwatch StartNew() { MyStopwatch myStopwatch = new MyStopwatch(); myStopwatch.Start(); return(myStopwatch); }
private static int GetCurrentMHz(int cpuId) { int result; int num; MyStopwatch.GetCurrentAndMaxMHz(cpuId, out result, out num); return(result); }
internal LatencyDetectionContext(LatencyDetectionLocation location, ContextOptions contextOptions, string version, object hash, params IPerformanceDataProvider[] providers) { this.latencyDetectionLocation = location; this.assemblyVersion = version; this.StackTraceContext = hash; this.contextOptions = contextOptions; if ((contextOptions & ContextOptions.DoNotMeasureTime) == ContextOptions.DoNotMeasureTime) { this.timer = null; } else { this.timer = MyStopwatch.StartNew(); } this.SetDataProviders(providers); }
public void Start() { if (!this.isRunning) { this.startTimeStamp = MyStopwatch.Timestamp; if (MyStopwatch.CpuTimeIsAvailable) { using (SafeThreadHandle currentThread = NativeMethods.GetCurrentThread()) { this.timerStartThreadHandle = currentThread.DangerousGetHandle().ToInt64(); } this.timerStartCPUID = (int)NativeMethods.GetCurrentProcessorNumber(); this.timerStartCurrentMHz = MyStopwatch.GetCurrentMHz(this.timerStartCPUID); this.timerEndCurrentMHz = this.timerStartCurrentMHz; this.startCPUcycles = MyStopwatch.CpuCycles; } this.isRunning = true; } }