/// <summary> /// Parse a provider input definition /// This function can retrieve provider from Name definition or Guid definition /// /// A name definition is associated with a manifest based provider and function will /// check if the provider is recorded on current workstation /// /// If name is not found we will try to parse Guid definition. /// A Guid definition must follow : /// TYPE{GUID} /// When /// TYPE: Manifest | TL | WPP /// GUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /// /// </summary> /// <param name="name">input provider definition</param> /// <returns>ProviderGuid definition</returns> public static ProviderGuid Parse(string name) { var providerGuid = TraceEventProviders.GetProviderGuidByName(name); if (providerGuid != Guid.Empty) { return(new ProviderGuid { Type = ProviderType.Manifest, Guid = providerGuid }); } var matches = PATTERN.Matches(name); if (matches.Count != 1) { throw new Exception("Invalid Provider Format"); } GroupCollection matchGroup = matches[0].Groups; return(new ProviderGuid { Type = (ProviderType)Enum.Parse(typeof(ProviderType), matchGroup["type"].Value), Guid = Guid.Parse(matchGroup["guid"].Value) }); }
private static void RealTimeSession() { if (options.ParsedClrKeywords == 0 && options.ParsedKernelKeywords == KernelTraceEventParser.Keywords.None && options.OtherProviders.Count == 0) { Bail("No events to collect"); } Console.CancelKeyPress += (_, __) => CloseSession(); if (options.DurationInSeconds > 0) { Task.Delay(TimeSpan.FromSeconds(options.DurationInSeconds)) .ContinueWith(_ => CloseSession()); } using (session = new TraceEventSession("etrace-realtime-session")) { if (options.ParsedKernelKeywords != KernelTraceEventParser.Keywords.None) { session.EnableKernelProvider(options.ParsedKernelKeywords); } if (options.ParsedClrKeywords != 0) { session.EnableProvider(ClrTraceEventParser.ProviderGuid, matchAnyKeywords: (ulong)options.ParsedClrKeywords); } if (options.OtherProviders.Any()) { foreach (var provider in options.OtherProviders) { Guid guid; if (Guid.TryParse(provider, out guid)) { session.EnableProvider(Guid.Parse(provider)); } else { guid = TraceEventProviders.GetProviderGuidByName(provider); if (guid != Guid.Empty) { session.EnableProvider(guid); } } } } if (options.IsOutFile) { outRelogger = new ETWReloggerTraceEventSource(session.SessionName, TraceEventSourceType.Session, options.OutFile); isOutReloggerSet = true; ProcessTrace(outRelogger); } else { ProcessTrace(session.Source); } } }
private void ThreadCallback(object state) { using (var session = new TraceEventSession("MyRealTimeSession")) { var providerName = "Microsoft-Windows-DotNETRuntime"; var eventSourceGuid = TraceEventProviders.GetProviderGuidByName(providerName); session.EnableProvider(eventSourceGuid); session.Source.Clr.GCHeapStats += ClrOnGcHeapStats; session.Source.Clr.GCStart += ClrOnGcStart; session.Source.Clr.GCStop += Clr_GCStop; session.Source.Process(); } }
private void RunAsync() { var elevated = TraceEventSession.IsElevated(); var eventSourceGuid = TraceEventProviders.GetProviderGuidByName(providerName); session = new TraceEventSession(sessionName, "data.etl"); kernelSession = new TraceEventSession(KernelTraceEventParser.KernelSessionName, "data.kernel.etl"); kernelSession.EnableKernelProvider(KernelTraceEventParser.Keywords.ImageLoad | KernelTraceEventParser.Keywords.Process | KernelTraceEventParser.Keywords.Thread); var optionsWithStacks = new TraceEventProviderOptions() { StacksEnabled = true }; session.EnableProvider(ClrTraceEventParser.ProviderGuid, TraceEventLevel.Verbose, (ulong)ClrTraceEventParser.Keywords.Default); session.EnableProvider(ClrTraceEventParser.ProviderGuid, TraceEventLevel.Verbose, (ulong)ClrTraceEventParser.Keywords.GC, optionsWithStacks); }
public static EventSourceDefinition Parse(string providerName, ulong matchAnyKeywords, int traceLevel, IEnumerable <int> ids, IEnumerable <int> processIds, IEnumerable <string> processNames) { Guid providerGuid = TraceEventProviders.GetProviderGuidByName(providerName); if (providerGuid == Guid.Empty) { providerGuid = TraceEventProviders.GetEventSourceGuidFromName(providerName); if (providerGuid == Guid.Empty) { throw new ArgumentException(string.Format("Provider name doesn't exist: {0}", providerName)); } } var definition = new EventSourceDefinition() { ProviderName = providerName, ProviderGuid = providerGuid, Keywords = matchAnyKeywords, TraceLevel = (TraceEventLevel)traceLevel, }; if (ids != null) { var idList = new List <int>(ids); definition.Ids = idList.Count > 0 ? idList : null; } if (processIds != null) { var processIdList = new List <int>(processIds); definition.ProcessIds = processIdList.Count > 0 ? processIdList : null; } if (processNames != null) { var processNameList = new List <string>(processNames); definition.ProcessNames = processNameList.Count > 0 ? processNameList : null; } return(definition); }
private void ProviderSelected(object sender, SelectionChangedEventArgs e) { var selectedItem = ProviderNameListBox.SelectedItem; if (selectedItem != null) { m_selectedProvider = selectedItem.ToString(); m_keys = new Dictionary <string, ProviderDataItem>(); foreach (var keyword in TraceEventProviders.GetProviderKeywords(TraceEventProviders.GetProviderGuidByName(m_selectedProvider))) { m_keys.Add(keyword.Name.ToString(), keyword); } m_keyStrings = new List <String>(); foreach (var key in m_keys.Keys) { m_keyStrings.Add(m_keys[key].Name.ToString()); } KeyNameListBox.ItemsSource = m_keyStrings; m_selectedKeys = new List <string>(); updateDisplays(); } }
private static void RealTimeSession() { if (options.ParsedClrKeywords == 0 && options.ParsedKernelKeywords == KernelTraceEventParser.Keywords.None && options.ParsedFrameworkEventKeywords == 0 && options.OtherProviders.Count == 0) { Bail("No events to collect"); } Console.CancelKeyPress += (_, __) => CloseSession(); if (options.DurationInSeconds > 0) { Task.Delay(TimeSpan.FromSeconds(options.DurationInSeconds)) .ContinueWith(_ => CloseSession()); } using (session = new TraceEventSession("etrace-realtime-session")) { if (options.ParsedKernelKeywords != KernelTraceEventParser.Keywords.None) { session.EnableKernelProvider(options.ParsedKernelKeywords); } if (options.ParsedClrKeywords != 0) { session.EnableProvider(ClrTraceEventParser.ProviderGuid, matchAnyKeywords: (ulong)options.ParsedClrKeywords); } if (options.ParsedFrameworkEventKeywords != 0) { session.EnableProvider(FrameworkEventSourceTraceEventParser.ProviderGuid, matchAnyKeywords: (ulong)options.ParsedFrameworkEventKeywords); if (options.HttpStatsOnly) { var ep = eventProcessor as HttpEventStatisticsAggregator; ep.parser = new FrameworkEventSourceTraceEventParser(session.Source); ep.options = options; ep.SetupHttpStatsParsing(options); } else if (options.HttpLatencyStatsOnly) { var ep = eventProcessor as HttpEventStatisticsAggregator; ep.parser = new FrameworkEventSourceTraceEventParser(session.Source); ep.options = options; ep.SetupHttpLatencyParsing(options); } } if (options.OtherProviders.Any()) { foreach (var provider in options.OtherProviders) { Guid guid; if (Guid.TryParse(provider, out guid)) { session.EnableProvider(Guid.Parse(provider)); } else { guid = TraceEventProviders.GetProviderGuidByName(provider); if (guid != Guid.Empty) { session.EnableProvider(guid); } } } } ProcessTrace(session.Source); } }