public static ProfilingBlockBase Start(string className, string memberName = null, string blockName = null) { if (!ShipyardCore.Debug) { return(EmptyBlock); } string[] splits = className.Split('.'); var profileblock = new ProfilingBlock(splits[1], splits[2], memberName, blockName); profileblock.Stopwatch.Start(); return(profileblock); }
private static void End(ProfilingBlock profilingBlock) { profilingBlock.Stopwatch.Stop(); Utilities.QueueAction(() => { try { double runtime = 1000d * profilingBlock.Stopwatch.ElapsedTicks / Stopwatch.Frequency; Namespace thisNamespace = Namespaces.FirstOrDefault(n => n.Name == profilingBlock.Namespace); if (thisNamespace == null) { thisNamespace = new Namespace(profilingBlock.Namespace); Namespaces.Add(thisNamespace); } Class thisClass = thisNamespace.Classes.FirstOrDefault(c => c.Name == profilingBlock.Class); if (thisClass == null) { thisClass = new Class(profilingBlock.Class); thisNamespace.Classes.Add(thisClass); } if (profilingBlock.Member == null) { if (thisClass.Runtimes.Count >= int.MaxValue) { thisClass.Runtimes.RemoveAt(0); } thisClass.Runtimes.Add(runtime); thisClass.MaxRuntime = thisClass.Runtimes.Max(); thisClass.AvgRuntime = thisClass.Runtimes.Average(); return; } Member thisMember = thisClass.Members.FirstOrDefault(m => m.Name == profilingBlock.Member); if (thisMember == null) { thisMember = new Member(profilingBlock.Member); thisClass.Members.Add(thisMember); } if (profilingBlock.Block == null) { if (thisMember.Runtimes.Count >= int.MaxValue) { thisMember.Runtimes.RemoveAt(0); } thisMember.Runtimes.Add(runtime); thisMember.MaxRuntime = thisMember.Runtimes.Max(); thisMember.AvgRuntime = thisMember.Runtimes.Average(); return; } Block thisBlock = thisMember.Blocks.FirstOrDefault(b => b.Name == profilingBlock.Block); if (thisBlock == null) { thisBlock = new Block(profilingBlock.Block); thisMember.Blocks.Add(thisBlock); } if (thisBlock.Runtimes.Count >= int.MaxValue) { thisBlock.Runtimes.RemoveAt(0); } thisBlock.Runtimes.Add(runtime); thisBlock.MaxRuntime = thisBlock.Runtimes.Max(); thisBlock.AvgRuntime = thisBlock.Runtimes.Average(); } catch (Exception ex) { Logging.Instance.WriteLine(ex.ToString()); } }); }