Exemple #1
0
 public static RunTimer CreateGeneratorDriverRunTimer(this CodeAnalysisEventSource eventSource)
 {
     if (eventSource.IsEnabled(EventLevel.Informational, Keywords.Performance))
     {
         var id = Guid.NewGuid().ToString();
         eventSource.StartGeneratorDriverRunTime(id);
         return(new RunTimer(t => eventSource.StopGeneratorDriverRunTime(t.Ticks, id)));
     }
     else
     {
         return(new RunTimer());
     }
 }
Exemple #2
0
 public static RunTimer CreateSingleGeneratorRunTimer(this CodeAnalysisEventSource eventSource, ISourceGenerator generator, Func <TimeSpan, TimeSpan> adjustRunTime)
 {
     if (eventSource.IsEnabled(EventLevel.Informational, Keywords.Performance))
     {
         var id   = Guid.NewGuid().ToString();
         var type = generator.GetGeneratorType();
         eventSource.StartSingleGeneratorRunTime(type.FullName !, type.Assembly.Location, id);
         return(new RunTimer(t => eventSource.StopSingleGeneratorRunTime(type.FullName !, type.Assembly.Location, t.Ticks, id), adjustRunTime));
     }
     else
     {
         return(new RunTimer(adjustRunTime));
     }
 }