Skip to content

Commit

Permalink
Merge pull request microsoft#1247 from mjsabby/fixdepsandbug
Browse files Browse the repository at this point in the history
Update package deps & fix a bug with CAP files
  • Loading branch information
brianrob authored Aug 18, 2020
2 parents d89dfe2 + c650346 commit 0b1df3a
Show file tree
Hide file tree
Showing 7 changed files with 3,909 additions and 2,342 deletions.
83 changes: 82 additions & 1 deletion src/PerfViewJS/DeserializedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PerfViewJS
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand All @@ -19,6 +20,8 @@ public sealed class DeserializedData : IDeserializedData

private readonly Dictionary<StackViewerModel, ICallTreeData> callTreeDataCache = new Dictionary<StackViewerModel, ICallTreeData>();

private readonly Dictionary<StackSourceCacheKey, StackSource> stackSourceCache = new Dictionary<StackSourceCacheKey, StackSource>();

private int initialized;

private TraceLogDeserializer deserializer;
Expand Down Expand Up @@ -61,7 +64,25 @@ public async ValueTask<ICallTreeData> GetCallTreeAsync(StackViewerModel model, S
double start = string.IsNullOrEmpty(model.Start) ? 0.0 : double.Parse(model.Start);
double end = string.IsNullOrEmpty(model.End) ? 0.0 : double.Parse(model.End);

value = new CallTreeData(stackSource ?? this.deserializer.GetStackSource((ProcessIndex)int.Parse(model.Pid), int.Parse(model.StackType), start, end), model);
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);
}

Expand Down Expand Up @@ -125,6 +146,32 @@ public async ValueTask<string> LookupSymbolsAsync(int[] moduleIndices)
return retVal;
}

private static TraceEventStackSource GetTraceEventStackSource(StackSource source)
{
StackSourceStacks rawSource = source;
while (true)
{
if (rawSource is TraceEventStackSource asTraceEventStackSource)
{
return asTraceEventStackSource;
}

if (rawSource is CopyStackSource asCopyStackSource)
{
rawSource = asCopyStackSource.SourceStacks;
continue;
}

if (rawSource is StackSource asStackSource && asStackSource != asStackSource.BaseStackSource)
{
rawSource = asStackSource.BaseStackSource;
continue;
}

return null;
}
}

private async Task EnsureInitialized()
{
if (Interlocked.CompareExchange(ref this.initialized, 1, comparand: -1) == 0)
Expand Down Expand Up @@ -215,5 +262,39 @@ private async Task Initialize()
this.semaphoreSlim.Release();
}
}

private readonly struct StackSourceCacheKey : IEquatable<StackSourceCacheKey>
{
private const double TOLERANCE = 0.1;

private readonly ProcessIndex processIndex;

private readonly int stackType;

private readonly double start;

private readonly double end;

private readonly string drillIntoKey;

public StackSourceCacheKey(ProcessIndex processIndex, int stackType, double start, double end, string drillIntoKey)
{
this.processIndex = processIndex;
this.stackType = stackType;
this.start = start;
this.end = end;
this.drillIntoKey = drillIntoKey;
}

public bool Equals(StackSourceCacheKey other)
{
return this.processIndex == other.processIndex && this.stackType == other.stackType && this.drillIntoKey == other.drillIntoKey && Math.Abs(this.start - other.start) < TOLERANCE && Math.Abs(this.end - other.end) < TOLERANCE;
}

public override int GetHashCode()
{
return HashCode.Combine(this.processIndex, this.stackType, this.start, this.end, this.drillIntoKey);
}
}
}
}
2 changes: 1 addition & 1 deletion src/PerfViewJS/PerfViewJS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.205" />
<ProjectReference Include="..\TraceEvent\TraceEvent.csproj" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 0b1df3a

Please sign in to comment.