static void PrintClassAllocationData(TextWriter writer, ProfilerEventHandler data, LoadedClass c, ulong totalAllocatedBytes) { double allocatedBytesPerClass = (double)c.AllocatedBytes; writer.WriteLine("{0,5:F2}% ({1} bytes) {2}", ((allocatedBytesPerClass / totalAllocatedBytes) * 100), c.AllocatedBytes, c.Name); if (data.Directives.AllocationsHaveStackTrace) { LoadedClass.AllocationsPerMethod[] allocationsPerMethodArray = c.Methods; double cumulativeAllocatedBytesPerMethod = 0; if (c.MethodsAtJitTimeCount > 0) { LoadedClass.AllocationsPerMethod[] allocationsPerMethodAtJitTime = c.MethodsAtJitTime; LoadedClass.AllocationsPerMethod[] totalAllocationsPerMethod = new LoadedClass.AllocationsPerMethod [allocationsPerMethodArray.Length + allocationsPerMethodAtJitTime.Length]; Array.Copy(allocationsPerMethodArray, totalAllocationsPerMethod, allocationsPerMethodArray.Length); Array.Copy(allocationsPerMethodAtJitTime, 0, totalAllocationsPerMethod, allocationsPerMethodArray.Length, allocationsPerMethodAtJitTime.Length); allocationsPerMethodArray = totalAllocationsPerMethod; } if (allocationsPerMethodArray.Length != 0) { Array.Sort(allocationsPerMethodArray, LoadedClass.AllocationsPerMethod.CompareByAllocatedBytes); Array.Reverse(allocationsPerMethodArray); foreach (LoadedClass.AllocationsPerMethod allocationsPerMethod in allocationsPerMethodArray) { PrintMethodAllocationsPerClass(writer, allocationsPerMethod, false, cumulativeAllocatedBytesPerMethod < allocatedBytesPerClass * 0.7, 0.7); cumulativeAllocatedBytesPerMethod += (double)allocationsPerMethod.AllocatedBytes; } } } else { LoadedClass.AllocationsPerMethod[] allocationsPerMethodArray = c.Methods; if (allocationsPerMethodArray.Length != 0) { Array.Sort(allocationsPerMethodArray, LoadedClass.AllocationsPerMethod.CompareByAllocatedBytes); Array.Reverse(allocationsPerMethodArray); foreach (LoadedClass.AllocationsPerMethod allocationsPerMethod in allocationsPerMethodArray) { PrintMethodAllocationsPerClass(writer, allocationsPerMethod, false, false, 0); } } if (c.MethodsAtJitTimeCount > 0) { allocationsPerMethodArray = c.MethodsAtJitTime; Array.Sort(allocationsPerMethodArray, LoadedClass.AllocationsPerMethod.CompareByAllocatedBytes); Array.Reverse(allocationsPerMethodArray); foreach (LoadedClass.AllocationsPerMethod allocationsPerMethod in allocationsPerMethodArray) { PrintMethodAllocationsPerClass(writer, allocationsPerMethod, true, false, 0); } } } }
static void PrintClassAllocationData (TextWriter writer, ProfilerEventHandler data, LoadedClass c, ulong totalAllocatedBytes) { double allocatedBytesPerClass = (double)c.AllocatedBytes; writer.WriteLine ("{0,5:F2}% ({1} bytes) {2}", ((allocatedBytesPerClass / totalAllocatedBytes) * 100), c.AllocatedBytes, c.Name); if (data.Directives.AllocationsHaveStackTrace) { LoadedClass.AllocationsPerMethod[] allocationsPerMethodArray = c.Methods; double cumulativeAllocatedBytesPerMethod = 0; if (c.MethodsAtJitTimeCount > 0) { LoadedClass.AllocationsPerMethod[] allocationsPerMethodAtJitTime = c.MethodsAtJitTime; LoadedClass.AllocationsPerMethod[] totalAllocationsPerMethod = new LoadedClass.AllocationsPerMethod [allocationsPerMethodArray.Length + allocationsPerMethodAtJitTime.Length]; Array.Copy (allocationsPerMethodArray, totalAllocationsPerMethod, allocationsPerMethodArray.Length); Array.Copy (allocationsPerMethodAtJitTime, 0, totalAllocationsPerMethod, allocationsPerMethodArray.Length, allocationsPerMethodAtJitTime.Length); allocationsPerMethodArray = totalAllocationsPerMethod; } if (allocationsPerMethodArray.Length != 0) { Array.Sort (allocationsPerMethodArray, LoadedClass.AllocationsPerMethod.CompareByAllocatedBytes); Array.Reverse (allocationsPerMethodArray); foreach (LoadedClass.AllocationsPerMethod allocationsPerMethod in allocationsPerMethodArray) { PrintMethodAllocationsPerClass (writer, allocationsPerMethod, false, cumulativeAllocatedBytesPerMethod < allocatedBytesPerClass * 0.7, 0.7); cumulativeAllocatedBytesPerMethod += (double)allocationsPerMethod.AllocatedBytes; } } } else { LoadedClass.AllocationsPerMethod[] allocationsPerMethodArray = c.Methods; if (allocationsPerMethodArray.Length != 0) { Array.Sort (allocationsPerMethodArray, LoadedClass.AllocationsPerMethod.CompareByAllocatedBytes); Array.Reverse (allocationsPerMethodArray); foreach (LoadedClass.AllocationsPerMethod allocationsPerMethod in allocationsPerMethodArray) { PrintMethodAllocationsPerClass (writer, allocationsPerMethod, false, false, 0); } } if (c.MethodsAtJitTimeCount > 0) { allocationsPerMethodArray = c.MethodsAtJitTime; Array.Sort (allocationsPerMethodArray, LoadedClass.AllocationsPerMethod.CompareByAllocatedBytes); Array.Reverse (allocationsPerMethodArray); foreach (LoadedClass.AllocationsPerMethod allocationsPerMethod in allocationsPerMethodArray) { PrintMethodAllocationsPerClass (writer, allocationsPerMethod, true, false, 0); } } } }
static void PrintMethodAllocationsPerClass(TextWriter writer, LoadedClass.AllocationsPerMethod allocationsPerMethod, bool JitTime, bool printStackTraces, double stackTraceTreshold) { if (!JitTime) { writer.WriteLine(" {0} bytes ({1} instances) from {2}.{3}", allocationsPerMethod.AllocatedBytes, allocationsPerMethod.AllocatedInstances, allocationsPerMethod.Method.Class.Name, allocationsPerMethod.Method.Name); } else { writer.WriteLine(" {0} bytes ({1} instances) at JIT time in {2}.{3}", allocationsPerMethod.AllocatedBytes, allocationsPerMethod.AllocatedInstances, allocationsPerMethod.Method.Class.Name, allocationsPerMethod.Method.Name); } if (printStackTraces) { LoadedClass.AllocationsPerStackTrace [] stackTraces = allocationsPerMethod.StackTraces; Array.Sort(stackTraces, LoadedClass.AllocationsPerStackTrace.CompareByAllocatedBytes); Array.Reverse(stackTraces); double cumulativeAllocatedBytesPerStackTrace = 0; foreach (LoadedClass.AllocationsPerStackTrace trace in stackTraces) { if (cumulativeAllocatedBytesPerStackTrace / allocationsPerMethod.AllocatedBytes < stackTraceTreshold) { writer.WriteLine(" {0} bytes ({1} instances) inside", trace.AllocatedBytes, trace.AllocatedInstances); for (StackTrace frame = trace.Trace; frame != null; frame = frame.Caller) { writer.Write(" "); if (frame.MethodIsBeingJitted) { writer.Write("[JIT time]:"); } writer.WriteLine("{0}.{1}", frame.TopMethod.Class.Name, frame.TopMethod.Name); } } else { break; } cumulativeAllocatedBytesPerStackTrace += (double)trace.AllocatedBytes; } } }
public MethodNode (ProfileStore store, Node parent, LoadedClass.AllocationsPerMethod instance) : base (store, parent) { this.instance = instance; }
public MethodNode(ProfileStore store, Node parent, LoadedClass.AllocationsPerMethod instance) : base(store, parent) { this.instance = instance; }