예제 #1
0
        //-------------------------------------------------------------------------

        private static void OutputStats(BuildTag tag)
        {
            Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine();

            if (tag != null)
            {
                Console.WriteLine(
                    "Tag: {0}" + Environment.NewLine,
                    tag.Text);
            }

            Console.WriteLine(
                "{0,-20} | {1,-9} | {2,-5} | {3,-5} | {4,-5} | {5,-5} | {6,-5} | {7,-5} |",
                "Project",
                "Completed",
                "Tot h",
                "Tot m",
                "Avg m",
                "Avg s",
                "Max m",
                "Max s");

            Console.WriteLine("----------------------------------------------------------------------------------");

            double totTotalBuildTime = 0.0;
            double totAvgBuildTime   = 0.0;
            double totMaxBuildTime   = 0.0;

            foreach (Project prj in Project.GetProjects())
            {
                IBuildStatsProvider stats = prj.GetStats(tag?.Text);

                if (stats == null)
                {
                    continue;
                }

                Console.WriteLine(
                    "{0,-20} | {1,4}/{2,-4} | {3,5} | {4,5} | {5,5} | {6,5} | {7,5} | {8,5} |",
                    prj.Name,
                    stats.CompletedBuildsCount,
                    stats.TotalBuildsCount,
                    (int)stats.TotalBuildTime.TotalHours,
                    (int)stats.TotalBuildTime.TotalMinutes,
                    (int)stats.AverageBuildTime.TotalMinutes,
                    (int)stats.AverageBuildTime.TotalSeconds,
                    (int)stats.MaxBuildTime.TotalMinutes,
                    (int)stats.MaxBuildTime.TotalSeconds);

                totTotalBuildTime += stats.TotalBuildTime.TotalMinutes;
                totAvgBuildTime   += stats.AverageBuildTime.TotalMinutes;
                totMaxBuildTime   += stats.MaxBuildTime.TotalMinutes;
            }

            Console.WriteLine("----------------------------------------------------------------------------------");

            Console.WriteLine(
                "{0,-20} | {1,4} {2,-4} | {3,5} | {4,5} | {5,5} | {6,5} | {7,5} | {8,5} |",
                "",
                "",
                "",
                "",
                (int)totTotalBuildTime,
                (int)totAvgBuildTime,
                "",
                (int)totMaxBuildTime,
                "");

            Console.WriteLine(Environment.NewLine);
        }
예제 #2
0
        //-------------------------------------------------------------------------

        private void ProcessFilesAndOutputSummary(
            string[] files,
            bool significantBuildsOnly)
        {
            foreach (string f in files)
            {
                try
                {
                    // Parse the log file.
                    BuildLogFile log = new BuildLogFile(f);

                    string[] tags = log.GetTags();
                    IReadOnlyCollection <BuildLogFile.LogEntry> entries = log.GetEntries();

                    // Extract the project name.
                    string projectName = tags[1];

                    // Add log entries to collection.
                    foreach (BuildLogFile.LogEntry entry in entries)
                    {
                        if (LogEntriesByProject.ContainsKey(projectName) == false)
                        {
                            LogEntriesByProject.Add(projectName, new List <BuildLogFile.LogEntry>());
                        }

                        LogEntriesByProject[projectName].Add(entry);
                    }
                }
                catch (Exception)
                {
                    // TODO
                }
            }

            // Sort the entries.
            foreach (List <BuildLogFile.LogEntry> entries in LogEntriesByProject.Values)
            {
                entries.Sort();
            }

            // Create stats.
            foreach (string projectName in LogEntriesByProject.Keys)
            {
                Project project = Project.GetProject(projectName);

                List <BuildLogFile.LogEntry> entries = LogEntriesByProject[projectName];

                for (int i = 0; i < entries.Count - 1; i++)
                {
                    if (entries[i].EntryType == BuildLogFile.LogEntry.LogEntryType.BUILD_STARTED &&
                        entries[i + 1].EntryType == BuildLogFile.LogEntry.LogEntryType.BUILD_ENDED)
                    {
                        if (significantBuildsOnly == false ||
                            (entries[i + 1].Timestamp - entries[i].Timestamp).TotalSeconds > 5)
                        {
                            project.AddBuild(
                                entries[i].Timestamp,
                                entries[i + 1].Timestamp,
                                entries[i].Tags.ToArray());
                        }
                    }
                    else if (entries[i].EntryType == BuildLogFile.LogEntry.LogEntryType.BUILD_STARTED)
                    {
                        if (significantBuildsOnly == false)
                        {
                            project.AddBuild(
                                entries[i].Timestamp,
                                null,
                                entries[i].Tags.ToArray());
                        }
                    }
                }
            }

            foreach (Project prj in Project.GetProjects())
            {
                IBuildStatsProvider stats = prj.GetStats("All");

                Stats.Add(stats);
            }

            // Summary.
            foreach (BuildTag tag in BuildTag.GetTags())
            {
                OutputStats(tag);
            }
        }