Esempio n. 1
0
        /// <summary>
        /// Creates a new ProfilerRunner using a ProcessStartInfo and a data writer.
        /// </summary>
        public ProfilerRunner(ProcessStartInfo startInfo, bool useTempFileDatabase, IProfilingDataWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (startInfo == null)
            {
                throw new ArgumentNullException("startInfo");
            }

            if (useTempFileDatabase)
            {
                this.database = new TempFileDatabase();
                this.writer   = writer;
                this.profiler = new Controller.Profiler(startInfo, this.database.GetWriter(), General.CreateProfilerOptions());
            }
            else
            {
                this.database = null;
                this.writer   = writer;
                this.profiler = new Controller.Profiler(startInfo, writer, General.CreateProfilerOptions());
            }

            PrintProfilerOptions();
            this.profiler.RegisterFailed   += delegate { MessageService.ShowError("${res:AddIns.Profiler.Messages.RegisterFailed}"); };
            this.profiler.DeregisterFailed += delegate { MessageService.ShowError("${res:AddIns.Profiler.Messages.UnregisterFailed}"); };
            this.profiler.OutputUpdated    += delegate { SetOutputText(profiler.ProfilerOutput); };
            this.profiler.SessionEnded     += delegate { FinishSession(); };
        }
        private void btnRun_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter     = "Programs|*.exe|All files|*.*";
            dlg.DefaultExt = ".exe";
            if (!(dlg.ShowDialog() ?? false))
            {
                return;
            }
            string path = dlg.FileName;

            // remove UI before disposing profiler
            //this.timeLine.ValuesList.Clear();
            if (this.provider != null)
            {
                this.provider.Close();
            }

            if (this.profiler != null)
            {
                this.profiler.Dispose();
            }

            string pathToDb = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(Profiler.Controller.Profiler).Assembly.Location), "output.sdps");

            if (File.Exists(pathToDb))
            {
                File.Delete(pathToDb);
            }

            this.database = new TempFileDatabase();

            this.profiler              = new Profiler.Controller.Profiler(path, database.GetWriter(), new ProfilerOptions());
            profiler.RegisterFailed   += delegate { MessageBox.Show("register failed"); };
            profiler.DeregisterFailed += delegate { MessageBox.Show("deregister failed"); };

            this.profiler.OutputUpdated += profiler_OutputUpdated;
            this.profiler.SessionEnded  += profiler_SessionEnded;

            this.profiler.Start();

            this.btnRun.IsEnabled  = false;
            this.btnStop.IsEnabled = true;
        }