public void BasicCalipersRunningTest(string relativePath) { var expectedCompletionSeconds = 45; var expectedCompletionTime = DateTime.UtcNow.AddSeconds(expectedCompletionSeconds); var sourcePath = Path.Combine(Environment.CurrentDirectory, relativePath); var destPath = Path.Combine(Path.GetTempPath(), nameof(BasicCalipersRunningTest) + ".zip"); File.Copy(sourcePath, destPath, true); using (var tj = new TraceJob(destPath)) { tj.StageForProcessing(); tj.RegisterCaliperByType<CpuSampled>(null); tj.RegisterCaliperByType<BootPhase>(); tj.RegisterProcessorByType<WinlogonSubscriberProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); tj.RegisterProcessorByType<GroupPolicyActionProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); tj.RegisterProcessorByType<DiskIoProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); tj.RegisterProcessorByType<NetworkInterfaceProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); tj.RegisterProcessorByType<ProcessLifetimeProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); //tj.RegisterProcessorByType<BootPhaseProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); tj.RegisterProcessorByType<SystemSleepProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); tj.RegisterProcessorByType<ServiceTransitionProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); tj.RegisterProcessorByType<NetworkInterfaceProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); tj.RegisterProcessorByType<DiskProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); var t = tj.Measure(); Assert.NotNull(t); Assert.True(expectedCompletionTime > DateTime.UtcNow); Assert.NotEmpty(t.GetMeasurements<IMeasurement>()); Assert.NotEmpty(t.GetMeasurements<WinlogonSubscriberTask>()); Assert.NotEmpty(t.GetMeasurements<GroupPolicyAction>()); Assert.NotEmpty(t.GetMeasurements<DiskIo>()); Assert.NotEmpty(t.GetMeasurements<MeasureTrace.TraceModel.CpuSampled>()); Assert.NotEmpty(t.GetMeasurements<ProcessLifetime>()); Assert.NotEmpty(t.GetMeasurements<MeasureTrace.TraceModel.BootPhase>()); Assert.NotEmpty(t.GetMeasurements<ServiceTransition>()); Assert.NotEmpty(t.GetMeasurements<TerminalSession>()); Assert.NotEmpty(t.GetMeasurements<NetworkInterface>()); Assert.NotEmpty(t.GetMeasurements<PhysicalDisk>()); Assert.NotEmpty(t.GetMeasurements<LogicalDisk>()); Assert.False(t.GetMeasurements<SystemSleep>().Any()); Assert.True(string.Equals(t.PackageFileNameFull, destPath, StringComparison.OrdinalIgnoreCase)); var packageRelName = Path.GetFileName(destPath); Assert.True(string.Equals(t.PackageFileNameFull, destPath, StringComparison.OrdinalIgnoreCase)); Assert.True(string.Equals(Path.GetFileName(t.PackageFileNameFull), packageRelName, StringComparison.OrdinalIgnoreCase)); } }
public void GroupPolicyTest(string relativePath) { var sourcePath = Path.Combine(Environment.CurrentDirectory, relativePath); var destPath = Path.Combine(Path.GetTempPath(), nameof(GroupPolicyTest) + ".zip"); File.Copy(sourcePath, destPath, true); using (var tj = new TraceJob(destPath)) { tj.StageForProcessing(); tj.RegisterProcessorByType<GroupPolicyActionProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); var t = tj.Measure(); Assert.NotNull(t); Assert.NotEmpty(t.GetMeasurements<GroupPolicyAction>()); } }
public void RegisterSecondPass(TraceJob traceJob) { traceJob.RegisterProcessorByType<TerminalSessionProcessor>(ProcessorTypeCollisionOption.UseExistingIfFound); traceJob.OnNewMeasurementOfType<TraceModel.BootPhase>(bp => _alreadyRegisteredBootPhases.Add(bp)); traceJob.OnNewMeasurementOfType<TerminalSession>(ts => { if ( _alreadyRegisteredBootPhases.Any( em => em.BootPhaseType == BootPhaseType.FromLogonUntilDesktopAppears)) return; if (ts.ExplorerProcessId == 0) return; traceJob.PublishMeasurement( new TraceModel.BootPhase { BootPhaseObserver = BootPhaseObserver.MeasureTrace, BootPhaseType = BootPhaseType.FromLogonUntilDesktopAppears, DurationMSec = ts.LogonCredentialEntryToShellReady } ); traceJob.PublishMeasurement( new TraceModel.BootPhase { BootPhaseObserver = BootPhaseObserver.MeasureTrace, BootPhaseType = BootPhaseType.FromPowerOnUntilDesktopAppears, DurationMSec = ts.ShellReadyOffsetMSec } ); }); traceJob.EtwTraceEventSource.Registered.AddCallbackForProviderEvents((pn, en) => { if (!string.Equals(pn, WinlogonProviderName, StringComparison.OrdinalIgnoreCase)) return EventFilterResponse.RejectProvider; return EventFilterResponse.AcceptEvent; }, e => { if ((WinlogonSystemBootEventId == (int) e.ID || WinlogonWelcomeScreenStartId == (int) e.ID) && _countOfPowerOnToReadyForLogon < 1) { _countOfPowerOnToReadyForLogon++; traceJob.PublishMeasurement(new TraceModel.BootPhase { BootPhaseObserver = BootPhaseObserver.MeasureTrace, BootPhaseType = BootPhaseType.FromPowerOnUntilReadyForLogon, DurationMSec = e.TimeStampRelativeMSec }); } }); traceJob.EtwTraceEventSource.Registered.AddCallbackForProviderEvents((pn, en) => { if (!string.Equals(pn, PerfTrackProviderName, StringComparison.OrdinalIgnoreCase)) return EventFilterResponse.RejectProvider; return EventFilterResponse.AcceptEvent; }, e => { if (PerfTrackIdleDetectionInfoEventId == (int) e.ID && _alreadyRegisteredBootPhases.All( bp => bp.BootPhaseType != BootPhaseType.FromDesktopAppearsUntilDesktopResponsive)) { var accumulatedIdleMs = Convert.ToInt32(e.PayloadValue(0)); if (IdleAccumulationCutoffMs > accumulatedIdleMs) return; var postBootEndOffsetMinusAccumulatedIdle = e.TimeStampRelativeMSec - accumulatedIdleMs; var bootToDesktop = _alreadyRegisteredBootPhases.FirstOrDefault( bp => bp.BootPhaseType == BootPhaseType.FromPowerOnUntilDesktopAppears); if (bootToDesktop == null) return; var postBootOnlyRawDurationMs = postBootEndOffsetMinusAccumulatedIdle - bootToDesktop.DurationMSec; var postBootDurationCleaned = CalculateRollOffPostBootValue(postBootOnlyRawDurationMs.Value); var desktopAppearsToDestkopResponsive = new TraceModel.BootPhase { BootPhaseObserver = BootPhaseObserver.MeasureTrace, BootPhaseType = BootPhaseType.FromDesktopAppearsUntilDesktopResponsive, DurationMSec = postBootDurationCleaned }; traceJob.PublishMeasurement(desktopAppearsToDestkopResponsive); traceJob.PublishMeasurement(new TraceModel.BootPhase { BootPhaseObserver = BootPhaseObserver.MeasureTrace, BootPhaseType = BootPhaseType.FromPowerOnUntilDesktopResponsive, DurationMSec = bootToDesktop.DurationMSec + desktopAppearsToDestkopResponsive.DurationMSec }); } }); }