private async Task RunAnalyzer(TargetScope targetScope) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var dte2 = (DTE2)Package.GetGlobalService(typeof(SDTE)); var project = dte2.ActiveDocument?.ProjectItem?.ContainingProject; if (project == null) { return; } var propertyProvider = CreateProjectPropertyProvider(project, OptionsProvider); await propertyProvider.LoadProperties(); _outputLogger.ActivateWindow(); string publishPath = null; JitTarget jitTarget; if (targetScope.RequiresBuild) { try { if (!propertyProvider.IsOptimized) { await ShowError( "The current build configuration does not have the \"Optimize code\" flag set and is therefore not suitable for analysing the JIT compiler.\r\n\r\nPlease enable the the \"Optimize code\" flag (under Project Properties -> Build) or switch to a non-debug configuration (e.g. 'Release') before running the Inlining Analyzer."); return; } } catch (Exception) { } _outputLogger.WriteText("Building " + project.Name + "..."); string configurationName = project.ConfigurationManager.ActiveConfiguration.ConfigurationName; dte2.Solution.SolutionBuild.BuildProject(configurationName, project.UniqueName, true); if (dte2.Solution.SolutionBuild.LastBuildInfo != 0) { _outputLogger.WriteText("Build failed."); return; } _outputLogger.ActivateWindow(); jitTarget = new JitTarget(DetermineTargetPlatform(propertyProvider), propertyProvider.TargetRuntime, OptionsProvider.NetCoreVersion); if (ProjectPublisher.IsPublishingNecessary(propertyProvider)) { var publisher = new ProjectPublisher(jitTarget, configurationName, propertyProvider, _outputLogger); if (!await Task.Run(() => publisher.Publish())) { return; } publishPath = publisher.PublishPath; } } else { // TODO: read target platform from assembly file jitTarget = new JitTarget(DetermineTargetPlatform(propertyProvider), OptionsProvider.PreferredRuntime, OptionsProvider.NetCoreVersion); } string assemblyFile = GetAssemblyPath(propertyProvider, publishPath, targetScope); if (assemblyFile == null) { return; } _statusBarLogger.SetText("Running Inlining Analyzer on " + project.Name); _statusBarLogger.StartProgressAnimation(); _outputLogger.WriteText(""); _outputLogger.WriteText("Starting Inlining Analyzer..."); if (!string.IsNullOrEmpty(propertyProvider.TargetFramework)) { _outputLogger.WriteText("TargetFramework: " + propertyProvider.TargetFramework); } _outputLogger.WriteText("Assembly: " + assemblyFile); _outputLogger.WriteText("Runtime: " + jitTarget.Runtime); _outputLogger.WriteText("Platform: " + jitTarget.Platform); if (jitTarget.Runtime == TargetRuntime.NetCore) { _outputLogger.WriteText(".NET Core Version: " + (jitTarget.HasSpecificNetCoreVersion ? jitTarget.NetCoreVersion : "Latest")); } _outputLogger.WriteText(targetScope.ToString()); _outputLogger.WriteText(""); try { var runner = new JitRunner(assemblyFile, jitTarget, targetScope, _outputLogger, new JitHostPathResolver()); AnalyzerModel.CallGraph = await Task.Run(() => runner.Run()); _outputLogger.WriteText("Finished Inlining Analyzer"); } catch (JitCompilerException jitException) { await ShowError(jitException.Message); } catch (Exception ex) { _outputLogger.WriteText(ex.ToString()); await ShowError("Jit Compilation failed with errors. Check the Inlining Analyzer Output Window for details."); } finally { if (publishPath != null) { try { Directory.Delete(publishPath, true); } catch (Exception) { } } } _statusBarLogger.StopProgressAnimation(); _statusBarLogger.Clear(); }
private async Task RunAnalyzer(TargetScope targetScope) { var dte2 = (DTE2)Package.GetGlobalService(typeof(SDTE)); var project = dte2.ActiveDocument?.ProjectItem?.ContainingProject; if (project == null) { return; } var propertyProvider = CreateProjectPropertyProvider(project, PreferredRuntime); await propertyProvider.LoadProperties(); try { if (!propertyProvider.IsOptimized) { ShowError( "The current build configuration does not have the \"Optimize code\" flag set and is therefore not suitable for analysing the JIT compiler.\r\n\r\nPlease enable the the \"Optimize code\" flag (under Project Properties -> Build) or switch to a non-debug configuration (e.g. 'Release') before running the Inlining Analyzer."); return; } } catch (Exception) { } _outputLogger.ActivateWindow(); _outputLogger.WriteText("Building " + project.Name + "..."); dte2.Solution.SolutionBuild.BuildProject(project.ConfigurationManager.ActiveConfiguration.ConfigurationName, project.UniqueName, true); if (dte2.Solution.SolutionBuild.LastBuildInfo != 0) { _outputLogger.WriteText("Build failed."); return; } _outputLogger.ActivateWindow(); string assemblyFile = GetAssemblyPath(propertyProvider); JitTarget jitTarget = new JitTarget(DetermineTargetPlatform(propertyProvider), propertyProvider.TargetRuntime); _statusBarLogger.SetText("Running Inlining Analyzer on " + project.Name); _statusBarLogger.StartProgressAnimation(); _outputLogger.WriteText("Starting Inlining Analyzer..."); _outputLogger.WriteText("Assembly: " + assemblyFile); _outputLogger.WriteText("Runtime: " + jitTarget.Runtime); _outputLogger.WriteText("Platform: " + jitTarget.Platform); if (targetScope == null) { _outputLogger.WriteText("Scope: All Types and Methods"); } else { _outputLogger.WriteText($"Scope ({targetScope.ScopeType}): {targetScope.Name}"); } _outputLogger.WriteText(""); try { var runner = new JitRunner(assemblyFile, jitTarget, targetScope, _outputLogger, new JitHostPathResolver()); AnalyzerModel.CallGraph = runner.Run(); _outputLogger.WriteText("Finished Inlining Analyzer"); } catch (JitCompilerException jitException) { ShowError(jitException.Message); } catch (Exception ex) { _outputLogger.WriteText(ex.ToString()); ShowError("Jit Compilation failed with errors. Check the Inlining Analyzer Output Window for details."); } _statusBarLogger.StopProgressAnimation(); _statusBarLogger.Clear(); }