internal void StartProfiling(ProfilingTarget target, SessionNode session, bool openReport = true) { if (!Utilities.SaveDirtyFiles()) { // Abort return; } if (target.ProjectTarget != null) { ProfileProjectTarget(session, target.ProjectTarget, openReport); } else if (target.StandaloneTarget != null) { ProfileStandaloneTarget(session, target.StandaloneTarget, openReport); } else { if (MessageBox.Show(Resources.NoProfilingConfiguredMessageText, Resources.NoProfilingConfiguredMessageCaption, MessageBoxButton.YesNo) == MessageBoxResult.Yes) { var newTarget = session.OpenTargetProperties(); if (newTarget != null && (newTarget.ProjectTarget != null || newTarget.StandaloneTarget != null)) { StartProfiling(newTarget, session, openReport); } } } }
private void ProfileProjectTarget(SessionNode session, ProjectTarget projectTarget, bool openReport) { var targetGuid = projectTarget.TargetProject; var dte = (EnvDTE.DTE)GetGlobalService(typeof(EnvDTE.DTE)); EnvDTE.Project projectToProfile = null; foreach (EnvDTE.Project project in dte.Solution.Projects) { var kind = project.Kind; if (String.Equals(kind, NodejsProfilingPackage.NodeProjectGuid, StringComparison.OrdinalIgnoreCase)) { var guid = project.Properties.Item("Guid").Value as string; Guid guidVal; if (Guid.TryParse(guid, out guidVal) && guidVal == projectTarget.TargetProject) { projectToProfile = project; break; } } } if (projectToProfile != null) { var t = ProfileProject(session, projectToProfile, openReport); } else { MessageBox.Show(Resources.ProjectNotFoundErrorMessageText, Resources.NodejsToolsForVS); } }
private void StartPerfAnalysis(object sender, EventArgs e) { var view = new ProfilingTargetView(); var sessions = ShowPerformanceExplorer().Sessions; SessionNode activeSession = sessions.ActiveSession; if (activeSession == null || activeSession.Target.ProjectTarget == null || !ProjectTarget.IsSame(activeSession.Target.ProjectTarget, view.Project.GetTarget())) { // need to create a new session var target = new ProfilingTarget() { ProjectTarget = view.Project.GetTarget() }; activeSession = AddPerformanceSession( view.Project.Name, target ); } ProfileProjectTarget(activeSession, activeSession.Target.ProjectTarget, true); }
internal void StartProfiling(ProfilingTarget target, SessionNode session, bool openReport = true) { if (!Utilities.SaveDirtyFiles()) { // Abort return; } if (target.ProjectTarget != null) { ProfileProjectTarget(session, target.ProjectTarget, openReport); } else if (target.StandaloneTarget != null) { ProfileStandaloneTarget(session, target.StandaloneTarget, openReport); } else { if (MessageBox.Show("Profiling session is not configured - would you like to configure now and then launch?", "No Profiling Target", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { var newTarget = session.OpenTargetProperties(); if (newTarget != null && (newTarget.ProjectTarget != null || newTarget.StandaloneTarget != null)) { StartProfiling(newTarget, session, openReport); } } } }
internal SessionNode OpenTarget(ProfilingTarget target, string filename) { for (int i = 0; i < _sessions.Count; i++) { if (_sessions[i].Filename == filename) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Performance '{0}' session is already open", filename)); } } uint prevSibl; if (_sessions.Count > 0) { prevSibl = _sessions[_sessions.Count - 1].ItemId; } else { prevSibl = VSConstants.VSITEMID_NIL; } var node = new SessionNode(this, target, filename); _sessions.Add(node); OnItemAdded(VSConstants.VSITEMID_ROOT, prevSibl, node.ItemId); if (_activeSession == VSConstants.VSITEMID_NIL) { SetActiveSession(node); } return(node); }
internal async System.Threading.Tasks.Task ProfileProject(SessionNode session, EnvDTE.Project projectToProfile, bool openReport) { var uiThread = (UIThreadBase)NodejsProfilingPackage.Instance.GetService(typeof(UIThreadBase)); if (!await uiThread.InvokeTask(() => EnsureProjectUpToDate(projectToProfile)) && await uiThread.InvokeAsync(() => MessageBox.Show(Resources.FailedToBuild, Resources.NodejsToolsForVS, MessageBoxButton.YesNo)) == MessageBoxResult.No) { return; } var interpreterArgs = (string)projectToProfile.Properties.Item(NodeProjectProperty.NodeExeArguments).Value; var scriptArgs = (string)projectToProfile.Properties.Item(NodeProjectProperty.ScriptArguments).Value; var startBrowser = (bool)projectToProfile.Properties.Item(NodeProjectProperty.StartWebBrowser).Value; string launchUrl = (string)projectToProfile.Properties.Item(NodeProjectProperty.LaunchUrl).Value; int?port = (int?)projectToProfile.Properties.Item(NodeProjectProperty.NodejsPort).Value; string interpreterPath = (string)projectToProfile.Properties.Item(NodeProjectProperty.NodeExePath).Value; string startupFile = (string)projectToProfile.Properties.Item("StartupFile").Value; if (String.IsNullOrEmpty(startupFile)) { MessageBox.Show(Resources.NoConfiguredStatupFileErrorMessageText, Resources.NodejsToolsForVS); return; } string workingDir = projectToProfile.Properties.Item("WorkingDirectory").Value as string; if (String.IsNullOrEmpty(workingDir) || workingDir == ".") { workingDir = projectToProfile.Properties.Item("ProjectHome").Value as string; if (String.IsNullOrEmpty(workingDir)) { workingDir = Path.GetDirectoryName(projectToProfile.FullName); } } RunProfiler( session, interpreterPath, interpreterArgs, startupFile, scriptArgs, workingDir, null, openReport, launchUrl, port, startBrowser ); }
internal void SetActiveSession(SessionNode node) { uint oldItem = _activeSession; if (oldItem != VSConstants.VSITEMID_NIL) { _window.ExpandItem(this, _activeSession, EXPANDFLAGS.EXPF_UnBoldItem); } _activeSession = node.ItemId; _window.ExpandItem(this, _activeSession, EXPANDFLAGS.EXPF_BoldItem); }
internal async System.Threading.Tasks.Task ProfileProject(SessionNode session, EnvDTE.Project projectToProfile, bool openReport) { if (!await UIThread.InvokeTask(() => EnsureProjectUpToDate(projectToProfile)) && await UIThread.InvokeAsync(() => MessageBox.Show(Resources.FailedToBuild, Resources.NodejsToolsForVS, MessageBoxButton.YesNo)) == MessageBoxResult.No) { return; } var interpreterArgs = (string)projectToProfile.Properties.Item("NodeExeArguments").Value; var scriptArgs = (string)projectToProfile.Properties.Item("ScriptArguments").Value; var startBrowser = (bool)projectToProfile.Properties.Item("StartWebBrowser").Value; string launchUrl = (string)projectToProfile.Properties.Item("LaunchUrl").Value; int?port = (int?)projectToProfile.Properties.Item("NodejsPort").Value; string interpreterPath = (string)projectToProfile.Properties.Item("NodeExePath").Value; string startupFile = (string)projectToProfile.Properties.Item("StartupFile").Value; if (String.IsNullOrEmpty(startupFile)) { MessageBox.Show("Project has no configured startup file, cannot start profiling.", Resources.NodejsToolsForVS); return; } string workingDir = projectToProfile.Properties.Item("WorkingDirectory").Value as string; if (String.IsNullOrEmpty(workingDir) || workingDir == ".") { workingDir = projectToProfile.Properties.Item("ProjectHome").Value as string; if (String.IsNullOrEmpty(workingDir)) { workingDir = Path.GetDirectoryName(projectToProfile.FullName); } } RunProfiler( session, interpreterPath, interpreterArgs, startupFile, scriptArgs, workingDir, null, openReport, launchUrl, port, startBrowser ); }
private static void ProfileStandaloneTarget(SessionNode session, StandaloneTarget runTarget, bool openReport) { RunProfiler( session, runTarget.InterpreterPath, String.Empty, // interpreter args runTarget.Script, runTarget.Arguments, runTarget.WorkingDirectory, null, // env vars openReport, null, // launch url, null, // port false // start browser ); }
private void ProfileProjectTarget(SessionNode session, ProjectTarget projectTarget, bool openReport) { var targetGuid = projectTarget.TargetProject; var dte = (EnvDTE.DTE)GetGlobalService(typeof(EnvDTE.DTE)); EnvDTE.Project projectToProfile = null; foreach (EnvDTE.Project project in dte.Solution.Projects) { var kind = project.Kind; if (String.Equals(kind, NodejsProfilingPackage.NodeProjectGuid, StringComparison.OrdinalIgnoreCase)) { var guid = project.Properties.Item("Guid").Value as string; Guid guidVal; if (Guid.TryParse(guid, out guidVal) && guidVal == projectTarget.TargetProject) { projectToProfile = project; break; } } } if (projectToProfile != null) { var t = ProfileProject(session, projectToProfile, openReport); } else { MessageBox.Show("Project could not be found in current solution.", Resources.NodejsToolsForVS); } }
public ContextCommandTarget(SessionNode node, uint itemid) { _node = node; _itemid = itemid; }
private static void RunProfiler(SessionNode session, string interpreter, string interpreterArgs, string script, string scriptArgs, string workingDir, Dictionary<string, string> env, bool openReport, string launchUrl, int? port, bool startBrowser) { if (String.IsNullOrWhiteSpace(interpreter)) { Nodejs.ShowNodejsNotInstalled(); return; } else if (!File.Exists(interpreter)) { Nodejs.ShowNodejsPathNotFound(interpreter); return; } var arch = NativeMethods.GetBinaryType(interpreter); bool jmc = true; using (var vsperfKey = VSRegistry.RegistryRoot(__VsLocalRegistryType.RegType_UserSettings).OpenSubKey("VSPerf")) { if (vsperfKey != null) { var value = vsperfKey.GetValue("tools.options.justmycode"); int jmcSetting; if (value != null && value is string && Int32.TryParse((string)value, out jmcSetting)) { jmc = jmcSetting != 0; } } } var process = new ProfiledProcess(interpreter, interpreterArgs, script, scriptArgs, workingDir, env, arch, launchUrl, port, startBrowser, jmc); string baseName = Path.GetFileNameWithoutExtension(session.Filename); string date = DateTime.Now.ToString("yyyyMMdd"); string outPath = Path.Combine(Path.GetDirectoryName(session.Filename), baseName + "_" + date + ".vspx"); int count = 1; while (File.Exists(outPath)) { outPath = Path.Combine(Path.GetTempPath(), baseName + "_" + date + "(" + count + ").vspx"); count++; } process.ProcessExited += (sender, args) => { var dte = (EnvDTE.DTE)NodejsProfilingPackage.GetGlobalService(typeof(EnvDTE.DTE)); _profilingProcess = null; _stopCommand.Enabled = false; _startCommand.Enabled = true; _startCommandCtx.Enabled = true; if (openReport && File.Exists(outPath)) { dte.ItemOperations.OpenFile(outPath); } }; session.AddProfile(outPath); process.StartProfiling(outPath); _profilingProcess = process; _stopCommand.Enabled = true; _startCommand.Enabled = false; _startCommandCtx.Enabled = false; }
internal async System.Threading.Tasks.Task ProfileProject(SessionNode session, EnvDTE.Project projectToProfile, bool openReport) { var uiThread = (UIThreadBase)NodejsProfilingPackage.Instance.GetService(typeof(UIThreadBase)); if (!await uiThread.InvokeTask(() => EnsureProjectUpToDate(projectToProfile)) && await uiThread.InvokeAsync(() => MessageBox.Show(Resources.FailedToBuild, Resources.NodejsToolsForVS, MessageBoxButton.YesNo)) == MessageBoxResult.No) { return; } var interpreterArgs = (string)projectToProfile.Properties.Item("NodeExeArguments").Value; var scriptArgs = (string)projectToProfile.Properties.Item("ScriptArguments").Value; var startBrowser = (bool)projectToProfile.Properties.Item("StartWebBrowser").Value; string launchUrl = (string)projectToProfile.Properties.Item("LaunchUrl").Value; int? port = (int?)projectToProfile.Properties.Item("NodejsPort").Value; string interpreterPath = (string)projectToProfile.Properties.Item("NodeExePath").Value; string startupFile = (string)projectToProfile.Properties.Item("StartupFile").Value; if (String.IsNullOrEmpty(startupFile)) { MessageBox.Show("Project has no configured startup file, cannot start profiling.", Resources.NodejsToolsForVS); return; } string workingDir = projectToProfile.Properties.Item("WorkingDirectory").Value as string; if (String.IsNullOrEmpty(workingDir) || workingDir == ".") { workingDir = projectToProfile.Properties.Item("ProjectHome").Value as string; if (String.IsNullOrEmpty(workingDir)) { workingDir = Path.GetDirectoryName(projectToProfile.FullName); } } RunProfiler( session, interpreterPath, interpreterArgs, startupFile, scriptArgs, workingDir, null, openReport, launchUrl, port, startBrowser ); }
private static void RunProfiler(SessionNode session, string interpreter, string interpreterArgs, string script, string scriptArgs, string workingDir, Dictionary <string, string> env, bool openReport, string launchUrl, int?port, bool startBrowser) { if (String.IsNullOrWhiteSpace(interpreter)) { Nodejs.ShowNodejsNotInstalled(); return; } else if (!File.Exists(interpreter)) { Nodejs.ShowNodejsPathNotFound(interpreter); return; } var arch = NativeMethods.GetBinaryType(interpreter); bool jmc = true; using (var vsperfKey = VSRegistry.RegistryRoot(__VsLocalRegistryType.RegType_UserSettings).OpenSubKey("VSPerf")) { if (vsperfKey != null) { var value = vsperfKey.GetValue("tools.options.justmycode"); int jmcSetting; if (value != null && value is string && Int32.TryParse((string)value, out jmcSetting)) { jmc = jmcSetting != 0; } } } var process = new ProfiledProcess(interpreter, interpreterArgs, script, scriptArgs, workingDir, env, arch, launchUrl, port, startBrowser, jmc); string baseName = Path.GetFileNameWithoutExtension(session.Filename); string date = DateTime.Now.ToString("yyyyMMdd", CultureInfo.InvariantCulture); string outPath = Path.Combine(Path.GetDirectoryName(session.Filename), baseName + "_" + date + ".vspx"); int count = 1; while (File.Exists(outPath)) { outPath = Path.Combine(Path.GetTempPath(), baseName + "_" + date + "(" + count + ").vspx"); count++; } process.ProcessExited += (sender, args) => { var dte = (EnvDTE.DTE)NodejsProfilingPackage.GetGlobalService(typeof(EnvDTE.DTE)); _profilingProcess = null; _stopCommand.Enabled = false; _startCommand.Enabled = true; _startCommandCtx.Enabled = true; if (openReport && File.Exists(outPath)) { dte.ItemOperations.OpenFile(outPath); } }; session.AddProfile(outPath); process.StartProfiling(outPath); _profilingProcess = process; _stopCommand.Enabled = true; _startCommand.Enabled = false; _startCommandCtx.Enabled = false; }
internal SessionNode OpenTarget(ProfilingTarget target, string filename) { for (int i = 0; i < _sessions.Count; i++) { if (_sessions[i].Filename == filename) { throw new InvalidOperationException(String.Format("Performance '{0}' session is already open", filename)); } } uint prevSibl; if (_sessions.Count > 0) { prevSibl = _sessions[_sessions.Count - 1].ItemId; } else { prevSibl = VSConstants.VSITEMID_NIL; } var node = new SessionNode(this, target, filename); _sessions.Add(node); OnItemAdded(VSConstants.VSITEMID_ROOT, prevSibl, node.ItemId); if (_activeSession == VSConstants.VSITEMID_NIL) { SetActiveSession(node); } return node; }
internal AutomationSession(SessionNode session) { _node = session; }