Exemple #1
0
        public SessionNode(SessionsNode parent, ProfilingTarget target, string filename)
        {
            _parent   = parent;
            _target   = target;
            _filename = filename;

            // Register this with the running document table.  This will prompt for save when the file is dirty and
            // by responding to GetProperty for VSHPROPID_ItemDocCookie we will support Ctrl-S when one of our
            // files is dirty.
            // http://msdn.microsoft.com/en-us/library/bb164600(VS.80).aspx
            IVsRunningDocumentTable rdt = NodejsProfilingPackage.GetGlobalService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
            uint   cookie;
            IntPtr punkDocData = Marshal.GetIUnknownForObject(this);

            try
            {
                ErrorHandler.ThrowOnFailure(rdt.RegisterAndLockDocument((uint)(_VSRDTFLAGS.RDT_VirtualDocument | _VSRDTFLAGS.RDT_EditLock | _VSRDTFLAGS.RDT_CanBuildFromMemory), filename, this, VSConstants.VSITEMID_ROOT, punkDocData, out cookie));
            }
            finally
            {
                if (punkDocData != IntPtr.Zero)
                {
                    Marshal.Release(punkDocData);
                }
            }
            _docCookie = cookie;

            ItemId = parent._sessionsCollection.Add(this);
        }
Exemple #2
0
        public int DeleteItem(uint dwDelItemOp, uint itemid)
        {
            Debug.Assert(_target.Reports != null && _target.Reports.Report != null && _target.Reports.Report.Length > 0);

            var report = GetReport(itemid);

            Reports.Remove((int)itemid);

            OnItemDeleted(itemid);
            OnInvalidateItems(ReportsItemId);

            if (File.Exists(report.Filename) && dwDelItemOp == (uint)__VSDELETEITEMOPERATION.DELITEMOP_DeleteFromStorage)
            {
                // close the file if it's open before deleting it...
                var dte = (EnvDTE.DTE)NodejsProfilingPackage.GetGlobalService(typeof(EnvDTE.DTE));
                if (dte.ItemOperations.IsFileOpen(report.Filename))
                {
                    var doc = dte.Documents.Item(report.Filename);
                    doc.Close();
                }

                File.Delete(report.Filename);
            }

            return(VSConstants.S_OK);
        }
Exemple #3
0
        /// <summary>
        /// Create a StandaloneTargetView with default values.
        /// </summary>
        public StandaloneTargetView()
        {
            var componentService = (IComponentModel)(NodejsProfilingPackage.GetGlobalService(typeof(SComponentModel)));

            _interpreterPath  = Nodejs.NodeExePath ?? String.Empty;
            _scriptPath       = String.Empty;
            _workingDirectory = String.Empty;
            _arguments        = null;

            _isValid = false;

            PropertyChanged += new PropertyChangedEventHandler(StandaloneTargetView_PropertyChanged);
        }
Exemple #4
0
        private void OpenProfile(uint itemid)
        {
            var item = GetReport(itemid);

            if (!File.Exists(item.Filename))
            {
                MessageBox.Show(string.Format(CultureInfo.CurrentCulture, Resources.PerformanceReportNoLongerExistsMessageText, item.Filename), Resources.NodejsToolsForVS);
            }
            else
            {
                var dte = (EnvDTE.DTE)NodejsProfilingPackage.GetGlobalService(typeof(EnvDTE.DTE));
                dte.ItemOperations.OpenFile(item.Filename);
            }
        }
Exemple #5
0
        private void OpenProfile(uint itemid)
        {
            var item = GetReport(itemid);

            if (!File.Exists(item.Filename))
            {
                MessageBox.Show(String.Format("Performance report no longer exists: {0}", item.Filename), Resources.NodejsToolsForVS);
            }
            else
            {
                var dte = (EnvDTE.DTE)NodejsProfilingPackage.GetGlobalService(typeof(EnvDTE.DTE));
                dte.ItemOperations.OpenFile(item.Filename);
            }
        }
        private SessionNode AddPerformanceSession(string baseName, ProfilingTarget target)
        {
            var dte = (EnvDTE.DTE)NodejsProfilingPackage.GetGlobalService(typeof(EnvDTE.DTE));

            string filename;
            int?   id   = null;
            bool   save = false;

            do
            {
                filename = baseName + id + PerfFileType;
                if (dte.Solution.IsOpen && !String.IsNullOrEmpty(dte.Solution.FullName))
                {
                    filename = Path.Combine(Path.GetDirectoryName(dte.Solution.FullName), filename);
                    save     = true;
                }
                id = (id ?? 0) + 1;
            } while (File.Exists(filename));
            return(ShowPerformanceExplorer().Sessions.AddTarget(target, filename, save));
        }
Exemple #7
0
        internal string GetProfilingName(out bool save)
        {
            string baseName = null;

            if (ProjectTarget != null)
            {
                if (!String.IsNullOrEmpty(ProjectTarget.FriendlyName))
                {
                    baseName = ProjectTarget.FriendlyName;
                }
            }
            else if (StandaloneTarget != null)
            {
                if (!String.IsNullOrEmpty(StandaloneTarget.Script))
                {
                    baseName = Path.GetFileNameWithoutExtension(StandaloneTarget.Script);
                }
            }

            if (baseName == null)
            {
                baseName = "Performance";
            }

            baseName = baseName + NodejsProfilingPackage.PerfFileType;

            var dte = (EnvDTE.DTE)NodejsProfilingPackage.GetGlobalService(typeof(EnvDTE.DTE));

            if (dte.Solution.IsOpen && !String.IsNullOrEmpty(dte.Solution.FullName))
            {
                save = true;
                return(Path.Combine(Path.GetDirectoryName(dte.Solution.FullName), baseName));
            }

            save = false;
            return(baseName);
        }
 /// <summary>
 /// Default constructor of the package.
 /// Inside this method you can place any initialization code that does not require 
 /// any Visual Studio service because at this point the package object is created but 
 /// not sited yet inside Visual Studio environment. The place to do all the other 
 /// initialization is the Initialize method.
 /// </summary>
 public NodejsProfilingPackage() {
     Instance = this;
 }
        public ProfilingSessionEditorFactory(NodejsProfilingPackage package) {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering {0} constructor", this.ToString()));

            this._editorPackage = package;
        }
 /// <summary>
 /// Default constructor of the package.
 /// Inside this method you can place any initialization code that does not require
 /// any Visual Studio service because at this point the package object is created but
 /// not sited yet inside Visual Studio environment. The place to do all the other
 /// initialization is the Initialize method.
 /// </summary>
 public NodejsProfilingPackage()
 {
     Instance = this;
 }
        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;
        }
Exemple #12
0
        public ProfilingSessionEditorFactory(NodejsProfilingPackage package)
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering {0} constructor", this.ToString()));

            this._editorPackage = package;
        }
 /// <summary>
 /// Default constructor of the package.
 /// Inside this method you can place any initialization code that does not require
 /// any Visual Studio service because at this point the package object is created but
 /// not sited yet inside Visual Studio environment. The place to do all the other
 /// initialization is the Initialize method.
 /// </summary>
 public NodejsProfilingPackage()
 {
     UIThread.InitializeAndAlwaysInvokeToCurrentThread();
     Instance = this;
 }
Exemple #14
0
        internal void Removed()
        {
            IVsRunningDocumentTable rdt = NodejsProfilingPackage.GetGlobalService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            ErrorHandler.ThrowOnFailure(rdt.UnlockDocument((uint)_VSRDTFLAGS.RDT_EditLock, _docCookie));
        }
Exemple #15
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);
            }
Exemple #16
0
        public override int ExecCommand(uint itemid, ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == VsMenus.guidVsUIHierarchyWindowCmds)
            {
                switch ((VSConstants.VsUIHierarchyWindowCmdIds)nCmdID)
                {
                case VSConstants.VsUIHierarchyWindowCmdIds.UIHWCMDID_DoubleClick:
                case VSConstants.VsUIHierarchyWindowCmdIds.UIHWCMDID_EnterKey:
                    if (itemid == VSConstants.VSITEMID_ROOT)
                    {
                        OpenTargetProperties();

                        // S_FALSE: don't process the double click to expand the item
                        return(VSConstants.S_FALSE);
                    }
                    else if (IsReportItem(itemid))
                    {
                        OpenProfile(itemid);
                    }

                    return((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED);

                case VSConstants.VsUIHierarchyWindowCmdIds.UIHWCMDID_RightClick:
                    int?ctxMenu = null;

                    if (itemid == VSConstants.VSITEMID_ROOT)
                    {
                        ctxMenu = (int)PkgCmdIDList.menuIdPerfContext;
                    }
                    else if (itemid == ReportsItemId)
                    {
                        ctxMenu = (int)PkgCmdIDList.menuIdPerfReportsContext;
                    }
                    else if (IsReportItem(itemid))
                    {
                        ctxMenu = (int)PkgCmdIDList.menuIdPerfSingleReportContext;
                    }

                    if (ctxMenu != null)
                    {
                        var uishell = (IVsUIShell)NodejsProfilingPackage.GetGlobalService(typeof(SVsUIShell));
                        if (uishell != null)
                        {
                            var pt   = System.Windows.Forms.Cursor.Position;
                            var pnts = new[] { new POINTS {
                                                   x = (short)pt.X, y = (short)pt.Y
                                               } };
                            var guid = ProfilingGuids.NodejsProfilingCmdSet;
                            int hr   = uishell.ShowContextMenu(
                                0,
                                ref guid,
                                ctxMenu.Value,
                                pnts,
                                new ContextCommandTarget(this, itemid));

                            ErrorHandler.ThrowOnFailure(hr);
                        }
                    }

                    break;
                }
            }

            return(base.ExecCommand(itemid, ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }