Example #1
0
 public StatusTextWriter(StatusBar statusBar, TextWriter stream)
 {
     m_statusBar = statusBar;
     m_stream    = stream;
 }
Example #2
0
        /// <summary>
        /// Called when the application is started.
        /// </summary>
        private void ApplicationStarted()
        {
            MainWindow = new MainWindow();
            var logFile = File.CreateText(App.LogFileName);

            StatusBar.AttachWriterToLogStream(logFile);
            App.CommandProcessor.LogFile = MainWindow.StatusBar.LogWriter;

            // Work around for Non-English/US locale (e.g. French) where among other things the decimal point is a comma.
            // WPF never uses the CurrentCulture when it formats numbers (it always uses US)
            // This sets the default to the current culture.
            // see http://serialseb.blogspot.com/2007/04/wpf-tips-1-have-all-your-dates-times.html
            FrameworkElement.LanguageProperty.OverrideMetadata(
                typeof(FrameworkElement),
                new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            if (App.CommandLineArgs.HelpRequested)
            {
                MainWindow.Show();
                MainWindow.DoCommandLineHelp(null, null);
                return;
            }

            MainWindow.StatusBar.LogWriter.WriteLine("Started with command line: {0}", Environment.CommandLine);
            MainWindow.StatusBar.LogWriter.WriteLine("PerfView Version: {0}  BuildDate: {1}", AppLog.VersionNumber, AppLog.BuildDate);
            MainWindow.StatusBar.LogWriter.WriteLine("PerfView Start Time {0}", DateTime.Now);

            if (App.NeedsEulaConfirmation(App.CommandLineArgs))
            {
                var  eula     = new PerfView.Dialogs.EULADialog(MainWindow);
                bool?accepted = eula.ShowDialog();
                if (!(accepted ?? false))
                {
                    Environment.Exit(-10);
                }

                App.AcceptEula();       // Remember that we have accepted the EULA for next time.
            }

            MainWindow.Loaded += delegate(object sender, RoutedEventArgs ev)
            {
                string[] providers = App.CommandLineArgs.Providers;

                if (App.CommandLineArgs.CommandLineFailure != null)
                {
                    var message = App.CommandLineArgs.CommandLineFailure.Message;
                    if (message.Contains("\n"))
                    {
                        MainWindow.StatusBar.LogError("Command Line Error, see log file for details.");
                        MainWindow.StatusBar.Log(message);
                    }
                    else
                    {
                        MainWindow.StatusBar.LogError("Command Line Error: " + message);
                    }

                    return;
                }

                if (App.CommandLineArgs.DoCommand == null)
                {
                    App.CommandLineArgs.DoCommand = App.CommandProcessor.View;
                }

                string commandName  = "View";
                Action continuation = delegate
                {
                    if (App.CommandLineArgs.DataFile != null)
                    {
                        MainWindow.OpenPath(App.CommandLineArgs.DataFile);
                    }
                };
                if (App.CommandLineArgs.DoCommand != App.CommandProcessor.View)
                {
                    commandName  = App.CommandLineArgs.DoCommand.Method.Name;
                    continuation = null;
                }

                // Run commands in the PerfViewExtensions\PerfViewStartup file.
                PerfViewExtensibility.Extensions.RunUserStartupCommands(MainWindow.StatusBar);
                MainWindow.OpenPreviouslyOpened();
                MainWindow.ExecuteCommand(commandName, App.CommandLineArgs.DoCommand, null, continuation);
            };
            MainWindow.Show();
        }
Example #3
0
        void LaunchViewer(List <IProcess> selectedProcesses)
        {
            // Single process only
            if (selectedProcesses != null && selectedProcesses.Count != 1)
            {
                return;
            }

            IProcess proc = selectedProcesses[0];

            int procID = proc.ProcessID;

            // Create the application's main window
            m_mainWindow       = new Window();
            m_mainWindow.Title = String.Format(FullTitle, proc.Name, procID);

            // HelpBox
            m_helpBox = new TextBox();
            m_helpBox.TextWrapping = TextWrapping.Wrap;
            m_helpBox.Foreground   = Brushes.Blue;

            m_statusBar        = new StatusBar();
            m_statusBar.Height = 24;

            // GCInfoView Panel
            GcInfoView gcinfo = new GcInfoView();

            // Grid for 5 panels with adjustable heights
            Grid grid = new Grid();

            m_gcInfoPanel = new GridRow(grid, gcinfo.CreateGCInfoPanel(m_helpBox).Wrap(GCEventPanelName), true, true, 0, 111);

            // HeapTickView Panel
            HeapAllocView heapAlloc = new HeapAllocView();

            m_heapAllocPanel = new GridRow(grid, heapAlloc.CreateHeapAllocPanel(m_traceLog).Wrap(AllocTickPanelName), false, true, 1, 111);

            // Thread Panel
            ThreadView threadView = new ThreadView();

            m_threadPanel = new GridRow(grid, threadView.CreateThreadViewPanel().Wrap(ThreadPanelName), false, true, 2, 111);

            // Issue Panel
            IssueView issue = new IssueView();

            m_issuePanel = new GridRow(grid, issue.CreateIssuePanel(m_helpBox).Wrap(IssuePanelName), false, true, 3, 111);

            // HeapDiagram Panel
            HeapDiagram diagram = new HeapDiagram(m_dataFile, m_statusBar, m_mainWindow);

            m_heapDiagramPanel = new GridRow(grid, diagram.CreateHeapDiagramPanel(m_helpBox).Wrap(HeapDiagramPanelName), true, false, 4, 111);

            DockPanel main = new DockPanel();

            main.DockBottom(m_statusBar);

            main.DockTop(CreateMainMenu());
            main.DockBottom(grid);

            m_mainWindow.Content = main;
            m_mainWindow.Closed += CloseMainWindow;
            m_mainWindow.Show();

            // Load events for the process
            m_heapInfo = new ProcessMemoryInfo(m_traceLog, m_dataFile, m_statusBar);

            m_statusBar.StartWork(String.Format("Loading events for process {0} (pid={1})", proc.Name, procID), delegate()
            {
                m_heapInfo.LoadEvents(procID, (int)m_traceLog.SampleProfileInterval.Ticks);

                m_statusBar.EndWork(delegate()
                {
                    gcinfo.SetGCEvents(m_heapInfo.GcEvents);
                    heapAlloc.SetAllocEvents(m_heapInfo.m_allocSites);
                    threadView.SetData(m_heapInfo);
                    diagram.SetData(m_heapInfo);
                    issue.SetData(m_heapInfo);
                });
            });
        }