コード例 #1
0
ファイル: Compiler.cs プロジェクト: brandon-kohn/Meta
 public Compiler(EnvDTE.Project proj, string file, IVsOutputWindowPane pane)
 {
     taskTimer = new TaskTimer("Compile " + file);
     project = proj;
     clTool = new VCCompilerHelper(project);
     filename = file;
     buildPane = pane;
 }
コード例 #2
0
ファイル: BuildProfiler.cs プロジェクト: kimgr/Meta
        private void Execute()
        {
            try
            {
                buildPane.Clear();
                buildPane.Activate();

                if (onlyFile == null)
                    buildPane.OutputStringThreadSafe("Starting Build Profile on " + project.Name + " (" + clTool.ActiveConfiguration.Name + "):" + Environment.NewLine);
                else
                    buildPane.OutputStringThreadSafe("Starting Build Profile on " + project.Name + "\\" + onlyFile + " (" + clTool.ActiveConfiguration.Name + "):" + Environment.NewLine);

                profilePane.Clear();
                profilePane.Activate();

                if (onlyFile == null)
                    profilePane.OutputStringThreadSafe("Starting Build Profile on " + project.Name + " (" + clTool.ActiveConfiguration.Name + "):" + Environment.NewLine);
                else
                    profilePane.OutputStringThreadSafe("Starting Build Profile on " + project.Name + "\\" + onlyFile + " (" + clTool.ActiveConfiguration.Name + "):" + Environment.NewLine);

                foreach (EnvDTE.ProjectItem i in project.ProjectItems)
                {
                    if (cancelBuild)
                    {
                        profilePane.OutputStringThreadSafe(Environment.NewLine + "User canceled build profile." + Environment.NewLine);
                        buildPane.OutputStringThreadSafe(Environment.NewLine + "User canceled build profile." + Environment.NewLine);
                        return;
                    }

                    if (!i.Saved)
                        i.Save("");
                }

                VCFile singleFile = null;
                if (onlyFile != null)
                    singleFile = clTool.GetVCFile(onlyFile);

                TaskTimer job = new TaskTimer("Total Build");
                job.StartTask("Total Build Time");

                profilePane.OutputStringThreadSafe(Environment.NewLine + String.Format("{0,-60}: {1,12}", "Translation Unit", "Compile Time (hh:mm:ss:ms)") + Environment.NewLine);
                StringBuilder divider = new StringBuilder(88);
                divider.Append('-', 88);
                profilePane.OutputStringThreadSafe(divider + Environment.NewLine + Environment.NewLine);

                if (singleFile == null)
                {
                    foreach (VCFile file in clTool.Project.GetFilesWithItemType("CLCompile"))
                    {
                        if (cancelBuild)
                        {
                            profilePane.OutputStringThreadSafe(Environment.NewLine + "User canceled build profile." + Environment.NewLine);
                            buildPane.OutputStringThreadSafe(Environment.NewLine + "User canceled build profile." + Environment.NewLine);
                            return;
                        }

                        if (System.IO.File.Exists(file.FullPath))
                        {
                            cl = new Compiler(project, file.ItemName, buildPane);
                            cl.Compile();
                            TimeSpan ts = cl.BuildTime;
                            data.Insert(ts, file.ItemName);
                            string elapsedTime = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D3}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
                            profilePane.OutputStringThreadSafe(String.Format("{0,-60}: {1,12}" + Environment.NewLine, file.ItemName, elapsedTime));
                        }
                        else
                            profilePane.OutputStringThreadSafe(Environment.NewLine + "File not found: " + file.ItemName);
                    }
                }
                else
                {
                    if (cancelBuild)
                    {
                        profilePane.OutputStringThreadSafe(Environment.NewLine + "User canceled build profile." + Environment.NewLine);
                        buildPane.OutputStringThreadSafe(Environment.NewLine + "User canceled build profile." + Environment.NewLine);
                        return;
                    }

                    if (System.IO.File.Exists(singleFile.FullPath))
                    {
                        cl = new Compiler(project, singleFile.ItemName, buildPane);
                        cl.Compile();
                        TimeSpan ts = cl.BuildTime;
                        data.Insert(ts, singleFile.ItemName);
                        string elapsedTime = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D3}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
                        profilePane.OutputStringThreadSafe(String.Format("{0,-60}: {1,12}" + Environment.NewLine, singleFile.ItemName, elapsedTime));
                    }
                    else
                        profilePane.OutputStringThreadSafe(Environment.NewLine + "File not found: " + singleFile.ItemName);
                }
                job.Stop();

                profilePane.OutputStringThreadSafe
                    (
                        Environment.NewLine + Environment.NewLine + "Summary: " +
                        Environment.NewLine + Environment.NewLine + "Total Build RunTime: " + job.Elapsed() +
                        Environment.NewLine + String.Format("{0,-60}: {1,12}", "Translation Unit", "Compile Time (hh:mm:ss:ms)") + Environment.NewLine +
                        divider + Environment.NewLine + Environment.NewLine
                    );
                var it = data.RBegin;
                while (it.MovePrev())
                {
                    TimeSpan ts = it.Current.Key;
                    string name = it.Current.Value;
                    string elapsedTime = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D3}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
                    profilePane.OutputStringThreadSafe(String.Format("{0,-60}: {1,12}" + Environment.NewLine, name, elapsedTime));
                }
            }
            catch (System.Exception ex)
            {
                profilePane.OutputStringThreadSafe(ex.Message);
            }
            finally
            {
                signalFinished();
            }
        }