public static string Start(string etlPath, IEnumerable <ProviderInfo> providerInfo, int bufferSizeMB = 64) { EnsureUnloadHandlerRegistered(); var userSessionName = "xunit.performance.logger." + Guid.NewGuid().ToString(); Sessions sessions = new Sessions(); sessions.UserFileName = Path.ChangeExtension(etlPath, ".user.etl"); sessions.KernelFileName = Path.ChangeExtension(etlPath, ".kernel.etl"); sessions.MergedFileName = etlPath; var mergedProviderInfo = ProviderInfo.Merge(providerInfo); try { sessions.UserSession = new TraceEventSession(userSessionName, sessions.UserFileName); sessions.UserSession.BufferSizeMB = bufferSizeMB; if (IsWin8OrGreater) { var availableCpuCounters = TraceEventProfileSources.GetInfo(); var cpuCounterIds = new List <int>(); var cpuCounterIntervals = new List <int>(); foreach (var cpuInfo in mergedProviderInfo.OfType <CpuCounterInfo>()) { ProfileSourceInfo profInfo; if (availableCpuCounters.TryGetValue(cpuInfo.CounterName, out profInfo)) { cpuCounterIds.Add(profInfo.ID); cpuCounterIntervals.Add(Math.Min(profInfo.MaxInterval, Math.Max(profInfo.MinInterval, cpuInfo.Interval))); } } if (cpuCounterIds.Count > 0) { TraceEventProfileSources.Set(cpuCounterIds.ToArray(), cpuCounterIntervals.ToArray()); } } var kernelInfo = mergedProviderInfo.OfType <KernelProviderInfo>().FirstOrDefault(); if (kernelInfo != null && NeedSeparateKernelSession(kernelInfo.Keywords)) { sessions.KernelSession = new TraceEventSession(KernelTraceEventParser.KernelSessionName, sessions.KernelFileName); sessions.KernelSession.BufferSizeMB = bufferSizeMB; } else { sessions.KernelFileName = sessions.UserFileName; sessions.KernelSession = sessions.UserSession; } if (kernelInfo != null) { var kernelKeywords = (KernelTraceEventParser.Keywords)kernelInfo.Keywords; var kernelStackKeywords = (KernelTraceEventParser.Keywords)kernelInfo.StackKeywords; sessions.KernelSession.EnableKernelProvider(kernelKeywords, kernelStackKeywords); } foreach (var userInfo in mergedProviderInfo.OfType <UserProviderInfo>()) { sessions.UserSession.EnableProvider(userInfo.ProviderGuid, userInfo.Level, userInfo.Keywords); } s_sessions[userSessionName] = sessions; } catch { sessions.Close(); throw; } return(userSessionName); }