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); }
/// <summary> /// Create a ProfilingTargetView with default values. /// </summary> public ProfilingTargetView(IServiceProvider serviceProvider) { var solution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution; var availableProjects = new List<ProjectTargetView>(); foreach (var project in solution.EnumerateLoadedProjects()) { availableProjects.Add(new ProjectTargetView((IVsHierarchy)project)); } _availableProjects = new ReadOnlyCollection<ProjectTargetView>(availableProjects); _project = null; _standalone = new StandaloneTargetView(serviceProvider); _isProjectSelected = true; _isValid = false; PropertyChanged += new PropertyChangedEventHandler(ProfilingTargetView_PropertyChanged); _standalone.PropertyChanged += new PropertyChangedEventHandler(Standalone_PropertyChanged); var startupProject = PythonProfilingPackage.GetStartupProjectGuid(serviceProvider); Project = AvailableProjects.FirstOrDefault(p => p.Guid == startupProject) ?? AvailableProjects.FirstOrDefault(); if (Project != null) { IsStandaloneSelected = false; IsProjectSelected = true; } else { IsProjectSelected = false; IsStandaloneSelected = true; } _startText = "_Start"; }
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 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); } }
/// <summary> /// Create a ProfilingTargetView with default values. /// </summary> public ProfilingTargetView(IServiceProvider serviceProvider) { var solution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution; var availableProjects = new List <ProjectTargetView>(); foreach (var project in solution.EnumerateLoadedProjects()) { availableProjects.Add(new ProjectTargetView((IVsHierarchy)project)); } _availableProjects = new ReadOnlyCollection <ProjectTargetView>(availableProjects); _project = null; _standalone = new StandaloneTargetView(serviceProvider); _isProjectSelected = true; _isValid = false; _useVTune = false; #if EXTERNAL_PROFILER_DRIVER _isVTuneAvailable = PythonProfilingPackage.CheckForExternalProfiler(); _isExternalProfilerEnabled = true; #else _isVTuneAvailable = false; _isExternalProfilerEnabled = false; #endif PropertyChanged += new PropertyChangedEventHandler(ProfilingTargetView_PropertyChanged); _standalone.PropertyChanged += new PropertyChangedEventHandler(Standalone_PropertyChanged); var startupProject = PythonProfilingPackage.GetStartupProjectGuid(serviceProvider); Project = AvailableProjects.FirstOrDefault(p => p.Guid == startupProject) ?? AvailableProjects.FirstOrDefault(); if (Project != null) { IsStandaloneSelected = false; IsProjectSelected = true; } else { IsProjectSelected = false; IsStandaloneSelected = true; } _startText = Strings.LaunchProfiling_Start; }
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; }
public ProfilingSessionEditorFactory(PythonProfilingPackage 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 PythonProfilingPackage() { Instance = this; }
internal void Removed() { IVsRunningDocumentTable rdt = PythonProfilingPackage.GetGlobalService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; ErrorHandler.ThrowOnFailure(rdt.UnlockDocument((uint)_VSRDTFLAGS.RDT_EditLock, _docCookie)); }
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); }