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;
        }
        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;
        }
Exemplo n.º 3
0
            public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
            {
                if (pguidCmdGroup == ProfilingGuids.NodejsProfilingCmdSet)
                {
                    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:
                    {
                        CompareReportsView compareView;
                        if (_node.IsReportItem(_itemid))
                        {
                            var report = _node.GetReport(_itemid);
                            compareView = new CompareReportsView(report.Filename);
                        }
                        else
                        {
                            compareView = new CompareReportsView();
                        }

                        var dialog = new CompareReportsWindow(compareView);
                        var res    = dialog.ShowModal() ?? false;
                        if (res && compareView.IsValid)
                        {
                            IVsUIShellOpenDocument sod = NodejsProfilingPackage.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),
                                compareView.GetComparisonUri(),
                                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 dialog = new OpenFileDialog();
                        dialog.Filter          = NodejsProfilingPackage.PerformanceFileFilter;
                        dialog.CheckFileExists = true;
                        var res = dialog.ShowDialog() ?? false;
                        if (res)
                        {
                            _node.AddProfile(dialog.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);
            }