public void NestedCollectorTest() { using (PerformanceCollector collector = new PerformanceCollector(TimeSpan.FromMilliseconds(10))) { using (var aggregator = collector.CreateAggregator()) { // Sleep until we get a sample Stopwatch sw = Stopwatch.StartNew(); while (sw.Elapsed.TotalSeconds < 60 && GetMaxAggregatorCount(aggregator) < 2) { Thread.Sleep(10); } XAssert.IsTrue(GetMaxAggregatorCount(aggregator) > 0, "No samples were collected"); using (var aggregator2 = collector.CreateAggregator()) { Stopwatch sw2 = Stopwatch.StartNew(); while (sw2.Elapsed.TotalSeconds < 1 && GetMaxAggregatorCount(aggregator2) < 2) { Thread.Sleep(10); } XAssert.IsTrue(GetMaxAggregatorCount(aggregator) > GetMaxAggregatorCount(aggregator2), "The nested aggregator should have fewer samples than the earlier created aggregator"); } } } }
private static IFrontEndController TryCreateFrontEndController( FrontEndFactory frontEndFactory, IDecorator <EvaluationResult> decorator, ICommandLineConfiguration configuration, SymbolTable symbolTable, LoggingContext loggingContext, PerformanceCollector collector, bool collectMemoryAsSoonAsPossible, IFrontEndStatistics statistics) { Contract.Requires(frontEndFactory != null && !frontEndFactory.IsSealed); // Statistic should be global for all front-ends, not per an instance. var frontEndStatistics = statistics ?? new FrontEndStatistics(); var sharedModuleRegistry = new ModuleRegistry(symbolTable); // Note, that the following code is absolutely critical for detecting that front-end related objects // are freed successfully after evaluation. // ModuleRegistry was picked intentionally because it holds vast amount of front-end data. FrontEndControllerMemoryObserver.CaptureFrontEndReference(sharedModuleRegistry); frontEndFactory.SetConfigurationProcessor( new ConfigurationProcessor( new FrontEndStatistics(), // Configuration processing is so lightweight that it won't affect overall perf statistics logger: null)); frontEndFactory.AddFrontEnd(new DScriptFrontEnd( frontEndStatistics, evaluationDecorator: decorator)); frontEndFactory.AddFrontEnd(new NugetFrontEnd( frontEndStatistics, evaluationDecorator: decorator)); frontEndFactory.AddFrontEnd(new DownloadFrontEnd()); #if PLATFORM_WIN frontEndFactory.AddFrontEnd(new MsBuildFrontEnd()); frontEndFactory.AddFrontEnd(new NinjaFrontEnd()); frontEndFactory.AddFrontEnd(new CMakeFrontEnd()); frontEndFactory.AddFrontEnd(new RushFrontEnd()); frontEndFactory.AddFrontEnd(new YarnFrontEnd()); frontEndFactory.AddFrontEnd(new LageFrontEnd()); #endif if (!frontEndFactory.TrySeal(loggingContext)) { return(null); } return(new FrontEndHostController( frontEndFactory, evaluationScheduler: EvaluationScheduler.Default, moduleRegistry: sharedModuleRegistry, frontEndStatistics: frontEndStatistics, logger: BuildXL.FrontEnd.Core.Tracing.Logger.CreateLogger(), collector: collector, collectMemoryAsSoonAsPossible: collectMemoryAsSoonAsPossible)); }
public void PerformanceCollectorBadStateTest() { var counters = new PerformanceCounter[] { new PerformanceCounter("Processor", "% Processor Time", "_Total123blabla"), new PerformanceCounter("Processor", "% Processor Time", "_Total") }; IPerformanceCollector collector = new PerformanceCollector(); foreach (var pc in counters) { try { collector.RegisterPerformanceCounter( PerformanceCounterUtility.FormatPerformanceCounter(pc), null, pc.CategoryName, pc.CounterName, pc.InstanceName, false, true); } catch (Exception) { } } Assert.IsTrue(collector.PerformanceCounters.First().IsInBadState); Assert.IsFalse(collector.PerformanceCounters.Last().IsInBadState); }
/// <nodoc/> public Aggregator(PerformanceCollector collector) { m_parent = collector; ProcessCpu = new Aggregation(); ProcessPrivateMB = new Aggregation(); ProcessWorkingSetMB = new Aggregation(); ProcessThreadCount = new Aggregation(); ProcessHeldMB = new Aggregation(); MachineCpu = new Aggregation(); MachineAvailablePhysicalMB = new Aggregation(); MachineTotalPhysicalMB = new Aggregation(); CommitLimitMB = new Aggregation(); CommitUsedMB = new Aggregation(); MachineBandwidth = new Aggregation(); MachineKbitsPerSecSent = new Aggregation(); MachineKbitsPerSecReceived = new Aggregation(); ModifiedPagelistMB = new Aggregation(); StandbyPagelistMB = new Aggregation(); FreePagelistMB = new Aggregation(); List <Tuple <string, Aggregation> > aggs = new List <Tuple <string, Aggregation> >(); List <DiskStatistics> diskStats = new List <DiskStatistics>(); foreach (var drive in collector.GetDrives()) { aggs.Add(new Tuple <string, Aggregation>(drive, new Aggregation())); diskStats.Add(new DiskStatistics() { Drive = drive }); } m_diskStats = diskStats.ToArray(); }
public void PerformanceCollectorRefreshTest() { var counters = new PerformanceCounter[] { new PerformanceCounter("Processor", "% Processor Time", "_Total"), new PerformanceCounter("Processor", "% Processor Time", "_Total") }; var newCounter = new PerformanceCounter("Memory", "Available Bytes", string.Empty); IPerformanceCollector collector = new PerformanceCollector(); foreach (var pc in counters) { collector.RegisterPerformanceCounter( PerformanceCounterUtility.FormatPerformanceCounter(pc), null, pc.CategoryName, pc.CounterName, pc.InstanceName, false, true); } collector.RefreshPerformanceCounter(collector.PerformanceCounters.Last(), newCounter); Assert.IsTrue(collector.PerformanceCounters.Last().PerformanceCounter.CategoryName == newCounter.CategoryName); Assert.IsTrue(collector.PerformanceCounters.Last().PerformanceCounter.CounterName == newCounter.CounterName); Assert.IsTrue(collector.PerformanceCounters.Last().PerformanceCounter.InstanceName == newCounter.InstanceName); }
public static TimedBlock <TStartObject, TEndObject> Start( LoggingContext parentLoggingContext, PerformanceCollector collector, string phaseFriendlyName, Action <LoggingContext, TStartObject> startAction, TStartObject startObject, Action <LoggingContext, TEndObject> endAction, Func <TEndObject> endObjGetter) { // There's no point is using this structure if the end action and struct aren't set Contract.Requires(parentLoggingContext != null); Contract.Requires(endAction != null); Contract.Requires(endObjGetter != null); Contract.Requires(startAction != null); Contract.Requires(collector == null || !string.IsNullOrWhiteSpace(phaseFriendlyName)); startAction(parentLoggingContext, startObject); return(new TimedBlock <TStartObject, TEndObject>( parentLoggingContext, collector?.CreateAggregator(), phaseFriendlyName, endAction, endObjGetter)); }
public static PerformanceMeasurement Start( LoggingContext parentLoggingContext, PerformanceCollector collector, string phaseFriendlyName, Action <Guid> startAction, Action endAction) { Contract.Requires(parentLoggingContext != null); Contract.Requires(collector == null || !string.IsNullOrWhiteSpace(phaseFriendlyName)); Contract.Requires(startAction != null); Contract.Requires(endAction != null); return(Start( parentLoggingContext, collector, phaseFriendlyName, (context) => { EventSource.SetCurrentThreadActivityId(context.ActivityId); startAction(context.ParentActivityId); }, (context) => { EventSource.SetCurrentThreadActivityId(context.ActivityId); endAction(); })); }
private static AnalyzerTaskResult InternalAnalyzeAsync(ProcedureContext procedureContext, AdomdClient.AdomdConnection connection) { var queryResult = default(DataTable); var profilerResult = default(ProfilerResult); var performanceResult = default(PerformanceResult); using (var collectorsSynchronizer = CollectorsSynchronizer.Create(procedureContext.CancellationToken)) using (var performanceTask = PerformanceCollector.StartAsync(procedureContext, collectorsSynchronizer)) { try { if (!performanceTask.IsFaulted && !procedureContext.IsCancellationRequested) { #region profiler collector using (var profilerCancellation = CancellationTokenSource.CreateLinkedTokenSource(procedureContext.CancellationToken)) using (var profilerTask = ProfilerCollector.StartAsync(procedureContext, collectorsSynchronizer, profilerCancellation.Token)) { try { if (!profilerTask.IsFaulted && !profilerCancellation.IsCancellationRequested) { try { queryResult = AdomdClientHelper.ExecuteDataTable( connection, procedureContext.CancellationToken, procedureContext.Statement, activityID: procedureContext.ClientActivityID, rowsLimit: procedureContext.QueryResultRowLimit, beforeStart: () => EventsNotifier.Instance.Notify(ProcedureEvents.ProcedureAnalyzeStepExecuteStatement), beforeWait: () => EventsNotifier.Instance.Notify(ProcedureEvents.ProcedureAnalyzeStepPendingOutcome) ); } finally { profilerCancellation.Cancel(); } } } finally { profilerResult = profilerTask.Result; } } #endregion } } finally { performanceResult = performanceTask.Result; } } return(AnalyzerTaskResult.Create(queryResult, profilerResult, performanceResult)); }
static MainWindow() { var counterCreationDatas = new[] { new CounterCreationData(COUNTER_NAME, "Help", PerformanceCounterType.NumberOfItems64), new CounterCreationData(COUNTER2_NAME, "Help", PerformanceCounterType.RateOfCountsPerSecond64) }; _performanceCollector = PerformanceCollector.Create("_Temp1", "test", counterCreationDatas); }
public TestScheduler( PipGraph graph, TestPipQueue pipQueue, PipExecutionContext context, FileContentTable fileContentTable, EngineCache cache, IConfiguration configuration, FileAccessWhitelist fileAccessWhitelist, DirectoryMembershipFingerprinterRuleSet directoryMembershipFingerprinterRules = null, ITempCleaner tempCleaner = null, PipRuntimeTimeTable runningTimeTable = null, JournalState journalState = null, PerformanceCollector performanceCollector = null, string fingerprintSalt = null, PreserveOutputsInfo?previousInputsSalt = null, IEnumerable <Pip> successfulPips = null, IEnumerable <Pip> failedPips = null, LoggingContext loggingContext = null, IIpcProvider ipcProvider = null, DirectoryTranslator directoryTranslator = null, VmInitializer vmInitializer = null, SchedulerTestHooks testHooks = null) : base(graph, pipQueue, context, fileContentTable, cache, configuration, fileAccessWhitelist, loggingContext, null, directoryMembershipFingerprinterRules, tempCleaner, AsyncLazy <PipRuntimeTimeTable> .FromResult(runningTimeTable), performanceCollector, fingerprintSalt, previousInputsSalt, ipcProvider: ipcProvider, directoryTranslator: directoryTranslator, journalState: journalState, vmInitializer: vmInitializer, testHooks: testHooks) { m_testPipQueue = pipQueue; if (successfulPips != null) { foreach (var pip in successfulPips) { Contract.Assume(pip.PipId.IsValid, "Override results must be added after the pip has been added to the scheduler"); m_overridePipResults.Add(pip.PipId, PipResultStatus.Succeeded); } } if (failedPips != null) { foreach (var pip in failedPips) { Contract.Assume(pip.PipId.IsValid, "Override results must be added after the pip has been added to the scheduler"); m_overridePipResults.Add(pip.PipId, PipResultStatus.Failed); } } m_loggingContext = loggingContext; }
/// <summary> /// Calls the specified observable call. /// </summary> /// <param name="statementMetricHandle">The statement metric handle.</param> /// <param name="perfCollector">The perf collector.</param> /// <param name="observableCall">The observable call.</param> /// <param name="numInput">The num input.</param> public static void Call(this StatementMetricHandle statementMetricHandle, PerformanceCollector perfCollector, Action observableCall, int numInput = 1) { if ((MetricReportingPath.IsMetricsEnabled) && statementMetricHandle.IsEnabled) { #if MONO long lCreationTime, lExitTime; long lUserTimeA, lKernelTimeA; long lUserTimeB, lKernelTimeB; //IntPtr thread = GetCurrentThread(); long lWallTimeA = PerformanceObserverMono.NanoTime; //GetThreadTimes(out lUserTimeA, out lKernelTimeA); observableCall.Invoke(); //GetThreadTimes(out lUserTimeB, out lKernelTimeB); long lWallTimeB = PerformanceObserverMono.NanoTime; long lTimeA = 0; // lKernelTimeA + lUserTimeA long lTimeB = 0; // lKernelTimeB + lUserTimeB perfCollector.Invoke( metricValue, 100 * (lTimeB - lTimeA), lWallTimeB - lWallTimeA); #else long lCreationTime, lExitTime; long lUserTimeA, lKernelTimeA; long lUserTimeB, lKernelTimeB; IntPtr thread = GetCurrentThread(); long lWallTimeA = PerformanceObserverMono.NanoTime; GetThreadTimes(thread, out lCreationTime, out lExitTime, out lUserTimeA, out lKernelTimeA); observableCall.Invoke(); GetThreadTimes(thread, out lCreationTime, out lExitTime, out lUserTimeB, out lKernelTimeB); long lWallTimeB = PerformanceObserverMono.NanoTime; long lTimeA = (lKernelTimeA + lUserTimeA); long lTimeB = (lKernelTimeB + lUserTimeB); perfCollector.Invoke( statementMetricHandle, 100 * (lTimeB - lTimeA), lWallTimeB - lWallTimeA, numInput); #endif } else { observableCall.Invoke(); } }
/// <summary> /// Makes a new instance of <see cref="GameLoop"/> class. /// </summary> /// <param name="actionToDo">Delegate that will be executed on each frame.</param> /// <param name="threadName">Name of the associated thread.</param> public GameLoop(TimedAction actionToDo, string threadName) { loopAction = actionToDo; ExitRequest = false; this.threadName = threadName; // - Initialize performance collector Performance = new PerformanceCollector(threadName); // - Initialize scheduler Scheduler = new Scheduler(); // - Initialize clock Clock = new ThrottledFramedClock(); }
/// <nodoc /> private FrontEndControllerFactory( FrontEndMode mode, LoggingContext loggingContext, ICommandLineConfiguration configuration, PerformanceCollector collector, bool collectMemoryAsSoonAsPossible, IFrontEndStatistics statistics) { m_mode = mode; CollectMemoryAsSoonAsPossible = collectMemoryAsSoonAsPossible; Configuration = configuration; LoggingContext = loggingContext; Collector = collector; m_statistics = statistics; }
/// <summary> /// Makes a new instance of <see cref="GameLoop"/> class. /// </summary> /// <param name="action">Delegate that will be executed on each frame.</param> /// <param name="threadName">Name of the associated thread.</param> public GameLoop(Action <IFrameBasedClock> action, string threadName) { pLoopAction = action; ExitRequest = false; ThreadName = threadName; // - Initialize performance collector Performance = new PerformanceCollector(threadName); // - Initialize scheduler Scheduler = new Scheduler(); // - Initialize clock Clock = new ThrottledFramedClock(); }
/// <nodoc /> public static FrontEndControllerFactory Create( FrontEndMode mode, LoggingContext loggingContext, ICommandLineConfiguration configuration, PerformanceCollector collector, bool collectMemoryAsSoonAsPossible = true, IFrontEndStatistics statistics = null) { return(new FrontEndControllerFactory( mode, loggingContext, configuration, collector, collectMemoryAsSoonAsPossible, statistics)); }
public static DataTable GetConfigurationFor(ConfigurationType configurationType) { switch (configurationType) { case ConfigurationType.Engine: return(ProcedureContext.GetConfiguration()); case ConfigurationType.TraceEvents: return(ProfilerCollector.GetConfiguration()); case ConfigurationType.PerformanceCounters: return(PerformanceCollector.GetConfiguration()); default: throw new ApplicationException("Unknown ConfigurationType [{0}]".FormatWith(configurationType)); } }
public static List <TestResult> CallBatch(Func <IRpcService, TestRequest> requestFactory, int batchSize, PerformanceCollectorOptions options, TestResultCollector testResultCollector = null) { string requestMethodName = null; var testResults = new List <TestResult>(); foreach (var service in TestExecutor.Services) { var request = requestFactory(service); if (requestMethodName == null) { requestMethodName = request.MethodName; } if (options.Enabled) { options?.Writer? .WriteLine() .WriteLine($"Calling batch of {batchSize} {requestMethodName}".Center(80, '~')) .WriteLine(request.ToString()) .DrawLine('~'); } using (PerformanceCollector performanceCollector = new PerformanceCollector(service.GetServiceDescription(), options)) { PerformanceEntry performance = performanceCollector.Measure(() => service.CallBatch(Enumerable.Range(0, batchSize).Select(n => request).ToList())); testResults.Add(new TestResult(service, batchSize, performance)); AddBatchCallResult(service, requestMethodName, batchSize, performance.Elapsed); } } if (testResultCollector != null) { testResultCollector.Collect(batchSize.ToString(), testResults); } else { using (testResultCollector = new TestResultCollector($"{requestMethodName} BATCH calls")) { testResultCollector.Collect(batchSize.ToString(), testResults); } } return(testResults); }
public static PerformanceMeasurement Start( LoggingContext parentLoggingContext, PerformanceCollector collector, string phaseFriendlyName, Action <LoggingContext> startAction, Action <LoggingContext> endAction) { Contract.Requires(parentLoggingContext != null); Contract.Requires(collector == null || !string.IsNullOrWhiteSpace(phaseFriendlyName)); Contract.Requires(startAction != null); Contract.Requires(endAction != null); var pm = new PerformanceMeasurement( parentLoggingContext, collector != null ? collector.CreateAggregator() : null, phaseFriendlyName, endAction); startAction(pm.LoggingContext); return(pm); }
public void PerformanceCollectorSanityTest() { const int CounterCount = 3; const string CategoryName = "Processor"; const string CounterName = "% Processor Time"; const string InstanceName = "_Total"; IPerformanceCollector collector = new PerformanceCollector(); for (int i = 0; i < CounterCount; i++) { collector.RegisterPerformanceCounter( @"\Processor(_Total)\% Processor Time", null, CategoryName, CounterName, InstanceName, false, true); } var results = collector.Collect().ToList(); Assert.AreEqual(CounterCount, results.Count); foreach (var result in results) { var pc = result.Item1.PerformanceCounter; var value = result.Item2; Assert.AreEqual(CategoryName, pc.CategoryName); Assert.AreEqual(CounterName, pc.CounterName); Assert.AreEqual(InstanceName, pc.InstanceName); Assert.IsTrue(value >= 0 && value <= 100); } }
/// <summary> /// Run the test /// </summary> public bool Run(string testFolder, string specFile, string fullIdentifier, string shortName, string lkgFile, params string[] sdksToResolve) { Contract.Requires(!string.IsNullOrEmpty(testFolder)); Contract.Requires(!string.IsNullOrEmpty(specFile)); Contract.Requires(sdksToResolve != null); // Sadly the frontend doesn't use the engine abstractions file api's so we have to materialize stuff on disk for now... // TODO: Fix this code once the frontend supports a proper virtual FileSystem. // TODO: Change the package semantics to implicit when we expose a way to evaluate a single value var testFileName = Path.GetFileName(specFile); var mainFileName = "testMain.bp"; var testMainFile = Path.Combine(testFolder, mainFileName); Directory.CreateDirectory(testFolder); File.WriteAllText(Path.Combine(testFolder, Names.ModuleConfigBm), I($@"module( {{ name: 'TestPackage', nameResolutionSemantics: NameResolutionSemantics.implicitProjectReferences, projects: [ f`{mainFileName}`, f`{testFileName}`, ], }});")); File.WriteAllText(testMainFile, I($@" export const testFolder = d`{Path.GetDirectoryName(specFile).Replace('\\', '/')}`; @@public export const main = {fullIdentifier}();")); File.Copy(specFile, Path.Combine(testFolder, testFileName)); // Create a fake package for Sdk.TestRunner so that you can safely test packages that have the tests embedded in them. var testRunnerFolder = Path.Combine(testFolder, "Sdk.TestRunner"); Directory.CreateDirectory(testRunnerFolder); File.WriteAllText(Path.Combine(testRunnerFolder, Names.ModuleConfigBm), I($"module({{\n\tname: 'Sdk.TestRunner',\n}});")); File.WriteAllText(Path.Combine(testRunnerFolder, "package" + Names.DotDscExtension), I($@" export interface TestArguments {{ testFiles: File[]; sdkFolders?: (Directory|StaticDirectory)[]; autoFixLkgs?: boolean; }} export interface TestResult {{ xmlResults: File; }} export function test(args: TestArguments): TestResult {{ Contract.fail(""Can't run a DScript UnitTest inside of a DScript UnitTest""); }}")); // Setup Context and configuration var frontEndContext = FrontEndContext.CreateInstanceForTesting(); var pipContext = new SchedulerContext(CancellationToken.None, frontEndContext.StringTable, frontEndContext.PathTable, frontEndContext.SymbolTable, frontEndContext.QualifierTable); var pathTable = frontEndContext.PathTable; var testFolderPath = AbsolutePath.Create(pathTable, testFolder); var configuration = CreateConfiguration(sdksToResolve.Union(new[] { testRunnerFolder }), pathTable, testFolderPath); var engineAbstraction = new TestEngineAbstraction(pathTable, frontEndContext.StringTable, testFolderPath, new PassThroughFileSystem(pathTable)); var frontEndStatistics = new FrontEndStatistics(); if (!CreateFactories( frontEndContext, engineAbstraction, frontEndStatistics, configuration, out var ambientTesting, out var moduleRegistry, out var frontEndFactory)) { return(false); } // Set the timeout to a large number to avoid useless performance collections in tests. using (var performanceCollector = new PerformanceCollector(TimeSpan.FromHours(1))) using (var frontEndHostController = new FrontEndHostController( frontEndFactory, new EvaluationScheduler(1), moduleRegistry, frontEndStatistics, m_tracingLogger, performanceCollector, collectMemoryAsSoonAsPossible: true)) { var frontEndController = (IFrontEndController)frontEndHostController; frontEndController.InitializeHost(frontEndContext, configuration); frontEndController.ParseConfig(configuration); // Populate the graph using (var pipTable = new PipTable( pipContext.PathTable, pipContext.SymbolTable, initialBufferSize: 16384, maxDegreeOfParallelism: 1, debug: true)) { var mountPathExpander = new MountPathExpander(pathTable); mountPathExpander.Add(pathTable, new SemanticPathInfo(PathAtom.Create(frontEndContext.StringTable, "testFolder"), testFolderPath, allowHashing: true, readable: true, writable: false)); mountPathExpander.Add(pathTable, new SemanticPathInfo(PathAtom.Create(frontEndContext.StringTable, "src"), testFolderPath.Combine(pathTable, "src"), allowHashing: true, readable: true, writable: true)); mountPathExpander.Add(pathTable, new SemanticPathInfo(PathAtom.Create(frontEndContext.StringTable, "out"), testFolderPath.Combine(pathTable, "out"), allowHashing: true, readable: true, writable: true)); mountPathExpander.Add(pathTable, new SemanticPathInfo(PathAtom.Create(frontEndContext.StringTable, "noRead"), testFolderPath.Combine(pathTable, "noRead"), allowHashing: true, readable: false, writable: true)); mountPathExpander.Add(pathTable, new SemanticPathInfo(PathAtom.Create(frontEndContext.StringTable, "temp"), engineAbstraction.Layout.TempDirectory, allowHashing: true, readable: true, writable: true)); mountPathExpander.Add(pathTable, new SemanticPathInfo(PathAtom.Create(frontEndContext.StringTable, "obj"), engineAbstraction.Layout.ObjectDirectory, allowHashing: true, readable: true, writable: true)); var graph = new PipGraph.Builder( pipTable, pipContext, m_pipLogger, frontEndContext.LoggingContext, configuration, mountPathExpander); using (var cacheLayer = new EngineCache( new InMemoryArtifactContentCache(), new InMemoryTwoPhaseFingerprintStore())) { var cache = Task.FromResult(Possible.Create(cacheLayer)); try { var evaluationFilter = new EvaluationFilter( pipContext.SymbolTable, pipContext.PathTable, new FullSymbol[0], new[] { AbsolutePath.Create(frontEndContext.PathTable, testMainFile), }, CollectionUtilities.EmptyArray <StringId>()); if (!frontEndController.PopulateGraph(cache, graph, engineAbstraction, evaluationFilter, configuration, configuration.Startup)) { HandleDiagnostics(); return(false); } } catch (AggregateException e) { var baseException = e.GetBaseException(); if (baseException is XunitException) { // If it is an XUnit assert, then unwrap the exception and throw that because XUnit other doesn't display the error nicely. ExceptionDispatchInfo.Capture(baseException).Throw(); } throw; } } if (!ValidatePips(frontEndContext, graph, testFolderPath, specFile, shortName, lkgFile, ambientTesting.DontValidatePipsEnabled)) { return(false); } } } HandleDiagnostics(); return(true); }
public static void CallNTimes(Func <IRpcService, TestRequest> requestFactory, int count, PerformanceCollectorOptions options, TestResultCollector testResultCollector = null) { string requestMethodName = null; List <TestResult>[] testResults = Enumerable.Range(0, count).Select((i) => new List <TestResult>()).ToArray(); foreach (var service in TestExecutor.Services) { var request = requestFactory(service); if (requestMethodName == null) { requestMethodName = request.MethodName; } if (options.Enabled) { options?.Writer? .WriteLine() .WriteLine($"Calling {requestMethodName} {count} times".Center(80, '~')) .WriteLine(request.ToString()) .DrawLine('~'); } using (PerformanceCollector performanceCollector = new PerformanceCollector(service.GetServiceDescription(), options)) { for (int i = 0; i < count; i++) { int retries = 0; while (retries < MAX_RETRY) { try { PerformanceEntry performance = performanceCollector.Measure(() => service.CallSingle(request)); testResults[i].Add(new TestResult(service, count, performance)); AddSingleCallResult(service, requestMethodName, performance.Elapsed); break; } catch (System.Exception ex) { Thread.Sleep(200); //introduces a wait between calls because of intermittent problem with "The server returned an invalid or unrecognized response" error retries++; } } } } } if (testResultCollector != null) { for (int i = 0; i < testResults.Length; i++) { testResultCollector.Collect($"t-{i + 1}", testResults[i]); } } else { using (testResultCollector = new TestResultCollector($"{requestMethodName} repeated calls ({count}).")) { for (int i = 0; i < testResults.Length; i++) { testResultCollector.Collect($"t-{i + 1}", testResults[i]); } } } }
/// <summary> /// Calls the specified observable call. /// </summary> /// <param name="statementMetricHandle">The statement metric handle.</param> /// <param name="perfCollector">The perf collector.</param> /// <param name="observableCall">The observable call.</param> /// <param name="numInput">The num input.</param> public static void Call(this StatementMetricHandle statementMetricHandle, PerformanceCollector perfCollector, Action observableCall, int numInput = 1) { if ((MetricReportingPath.IsMetricsEnabled) && statementMetricHandle.IsEnabled) { #if MONO long lCreationTime, lExitTime; long lUserTimeA, lKernelTimeA; long lUserTimeB, lKernelTimeB; //IntPtr thread = GetCurrentThread(); long lWallTimeA = PerformanceObserverMono.NanoTime; //GetThreadTimes(out lUserTimeA, out lKernelTimeA); observableCall.Invoke(); //GetThreadTimes(out lUserTimeB, out lKernelTimeB); long lWallTimeB = PerformanceObserverMono.NanoTime; long lTimeA = 0; // lKernelTimeA + lUserTimeA long lTimeB = 0; // lKernelTimeB + lUserTimeB perfCollector.Invoke( metricValue, 100 * (lTimeB - lTimeA), lWallTimeB - lWallTimeA); #else FILETIME lCreationTime; FILETIME lExitTime; FILETIME lUserTimeA; FILETIME lKernelTimeA; FILETIME lUserTimeB; FILETIME lKernelTimeB; IntPtr thread = GetCurrentThread(); long lWallTimeA = PerformanceObserverMono.NanoTime; GetThreadTimes(thread, out lCreationTime, out lExitTime, out lUserTimeA, out lKernelTimeA); observableCall.Invoke(); GetThreadTimes(thread, out lCreationTime, out lExitTime, out lUserTimeB, out lKernelTimeB); long lWallTimeB = PerformanceObserverMono.NanoTime; // Calculate the time, not that the numbers represent 100-nanosecond intervals since // January 1, 601 (UTC). // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284(v=vs.85).aspx var kernelTimeA = (((long)lKernelTimeA.dwHighDateTime) << 32) | ((long)lKernelTimeA.dwLowDateTime); var kernelTimeB = (((long)lKernelTimeB.dwHighDateTime) << 32) | ((long)lKernelTimeB.dwLowDateTime); var userTimeA = (((long)lUserTimeA.dwHighDateTime) << 32) | ((long)lUserTimeA.dwLowDateTime); var userTimeB = (((long)lUserTimeB.dwHighDateTime) << 32) | ((long)lUserTimeB.dwLowDateTime); var execTimeNano = 100 * (userTimeB - userTimeA + kernelTimeB - kernelTimeA); perfCollector.Invoke( statementMetricHandle, execTimeNano, lWallTimeB - lWallTimeA, numInput); #endif } else { observableCall.Invoke(); } }
private static IFrontEndController TryCreateFrontEndController( FrontEndFactory frontEndFactory, IDecorator <EvaluationResult> decorator, ICommandLineConfiguration configuration, SymbolTable symbolTable, LoggingContext loggingContext, PerformanceCollector collector, bool collectMemoryAsSoonAsPossible, IFrontEndStatistics statistics) { var workspaceResolverFactory = new DScriptWorkspaceResolverFactory(); Contract.Requires(frontEndFactory != null && !frontEndFactory.IsSealed); // Statistic should be global for all front-ends, not per an instance. var frontEndStatistics = statistics ?? new FrontEndStatistics(); var globalConstants = new GlobalConstants(symbolTable); var sharedModuleRegistry = new ModuleRegistry(); // Note, that the following code is absolutely critical for detecting that front-end related objects // are freed successfully after evaluation. // ModuleRegistry was picked intentionally because it holds vast amount of front-end data. FrontEndControllerMemoryObserver.CaptureFrontEndReference(sharedModuleRegistry); frontEndFactory.SetConfigurationProcessor( new ConfigurationProcessor(globalConstants, sharedModuleRegistry, logger: null)); var msBuildFrontEnd = new MsBuildFrontEnd( globalConstants, sharedModuleRegistry, frontEndStatistics); var ninjaFrontEnd = new NinjaFrontEnd( globalConstants, sharedModuleRegistry, frontEndStatistics); var cmakeFrontEnd = new CMakeFrontEnd( globalConstants, sharedModuleRegistry, frontEndStatistics); // TODO: Workspace resolvers and frontends are registered in separate factories. Consider // adding a main coordinator/registry RegisterKnownWorkspaceResolvers( workspaceResolverFactory, globalConstants, sharedModuleRegistry, frontEndStatistics, msBuildFrontEnd, ninjaFrontEnd, cmakeFrontEnd); frontEndFactory.AddFrontEnd(new DScriptFrontEnd( globalConstants, sharedModuleRegistry, frontEndStatistics, evaluationDecorator: decorator)); frontEndFactory.AddFrontEnd(new NugetFrontEnd( globalConstants, sharedModuleRegistry, frontEndStatistics, evaluationDecorator: decorator)); frontEndFactory.AddFrontEnd(new DownloadFrontEnd( globalConstants, sharedModuleRegistry)); frontEndFactory.AddFrontEnd(msBuildFrontEnd); frontEndFactory.AddFrontEnd(ninjaFrontEnd); frontEndFactory.AddFrontEnd(cmakeFrontEnd); if (!frontEndFactory.TrySeal(loggingContext)) { return(null); } return(new FrontEndHostController(frontEndFactory, workspaceResolverFactory, frontEndStatistics: frontEndStatistics, collector: collector, collectMemoryAsSoonAsPossible: collectMemoryAsSoonAsPossible)); }