public JitCapCollector(ETLDataFile etlDataFile) { this.EtlDataFile = etlDataFile; this.TraceLog = EtlDataFile.TraceLog; this.Source = TraceLog.Events.GetSource(); this.Report = new ClrCap.JitCapAnalysis(); }
public static ClrCap.JitCapAnalysis CreateJITCap(string etlFile, int methodCount = 20) { ETLDataFile EtlDataFile = new ETLDataFile(etlFile); TraceLog TraceLog = EtlDataFile.TraceLog; TraceLogEventSource Source = TraceLog.Events.GetSource(); using (ETLDataFile etlDataFile = new ETLDataFile(etlFile)) { TraceLog traceLog = etlDataFile.TraceLog; TraceLogEventSource source = traceLog.Events.GetSource(); using (ETWTraceEventModelSource model = new ETWTraceEventModelSource(source)) { model.DisableAll().EnableSamples().Configure(etlDataFile); ClrCap.JitCapAnalysis report = new ClrCap.JitCapAnalysis(); SetupCapCollectors(model.Source, report); model.Process(); //UpdateCommonInfo(etlFile, model.Source, report); ClrCap.CAP.GenerateJITCAPReport(model.Processes, report, methodCount); return(report); } } }
public void CalculateStatistics(string etlFileName, string providerName, string startEvent, string stopEvent, string outputReport = "report.xlsx") { Parser parser = new Parser(GetViewer(outputReport)); using (ETLDataFile etlFile = OpenETLFile(etlFileName)) { ParserArguments arguments = new ParserArguments { ProviderName = providerName, StartEvent = startEvent, StopEvent = stopEvent, OutputReport = outputReport }; TraceEvents events = GetTraceEventsWithProcessFilter(etlFile); parser.Parse(events, arguments); } }
/// <summary> /// Gets the TraceEvents list of events from etlFile, applying a process filter if the /process argument is given. /// </summary> private TraceEvents GetTraceEventsWithProcessFilter(ETLDataFile etlFile) { // If the user asked to focus on one process, do so. TraceEvents events; if (CommandLineArgs.Process != null) { var process = etlFile.Processes.LastProcessWithName(CommandLineArgs.Process); if (process == null) { throw new ApplicationException("Could not find process named " + CommandLineArgs.Process); } events = process.EventsInProcess; } else { events = etlFile.TraceLog.Events; // All events in the process. } return(events); }
public void OpenWcfEventsView(string etlFileName, string viewName) { ETLDataFile etlFile = OpenETLFile(etlFileName); TraceLog traceLog = etlFile.TraceLog; var eventSource = traceLog.Events.GetSource(); var stackSource = new InternStackSource(); StackSourceModuleIndex emptyModuleIdx = stackSource.Interner.ModuleIntern(""); var mySample = new StackSourceSample(stackSource); var operations = new List <OperationData>(); var opStartTimeStamps = new Dictionary <int, double>(); var pendingOps = new Dictionary <int, OperationData>(); eventSource.Dynamic.All += x => OnNewEvent(operations, opStartTimeStamps, pendingOps, x); eventSource.Process(); foreach (var op in operations) { mySample.TimeRelativeMSec = op.TimeStamp; mySample.Metric = (float)op.Duration.TotalMilliseconds; mySample.StackIndex = stackSource.Interner.CallStackIntern( stackSource.Interner.FrameIntern(op.Contract, emptyModuleIdx), StackSourceCallStackIndex.Invalid); mySample.StackIndex = stackSource.Interner.CallStackIntern( stackSource.Interner.FrameIntern(op.Name, emptyModuleIdx), mySample.StackIndex); stackSource.AddSample(mySample); } Stacks stacksForViewer = new Stacks(stackSource, viewName, etlFile); OpenStackViewer(stacksForViewer); }
/// <summary> /// If you place a file called PerfViewExtensions\PerfViewStartup next to the PerfView.exe it will /// run execute commands in that file. If you put /// /// DeclareFileView .etl "Demo View In Etl File" DemoDeclareFileView /// /// It will create a child node for all .etl files called 'Demo View In Etl File' If you click /// on this node it will execute this user command. It is passed the name of the file that was /// opened and the name of the view that was opened (in this case 'Demo View In Etl File'). /// </summary> public void DemoDeclareFileView(string fileName, string viewName) { // This demo creates a view that shows you all the START events in a stack view. LogFile.WriteLine("************ In DemoDeclareFileView file = {0} view = {1}", fileName, viewName); // This is an example of opening an ETL file. ETLDataFile etlFile = OpenETLFile(fileName); // An ETLData file is a high level construct that knows about high level 'views' of the data (CPU stacks, thread time Stacks ...) // However if you want to create a new view, you probably want a TraceLog which is the underlying ETW data. TraceLog traceLog = etlFile.TraceLog; // A tracelog represent the whole ETL file (which has process, images, threads etc), we want events, and we want callbacks // for each event which is what GetSource() does. THus we get a source (which we can add callbacks to) var eventSource = traceLog.Events.GetSource(); // At this point create the 'output' of our routine. Our goal is to produce stacks that we will view in the // stack viewer. Thus we create an 'empty' one fo these. var stackSource = new MutableTraceEventStackSource(traceLog); // A stack source is list of samples. We create a sample structure, mutate it and then call AddSample() repeatedly to add samples. var sample = new StackSourceSample(stackSource); // Setup the callbacks, In this case we are going to watch for stacks where GCs happen eventSource.Clr.GCStart += delegate(GCStartTraceData data) { // An TraceLog should have a callstack associated with this event; CallStackIndex callStackIdx = data.CallStackIndex(); if (callStackIdx != CallStackIndex.Invalid) { // Convert the TraceLog call stack to a MutableTraceEventStackSource call stack StackSourceCallStackIndex stackCallStackIndex = stackSource.GetCallStack(callStackIdx, data); // Add a pseudo frame on the bottom of the stack StackSourceFrameIndex frameIdxForName = stackSource.Interner.FrameIntern("GC Gen " + data.Depth + "Reason " + data.Reason); stackCallStackIndex = stackSource.Interner.CallStackIntern(frameIdxForName, stackCallStackIndex); // create a sample with that stack and add it to the stack source (list of samples) sample.Metric = 1; sample.TimeRelativeMSec = data.TimeStampRelativeMSec; sample.StackIndex = stackCallStackIndex; stackSource.AddSample(sample); } }; // You can set up other callback for other events. // This causes the TraceLog source to actually spin through all the events calling our callbacks as requested. eventSource.Process(); // We are done adding sample to our stack Source, so we tell the MutableTraceEventStackSource that. // after that is becomes viewable (and read-only). stackSource.DoneAddingSamples(); // Take the stack source (raw data) and make it into a 'Stacks' allows you to add filtering to and send to 'OpendStackViewer' Stacks stacksForViewer = new Stacks(stackSource, viewName, etlFile); // Set any filtering options here. // Now we can display the viewer. OpenStackViewer(stacksForViewer); }