Skip to content

Commit

Permalink
Merge pull request #1164 from sharwell/stats-tweaks
Browse files Browse the repository at this point in the history
Improvements for statistics gathering in StyleCopTester
  • Loading branch information
sharwell committed Aug 8, 2015
2 parents 03b688f + 4251c95 commit ac434f9
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions StyleCop.Analyzers/StyleCopTester/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace StyleCopTester
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
Expand Down Expand Up @@ -47,10 +48,12 @@ private static void Main(string[] args)

if (!args.Contains("/nostats"))
{
Console.WriteLine("Number of projects:\t\t" + solution.ProjectIds.Count);
Console.WriteLine("Number of documents:\t\t" + solution.Projects.Sum(x => x.DocumentIds.Count));
List<Project> csharpProjects = solution.Projects.Where(i => i.Language == LanguageNames.CSharp).ToList();

var statistics = GetAnalyzerStatistics(solution);
Console.WriteLine("Number of projects:\t\t" + csharpProjects.Count);
Console.WriteLine("Number of documents:\t\t" + csharpProjects.Sum(x => x.DocumentIds.Count));

var statistics = GetAnalyzerStatistics(csharpProjects);

Console.WriteLine("Number of syntax nodes:\t\t" + statistics.NumberofNodes);
Console.WriteLine("Number of syntax tokens:\t" + statistics.NumberOfTokens);
Expand Down Expand Up @@ -79,27 +82,17 @@ private static void Main(string[] args)
}
}

private static Statistic GetAnalyzerStatistics(Solution solution)
private static Statistic GetAnalyzerStatistics(IEnumerable<Project> projects)
{
ThreadLocal<Statistic> sums = new ThreadLocal<Statistic>(() => new Statistic(0, 0, 0), true);

foreach (var project in solution.Projects)
{
Parallel.ForEach(project.Documents, document =>
{
var documentStatistics = GetAnalyzerStatistics(document).ConfigureAwait(false).GetAwaiter().GetResult();
var value = sums.Value;
sums.Value = value + documentStatistics;
});
}
ConcurrentBag<Statistic> sums = new ConcurrentBag<Statistic>();

Statistic sum = new Statistic(0, 0, 0);
foreach (var value in sums.Values)
Parallel.ForEach(projects.SelectMany(i => i.Documents), document =>
{
sum += value;
}
var documentStatistics = GetAnalyzerStatistics(document).ConfigureAwait(false).GetAwaiter().GetResult();
sums.Add(documentStatistics);
});

Statistic sum = sums.Aggregate(new Statistic(0, 0, 0), (currentResult, value) => currentResult + value);
return sum;
}

Expand Down

0 comments on commit ac434f9

Please sign in to comment.