{"record":{"id":"ba2c5c5dadf07a53","repo":"dotnet/BenchmarkDotNet","slug":"totaloperations-is-missing-unable-to-calculate-st","errorCode":null,"errorMessage":"TotalOperations is missing, unable to calculate stats","messagePattern":"TotalOperations is missing, unable to calculate stats","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet.Diagnostics.Windows/Tracing/TraceLogParser.cs","lineNumber":128,"sourceCode":"                    totalOperationsPerIteration = totalOperations;\n                else if (totalOperationsPerIteration.Value != totalOperations)\n                    throw new InvalidOperationException($\"TotalOperations count can't change during the benchmark run! Invalid trace!\");\n\n                workloadTimestamps.Add(timeStamp);\n            }\n        }\n\n        public void HandleNewSample(double timeStamp, ulong instructionPointer, int profileSourceId)\n            => samples.Add((timeStamp, instructionPointer, profileSourceId));\n\n        public IEnumerable<Metric> CalculateMetrics(Dictionary<int, int> profileSourceIdToInterval, PreciseMachineCounter[] counters)\n        {\n            if (overheadTimestamps.Count % 2 != 0)\n                throw new InvalidOperationException(\"One overhead iteration stop event is missing, unable to calculate stats\");\n            if (workloadTimestamps.Count % 2 != 0)\n                throw new InvalidOperationException(\"One workload iteration stop event is missing, unable to calculate stats\");\n            if (!totalOperationsPerIteration.HasValue)\n                throw new InvalidOperationException(\"TotalOperations is missing, unable to calculate stats\");\n\n            var overheadIterations = CreateIterationData(overheadTimestamps);\n            var workloadIterations = CreateIterationData(workloadTimestamps);\n\n            SumCountersPerIterations(profileSourceIdToInterval, workloadIterations, overheadIterations, counters);\n\n            var workloadTotalPerCounter = Sum(workloadIterations);\n            var overheadTotalPerCounter = Sum(overheadIterations);\n\n            return workloadTotalPerCounter.Select(perCounter =>\n            {\n                var pmc = counters.Single(counter => counter.ProfileSourceId == perCounter.Key);\n\n                overheadTotalPerCounter.TryGetValue(perCounter.Key, out var overhead);\n\n                // result = (avg(workload) - avg(overhead))/op\n                double result = perCounter.Value / (double)workloadIterations.Length;\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet.Diagnostics.Windows/Tracing/TraceLogParser.cs#L110-L146","documentation":"CalculateMetrics throws when totalOperationsPerIteration was never set, i.e. the trace contained no Workload iteration events at all. Without the per-iteration operations count the diagnoser cannot convert raw PMC samples into per-operation metrics.","triggerScenarios":"ProcessMetrics received no Workload-mode iteration events before CalculateMetrics ran. Typically means the benchmarked process never emitted Benchmarking ETW events (wrong process attributed), or the trace was captured before/after the workload phase.","commonSituations":"Running the PMC diagnoser against a process that is not the benchmark host; attaching the ETW session to the wrong PID; capturing an empty/partial .etl; the [Benchmark] was filtered out and never executed.","solutions":["Confirm the .etl actually contains the benchmark workload phase for the target process.","Ensure the benchmark is not filtered out and actually runs.","Capture the trace covering the full benchmark run window, not just setup/overhead."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { /* parse trace */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"TotalOperations is missing\"))\n{\n    log.Error(\"Trace has no workload iteration events; capture covered the wrong process/window.\");\n}","preventionTips":["Confirm the .etl actually contains the benchmark workload phase for the right PID.","Ensure the [Benchmark] is not filtered out and actually executes.","Capture the trace over the full run, not just setup/overhead."],"tags":["benchmarkdotnet","windows","etw","pmc","tracing","trace-corruption"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}