private static void RunProfiler(SessionNode session, string interpreter, string script, string arguments, string workingDir, bool openReport, ProcessorArchitecture arch) { var process = new ProfiledProcess(interpreter, String.Format("\"{0}\" {1}", script, arguments), workingDir, arch); string baseName = Path.GetFileNameWithoutExtension(session.Filename); string date = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString(); string outPath = Path.Combine(Path.GetTempPath(), baseName + date + ".vsp"); int count = 1; while (File.Exists(outPath)) { outPath = Path.Combine(Path.GetTempPath(), baseName + date + "(" + count + ").vsp"); count++; } process.ProcessExited += (sender, args) => { var dte = (EnvDTE.DTE)PythonProfilingPackage.GetGlobalService(typeof(EnvDTE.DTE)); _profilingProcess = null; _stopCommand.Enabled = false; _startCommand.Enabled = true; if (openReport) { dte.ItemOperations.OpenFile(outPath); } }; session.AddProfile(outPath); process.StartProfiling(outPath); _profilingProcess = process; _stopCommand.Enabled = true; _startCommand.Enabled = false; }
private static void RunProfiler(SessionNode session, LaunchConfiguration config, bool openReport) { var process = new ProfiledProcess( (PythonToolsService)session._serviceProvider.GetService(typeof(PythonToolsService)), config.GetInterpreterPath(), string.Join(" ", ProcessOutput.QuoteSingleArgument(config.ScriptName), config.ScriptArguments), config.WorkingDirectory, session._serviceProvider.GetPythonToolsService().GetFullEnvironment(config) ); string baseName = Path.GetFileNameWithoutExtension(session.Filename); string date = DateTime.Now.ToString("yyyyMMdd"); string outPath = Path.Combine(Path.GetTempPath(), baseName + "_" + date + ".vsp"); int count = 1; while (File.Exists(outPath)) { outPath = Path.Combine(Path.GetTempPath(), baseName + "_" + date + "(" + count + ").vsp"); count++; } process.ProcessExited += (sender, args) => { var dte = (EnvDTE.DTE)session._serviceProvider.GetService(typeof(EnvDTE.DTE)); _profilingProcess = null; _stopCommand.Enabled = false; _startCommand.Enabled = true; if (openReport && File.Exists(outPath)) { for (int retries = 10; retries > 0; --retries) { try { using (new FileStream(outPath, FileMode.Open, FileAccess.Read, FileShare.None)) { } break; } catch (IOException) { Thread.Sleep(100); } } dte.ItemOperations.OpenFile(outPath); } }; session.AddProfile(outPath); process.StartProfiling(outPath); _profilingProcess = process; _stopCommand.Enabled = true; _startCommand.Enabled = false; }
private static void RunProfiler(SessionNode session, string interpreter, string script, string arguments, string workingDir, Dictionary <string, string> env, bool openReport, ProcessorArchitecture arch) { var process = new ProfiledProcess( (PythonToolsService)session._serviceProvider.GetService(typeof(PythonToolsService)), interpreter, String.Format("\"{0}\" {1}", script, arguments ?? string.Empty), workingDir, env, arch ); string baseName = Path.GetFileNameWithoutExtension(session.Filename); string date = DateTime.Now.ToString("yyyyMMdd"); string outPath = Path.Combine(Path.GetTempPath(), baseName + "_" + date + ".vsp"); int count = 1; while (File.Exists(outPath)) { outPath = Path.Combine(Path.GetTempPath(), baseName + "_" + date + "(" + count + ").vsp"); count++; } process.ProcessExited += (sender, args) => { var dte = (EnvDTE.DTE)session._serviceProvider.GetService(typeof(EnvDTE.DTE)); _profilingProcess = null; _stopCommand.Enabled = false; _startCommand.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; }
public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { if (pguidCmdGroup == GuidList.guidPythonProfilingCmdSet) { switch (nCmdID) { case PkgCmdIDList.cmdidOpenReport: _node.OpenProfile(_itemid); return(VSConstants.S_OK); case PkgCmdIDList.cmdidPerfCtxSetAsCurrent: _node._parent.SetActiveSession(_node); return(VSConstants.S_OK); case PkgCmdIDList.cmdidPerfCtxStartProfiling: _node.StartProfiling(); return(VSConstants.S_OK); case PkgCmdIDList.cmdidReportsCompareReports: CompareReportsWindow compare; if (_node.IsReportItem(_itemid)) { var report = _node.GetReport(_itemid); compare = new CompareReportsWindow(report.Filename); } else { compare = new CompareReportsWindow(); } var cmpRes = compare.ShowDialog(); if (cmpRes != null && cmpRes.Value) { IVsUIShellOpenDocument sod = PythonProfilingPackage.GetGlobalService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; Debug.Assert(sod != null); Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame frame = null; Guid guid = new Guid("{9C710F59-984F-4B83-B781-B6356C363B96}"); // performance diff guid Guid guidNull = Guid.Empty; sod.OpenSpecificEditor( (uint)(_VSRDTFLAGS.RDT_CantSave | _VSRDTFLAGS.RDT_DontAddToMRU | _VSRDTFLAGS.RDT_NonCreatable | _VSRDTFLAGS.RDT_NoLock), compare.ComparisonUrl, ref guid, null, ref guidNull, "Performance Comparison", _node, _itemid, IntPtr.Zero, null, out frame ); if (frame != null) { Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(frame.Show()); } } return(VSConstants.S_OK); case PkgCmdIDList.cmdidReportsAddReport: var open = new OpenFileDialog(); open.Filter = PythonProfilingPackage.PerformanceFileFilter; open.CheckFileExists = true; var res = open.ShowDialog(); if (res != null && res.Value) { _node.AddProfile(open.FileName); } return(VSConstants.S_OK); } } else if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { switch ((VSConstants.VSStd97CmdID)nCmdID) { case VSConstants.VSStd97CmdID.PropSheetOrProperties: _node.OpenTargetProperties(); return(VSConstants.S_OK); } } return((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED); }
private static void RunProfiler(SessionNode session, LaunchConfiguration config, bool openReport) { var process = new ProfiledProcess( (PythonToolsService)session._serviceProvider.GetService(typeof(PythonToolsService)), config.GetInterpreterPath(), string.Join(" ", ProcessOutput.QuoteSingleArgument(config.ScriptName), config.ScriptArguments), config.WorkingDirectory, session._serviceProvider.GetPythonToolsService().GetFullEnvironment(config) ); string baseName = Path.GetFileNameWithoutExtension(session.Filename); string date = DateTime.Now.ToString("yyyyMMdd"); string outPath = Path.Combine(Path.GetTempPath(), baseName + "_" + date + ".vsp"); int count = 1; while (File.Exists(outPath)) { outPath = Path.Combine(Path.GetTempPath(), baseName + "_" + date + "(" + count + ").vsp"); count++; } process.ProcessExited += (sender, args) => { var dte = (EnvDTE.DTE)session._serviceProvider.GetService(typeof(EnvDTE.DTE)); _profilingProcess = null; _stopCommand.Enabled = false; _startCommand.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; }
private static void RunProfiler(SessionNode session, string interpreter, string script, string arguments, string workingDir, Dictionary<string, string> env, bool openReport, ProcessorArchitecture arch) { var process = new ProfiledProcess( (PythonToolsService)session._serviceProvider.GetService(typeof(PythonToolsService)), interpreter, String.Format("\"{0}\" {1}", script, arguments ?? string.Empty), workingDir, env, arch ); string baseName = Path.GetFileNameWithoutExtension(session.Filename); string date = DateTime.Now.ToString("yyyyMMdd"); string outPath = Path.Combine(Path.GetTempPath(), baseName + "_" + date + ".vsp"); int count = 1; while (File.Exists(outPath)) { outPath = Path.Combine(Path.GetTempPath(), baseName + "_" + date + "(" + count + ").vsp"); count++; } process.ProcessExited += (sender, args) => { var dte = (EnvDTE.DTE)session._serviceProvider.GetService(typeof(EnvDTE.DTE)); _profilingProcess = null; _stopCommand.Enabled = false; _startCommand.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; }