mirror of
https://github.com/Kae7in/perfview
synced 2026-08-09 12:09:44 +00:00
Speed up CTF process name parsing
Cache result of process name parsing to not constantly rebuild the string.
This commit is contained in:
@@ -37,6 +37,7 @@ namespace Microsoft.Diagnostics.Tracing.Ctf
|
||||
private CtfMetadata _metadata;
|
||||
private CtfStream _streamDefinition;
|
||||
CtfEventHeader _header = new CtfEventHeader();
|
||||
public Dictionary<int, string> _processes = new Dictionary<int, string>();
|
||||
|
||||
private bool _eof;
|
||||
private GCHandle _handle;
|
||||
@@ -149,6 +150,8 @@ namespace Microsoft.Diagnostics.Tracing.Ctf
|
||||
_header.Pid = eventContext.GetFieldValue<int>(result, "_vpid");
|
||||
_header.Tid = eventContext.GetFieldValue<int>(result, "_vtid");
|
||||
|
||||
if (IsProcessStartEvent(evt) || !_processes.TryGetValue(_header.Pid, out _header.ProcessName))
|
||||
{
|
||||
int procnameIndex = eventContext.GetFieldIndex("_procname");
|
||||
object[] procname = (object[])(result[procnameIndex]);
|
||||
processName.Clear();
|
||||
@@ -161,7 +164,10 @@ namespace Microsoft.Diagnostics.Tracing.Ctf
|
||||
processName.Append((char)b);
|
||||
}
|
||||
|
||||
_header.ProcessName = processName.ToString();
|
||||
string name = processName.ToString();
|
||||
_header.ProcessName = name;
|
||||
_processes[_header.Pid] = name;
|
||||
}
|
||||
}
|
||||
|
||||
_readHeader = true;
|
||||
@@ -169,6 +175,11 @@ namespace Microsoft.Diagnostics.Tracing.Ctf
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsProcessStartEvent(CtfEvent evt)
|
||||
{
|
||||
return evt.Name == "sched_process_exec";
|
||||
}
|
||||
|
||||
public void ResetBuffer()
|
||||
{
|
||||
_bitOffset = 0;
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace Microsoft.Diagnostics.Tracing
|
||||
private List<Tuple<ZipArchiveEntry, CtfMetadata>> _channels;
|
||||
private TraceEventNativeMethods.EVENT_RECORD* _header;
|
||||
private Dictionary<string, ETWMapping> _eventMapping;
|
||||
private Dictionary<int, string> _processes = new Dictionary<int, string>();
|
||||
|
||||
#if DEBUG
|
||||
private StreamWriter _debugOut;
|
||||
@@ -482,6 +483,7 @@ namespace Microsoft.Diagnostics.Tracing
|
||||
CtfEventHeader header = entry.Current;
|
||||
CtfEvent evt = header.Event;
|
||||
lastTimestamp = header.Timestamp;
|
||||
_processes[header.Pid] = header.ProcessName;
|
||||
|
||||
#if DEBUG
|
||||
if (_debugOut != null)
|
||||
@@ -549,6 +551,15 @@ namespace Microsoft.Diagnostics.Tracing
|
||||
return _header;
|
||||
}
|
||||
|
||||
internal override string ProcessName(int processID, long timeQPC)
|
||||
{
|
||||
string name;
|
||||
if (!_processes.TryGetValue(processID, out name))
|
||||
name = $"Process({processID.ToString("x")})";
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
private ETWMapping GetTraceEvent(CtfEvent evt)
|
||||
{
|
||||
ETWMapping result;
|
||||
|
||||
@@ -72,6 +72,9 @@ namespace Microsoft.Diagnostics.Tracing.Parsers
|
||||
private Action<SchedulerProcessTraceData> _action;
|
||||
private static string[] _payloadNames;
|
||||
|
||||
|
||||
public int Tid { get { throw new NotImplementedException(); } }
|
||||
|
||||
public SchedulerProcessTraceData(Action<SchedulerProcessTraceData> action, int eventID, int task, string taskName, Guid taskGuid, int opcode, string opcodeName, Guid providerGuid, string providerName)
|
||||
: base(eventID, task, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName)
|
||||
{
|
||||
@@ -124,7 +127,7 @@ namespace Microsoft.Diagnostics.Tracing.Parsers
|
||||
{
|
||||
Prefix(sb);
|
||||
XmlAttrib(sb, "ProcessID", ProcessID);
|
||||
XmlAttrib(sb, "ImageFileName", ImageFileName);
|
||||
XmlAttrib(sb, "ProcessName", ProcessName);
|
||||
sb.Append("/>");
|
||||
return sb;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user