public static StackSource SingleEventTypeStack(this TraceEvents events, TraceProcess process = null, Predicate <TraceEvent> predicate = null)
        {
            // optimization only
            if (process != null)
            {
                var start = Math.Max(events.StartTimeRelativeMSec, process.StartTimeRelativeMsec);
                var end   = Math.Min(events.EndTimeRelativeMSec, process.EndTimeRelativeMsec);
                events = events.FilterByTime(start, end);
                events = events.Filter(x => (predicate == null || predicate(x)) && x.ProcessID == process.ProcessID);
            }
            else
            {
                events = events.Filter(x => (predicate == null || predicate(x)) && x.ProcessID != 0); // TODO: Is it really correc that x.ProcessID != 0 should be there? What if we want see these?
            }

            var traceStackSource = new TraceEventStackSource(events)
            {
                ShowUnknownAddresses = true
            };

            return(CopyStackSource.Clone(traceStackSource));
        }
示例#2
0
        public static StackSource CPUStacks(
            this Microsoft.Diagnostics.Tracing.Etlx.TraceLog eventLog,
            Microsoft.Diagnostics.Tracing.Etlx.TraceProcess process = null,
            Predicate <TraceEvent> predicate = null)
        {
            Microsoft.Diagnostics.Tracing.Etlx.TraceEvents events;

            if (process == null)
            {
                events = eventLog.Events.Filter((x) => ((predicate == null) || predicate(x)) && x is SampledProfileTraceData && x.ProcessID != 0);
            }
            else
            {
                events = process.EventsInProcess.Filter((x) => ((predicate == null) || predicate(x)) && x is SampledProfileTraceData);
            }

            var traceStackSource = new TraceEventStackSource(events);

            traceStackSource.ShowUnknownAddresses = true;

            // Clone the samples so that the caller doesn't have to go back to the ETL file from here on.
            return(CopyStackSource.Clone(traceStackSource));
        }
示例#3
0
        public async ValueTask <ICallTreeData> GetCallTreeAsync(StackViewerModel model, StackSource stackSource = null)
        {
            await this.EnsureInitialized();

            lock (this.callTreeDataCache)
            {
                if (!this.callTreeDataCache.TryGetValue(model, out var value))
                {
                    double start = string.IsNullOrEmpty(model.Start) ? 0.0 : double.Parse(model.Start);
                    double end   = string.IsNullOrEmpty(model.End) ? 0.0 : double.Parse(model.End);

                    var key = new StackSourceCacheKey((ProcessIndex)int.Parse(model.Pid), int.Parse(model.StackType), start, end, model.DrillIntoKey);
                    if (!this.stackSourceCache.TryGetValue(key, out var ss))
                    {
                        ss = stackSource ?? this.deserializer.GetStackSource((ProcessIndex)int.Parse(model.Pid), int.Parse(model.StackType), start, end);
                        this.stackSourceCache.Add(key, ss);
                    }
                    else
                    {
                        var drillIntoStackSource = new CopyStackSource(GetTraceEventStackSource(ss));

                        ss.ForEach(delegate(StackSourceSample sample)
                        {
                            drillIntoStackSource.AddSample(sample);
                        });

                        ss = drillIntoStackSource;
                    }

                    value = new CallTreeData(stackSource ?? ss, model);
                    this.callTreeDataCache.Add(model, value);
                }

                return(value);
            }
        }