Skip to content

Commit

Permalink
Add utility process sub-type support, C#
Browse files Browse the repository at this point in the history
IdentifyChromeProcesses exists both as a Python script and as a
TraceProcessor written in C#. Eventually I should probably migrate to
just using the C# version, but for now I'm maintaining them both. See
the previous change for a full description of utility-process sub-types.
  • Loading branch information
randomascii committed May 14, 2020
1 parent d5499bf commit 40d1d8f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions TraceProcessors/IdentifyChromeProcesses/IdentifyChromeProcesses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ static void ProcessTrace(ITraceProcessor trace, bool showCPUUsage)

// Dictionary of Pids and their types.
var typesByPid = new Dictionary<int, string>();
// Dictionary of Pids and their sub-types.
var subTypesByPid = new Dictionary<int, string>();

// Find the space-terminated word after 'type='.
// Mark the first .* as lazy/ungreedy/reluctant so that if there are multiple
// --type options (such as with the V8 Proxy Resolver utility process) the
// first one will win. Or, at least, that's what the comments in the Python
// version of this said.
var r = new Regex(@".*? --type=(?<type>[^ ]*) .*");
// Find the utility sub-type, if present.
var r_sub = new Regex(@".*? --utility-sub-type=(?<subtype>[^ ]*) .*");
foreach (var entry in processSummaries)
{
var process = entry.Key;
Expand Down Expand Up @@ -157,6 +161,10 @@ static void ProcessTrace(ITraceProcessor trace, bool showCPUUsage)

typesByPid[pid] = type;

var match_sub = r_sub.Match(process.CommandLine);
if (match_sub.Success)
subTypesByPid[pid] = match_sub.Groups["subtype"].ToString();

// Retrieve or create the list of processes associated with this
// browser (parent) pid.
// This involves a lot of redundant dictionary lookups, but it is
Expand Down Expand Up @@ -336,17 +344,20 @@ static void ProcessTrace(ITraceProcessor trace, bool showCPUUsage)
type.Value.Sort();
foreach (var pid in type.Value)
{
string subTypeText = "";
if (subTypesByPid.ContainsKey(pid))
subTypeText = " (" + subTypesByPid[pid] + ")";
if (showCPUUsage)
{
Console.Write("\n ");
execTimes.TryGetValue(pid, out CPUUsageDetails details);
if (details.contextSwitches > 0)
Console.Write("{0,5} - {1,6} context switches, {2,8:0.00} ms CPU", pid, details.contextSwitches, details.ns / 1e6);
Console.Write("{0,5} - {1,6} context switches, {2,8:0.00} ms CPU{3}", pid, details.contextSwitches, details.ns / 1e6, subTypeText);
else
Console.Write("{0,5}", pid);
Console.Write("{0,5}{1}", pid, subTypeText);
}
else
Console.Write("{0} ", pid);
Console.Write("{0}{1} ", pid, subTypeText);
}
Console.WriteLine();
}
Expand Down

0 comments on commit 40d1d8f

Please sign in to comment.