private NodeTypeIndex GetNodeTypeIndex(ProfilerTypeID typeId) { var typeIdasInt = (int)typeId; NodeTypeIndex ret = NodeTypeIndex.Invalid; if (typeIdasInt >= m_profilerTypeToNodeType.Count) { int prevSize = m_profilerTypeToNodeType.Count; int newSize = typeIdasInt + 100; m_profilerTypeToNodeType.Count = newSize; for (int i = prevSize; i < newSize; i++) { m_profilerTypeToNodeType[i] = NodeTypeIndex.Invalid; } } else { ret = m_profilerTypeToNodeType[typeIdasInt]; } if (ret == NodeTypeIndex.Invalid) { ProfilerType profilerType = m_clrProfilerParser.GetTypeById(typeId); ret = CreateType(profilerType.name); m_profilerTypeToNodeType[typeIdasInt] = ret; // TODO FIX NOW don't allocate every time GetType(ret, AllocTypeNodeStorage()).ModuleName = profilerType.ModuleName; } return(ret); }
public ProfilerOptions(ProfilerType profilerType, int maxHistoryItems = 100, int maxHistoryAgeMs = 2000, string stringFormat = null) { MaxHistoryItems = maxHistoryItems; MaxHistoryAgeMs = maxHistoryAgeMs; //MaxHistoryAgeTicks = maxHistoryAgeMs * 10_000; ProfilerType = profilerType; StringFormat = stringFormat; if (stringFormat == null) { if (profilerType == ProfilerType.Counter) { StringFormat = "{0:0}"; } else { StringFormat = "{0:0,0.00}"; } } IsAverage = (profilerType == ProfilerType.SampleAverageTimeMs || profilerType == ProfilerType.SampleAveragePerSecond); AutoClean = true; }
protected static void WriteStructuredLog(ProfilerType type, string label, long elapsed) { foreach (var sink in StructuredSinks) { sink?.Invoke(type, label, elapsed); } }
public Profiler(string w) { profilerType = StartupImpact.settings.profilerType; what = w; }
public ClrProfilerMemoryGraph(string profilerFile) : base(10000) { // Needed for the callback in ReadFile m_tempChildren = new GrowableArray <NodeIndex>(1000); ClearWorker(); m_clrProfilerParser = new ClrProfilerParser(); m_clrProfilerParser.ObjectDescription += OnObjectDescription; m_clrProfilerParser.GCRoot += OnGCRoot; m_clrProfilerParser.HeapDump += OnHeapDump; m_clrProfilerParser.StaticVar += OnStaticVar; m_clrProfilerParser.LocalVar += OnLocalVar; m_clrProfilerParser.ReadFile(profilerFile); // set the module names on every type if present. var nodeTypeStorage = AllocTypeNodeStorage(); for (var profilerTypeId = 0; profilerTypeId < (int)m_clrProfilerParser.TypeIdLimit; profilerTypeId++) { var profilerType = m_clrProfilerParser.GetTypeById((ProfilerTypeID)profilerTypeId); if (profilerType == null) { continue; } var module = profilerType.Module; if (module != null && profilerTypeId < m_profilerTypeToNodeType.Count) { var nodeTypeId = m_profilerTypeToNodeType[profilerTypeId]; if (nodeTypeId != NodeTypeIndex.Invalid) { var nodeType = GetType((NodeTypeIndex)nodeTypeId, nodeTypeStorage); nodeType.ModuleName = profilerType.Module.name; } } } // Now we have module information, process the defer local and static processing foreach (var deferedRoot in m_deferedRoots) { ProfilerType profilerType = m_clrProfilerParser.GetTypeById(deferedRoot.typeID); var appDomainNode = m_rootNode.FindOrCreateChild("[appdomain " + deferedRoot.appDomainName + "]"); var varKindNode = appDomainNode.FindOrCreateChild("[" + deferedRoot.prefix + " vars]"); var moduleName = System.IO.Path.GetFileNameWithoutExtension(profilerType.ModuleName); var moduleNode = varKindNode.FindOrCreateChild("[" + deferedRoot.prefix + " vars " + moduleName + "]"); var typeNode = moduleNode.FindOrCreateChild("[" + deferedRoot.prefix + " vars " + profilerType.name + "]"); var node = typeNode.FindOrCreateChild( profilerType.name + "+" + deferedRoot.name + " [" + deferedRoot.prefix + " var]", profilerType.ModuleName); node.AddChild(deferedRoot.nodeIndex); } // finish off the root nodes. RootIndex = m_rootNode.Build(); AllowReading(); // These are only needed for the callbacks in 'ReadFile' save space by clearing them out. m_clrProfilerParser = null; m_tempChildren = new GrowableArray <NodeIndex>(); // Clear the array m_profilerTypeToNodeType = new GrowableArray <NodeTypeIndex>(); // Clear the array m_rootNode = null; m_rootNodeForUnknownRoot = null; m_addressToNodeIndex = null; m_deferedRoots = null; }
internal static ProfilerType GetProfilerType() { if (_LastCheck > DateTime.UtcNow.AddMinutes(-1)) { return(_LastProfilerType); } _LastCheck = DateTime.UtcNow; bool foundProcess = false; string instanceID = Left(Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID"), 6); string siteName = (Environment.GetEnvironmentVariable("WEBSITE_IIS_SITE_NAME") ?? "").TrimStart('~', '1'); //is azure app service? if (!string.IsNullOrEmpty(instanceID) && !string.IsNullOrEmpty(siteName)) { _LastProfilerType = ProfilerType.APM; return(_LastProfilerType); } if (!_ScanProcessException) { try { foreach (var process in Process.GetProcesses().ToList()) { if (process.Id <= 0) { continue; } try { switch (process?.ProcessName?.ToLower().Replace(".vshost", "")) { case "devdashservice": case "stackifytracerservice": case "stackifytracernotifier": case "devdashtestconsole": _LastProfilerType = ProfilerType.Prefix; foundProcess = true; break; case "stackifymonitoringservice": case "monitortestconsole": if (_LastProfilerType != ProfilerType.Prefix) { _LastProfilerType = ProfilerType.APM; } foundProcess = true; break; } } catch { _ScanProcessException = true; } } } catch { _ScanProcessException = true; } } //fall back to see if this has been set if (!foundProcess && _ScanProcessException) { var stackifyPath = Environment.GetEnvironmentVariable("StackifyPath"); if (!string.IsNullOrEmpty(stackifyPath) && (stackifyPath.IndexOf("prefix", StringComparison.CurrentCultureIgnoreCase) > -1 || stackifyPath.IndexOf("devdash", StringComparison.CurrentCultureIgnoreCase) > -1)) { _LastProfilerType = ProfilerType.Prefix; } else if (!string.IsNullOrEmpty(stackifyPath)) { _LastProfilerType = ProfilerType.APM; } } return(_LastProfilerType); }
protected static void WriteLog(ProfilerType type, string label, long elapsed) { WriteLog($"{type.ToString().ToUpper()} {GetLabel(label)}: {elapsed}ms"); WriteStructuredLog(type, GetLabel(label), elapsed); }