Esempio n. 1
0
        public int DeleteItem(uint dwDelItemOp, uint itemid)
        {
            Debug.Assert(_target.Reports != null && _target.Reports.Report != null && _target.Reports.Report.Length > 0);

            Report[] reports  = new Report[_target.Reports.Report.Length - 1];
            var      report   = GetReport(itemid);
            var      deleting = itemid - StartingReportId;

            for (int i = 0, write = 0; i < _target.Reports.Report.Length; i++)
            {
                if (i + StartingReportId != itemid)
                {
                    reports[write++] = _target.Reports.Report[i];
                }
            }

            _target.Reports.Report = reports;
            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)PythonProfilingPackage.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);
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        private void OpenProfile(uint itemid)
        {
            var item = GetReport(itemid);

            if (!File.Exists(item.Filename))
            {
                MessageBox.Show(String.Format("Performance report no longer exits: {0}", item.Filename));
            }
            else
            {
                var dte = (EnvDTE.DTE)PythonProfilingPackage.GetGlobalService(typeof(EnvDTE.DTE));
                dte.ItemOperations.OpenFile(item.Filename);
            }
        }
Esempio n. 4
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 = PythonProfilingPackage.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;
        }
Esempio n. 5
0
        internal void Removed()
        {
            IVsRunningDocumentTable rdt = PythonProfilingPackage.GetGlobalService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            ErrorHandler.ThrowOnFailure(rdt.UnlockDocument((uint)_VSRDTFLAGS.RDT_EditLock, _docCookie));
        }
Esempio n. 6
0
            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);
            }