{"record":{"id":"7d179b21df0b0cea","repo":"dotnet/BenchmarkDotNet","slug":"sampling-interval-change-is-not-supported","errorCode":null,"errorMessage":"Sampling interval change is not supported!","messagePattern":"Sampling interval change is not supported!","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet.Diagnostics.Windows/Tracing/TraceLogParser.cs","lineNumber":76,"sourceCode":"        private void OnOverheadActualStop(IterationEvent obj) => HandleIterationEvent(obj.ProcessID, obj.TimeStampRelativeMSec, IterationMode.Overhead, obj.TotalOperations);\n\n        private void OnWorkloadActualStart(IterationEvent obj) => HandleIterationEvent(obj.ProcessID, obj.TimeStampRelativeMSec, IterationMode.Workload, obj.TotalOperations);\n\n        private void OnWorkloadActualStop(IterationEvent obj) => HandleIterationEvent(obj.ProcessID, obj.TimeStampRelativeMSec, IterationMode.Workload, obj.TotalOperations);\n\n        private void HandleIterationEvent(int processId, double timeStampRelative, IterationMode iterationMode, long totalOperations)\n        {\n            // if given process emits Benchmarking events it's the process that we care about\n            if (!processIdToData.ContainsKey(processId))\n                processIdToData.Add(processId, new ProcessMetrics());\n\n            processIdToData[processId].HandleIterationEvent(timeStampRelative, iterationMode, totalOperations);\n        }\n\n        private void OnPmcIntervalChange(SampledProfileIntervalTraceData data)\n        {\n            if (profileSourceIdToInterval.TryGetValue(data.SampleSource, out int storedInterval) && storedInterval != data.NewInterval)\n                throw new NotSupportedException(\"Sampling interval change is not supported!\");\n\n            profileSourceIdToInterval[data.SampleSource] = data.NewInterval;\n        }\n\n        private void OnPmcEvent(PMCCounterProfTraceData data)\n        {\n            // if given process did not emit Benchmarking events before, we don't care about it\n            if (!processIdToData.ContainsKey(data.ProcessID))\n                return;\n\n            processIdToData[data.ProcessID].HandleNewSample(data.TimeStampRelativeMSec, data.InstructionPointer, data.ProfileSource);\n        }\n    }\n\n    public class ProcessMetrics\n    {\n        private readonly List<double> overheadTimestamps = new List<double>(20);\n        private readonly List<double> workloadTimestamps = new List<double>(20);","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet.Diagnostics.Windows/Tracing/TraceLogParser.cs#L58-L94","documentation":"Thrown by TraceLogParser.OnPmcIntervalChange when an ETW Precise Machine Counter (PMC) profile source reports a new sampling interval that differs from the one recorded earlier in the same run. The Windows ETW PMC diagnoser assumes a fixed per-counter interval for the whole run so it can normalize sample counts; a mid-run change makes the math invalid.","triggerScenarios":"Using the HardwareCounters / ETW PMC diagnoser on Windows while the OS, firmware, or another profiler rescales the PMU sample interval mid-capture. Triggered inside OnPmcIntervalChange(SampledProfileIntervalTraceData) when profileSourceIdToInterval[data.SampleSource] already holds a value != data.NewInterval.","commonSituations":"Running another sampling profiler (PerfView, VTune, xperf) concurrently; aggressive CPU power-management (throttling) on a laptop/server that retunes PMU config; running under a VM with passthrough PMU virtualization that reconfigures counters; very long benchmark runs that span a power-state transition.","solutions":["Disable other profiling/tracing tools (PerfView, VTune, dotTrace sampling) while the benchmark runs.","Pin CPU frequency and disable turbo/C-states in power settings (powercfg) so the PMU interval stays constant.","Run on bare metal instead of a virtualized environment that virtualizes the PMU.","Reduce the number of PMC counters requested so the OS does not re-balance them mid-run."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"// NotSupportedException from OnPmcIntervalChange is fatal for the run; surface to the user:\ntry { /* run PMC diagnoser */ }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Sampling interval\"))\n{\n    log.Error($\"PMC interval changed mid-run; rerun on bare metal without competing profilers. {ex.Message}\");\n}","preventionTips":["Run benchmarks with PMC counters on bare metal, not in a VM with virtualized PMU.","Stop PerfView/VTune/xperf before running BDN with HardwareCounters.","Pin CPU frequency and disable C-states/turbo to keep the PMU interval stable."],"tags":["benchmarkdotnet","windows","etw","pmc","hardware-counters","tracing"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}