Skip to content

Commit

Permalink
Add per-profile tab and frame counts to chrome://process-internals.
Browse files Browse the repository at this point in the history
Also removes AgentSchedulingGroupHost ID for now, since we don't
currently have more than one per process.  It can be shown again in
the future if we start creating more than one.

Bug: 850087
Change-Id: Icdc7ef263f3c076539d47dcdb4fd36ecd7525e9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4293054
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Commit-Queue: Charlie Reis <creis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1111683}
  • Loading branch information
creis authored and Chromium LUCI CQ committed Mar 1, 2023
1 parent 41b8366 commit 9cf7226
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 9 deletions.
38 changes: 34 additions & 4 deletions content/browser/resources/process/process_internals.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,40 @@
<div id="wc-list" class="list pages"></div>
<div id="tree-view-container">
<button id="refresh-frame-trees">Refresh</button>
<div>Legend:</div>
<div>Frame[<i>process_id</i>:<i>routing_id</i>:<i>agent_scheduling_group_id</i>]:
SI:<i>site_instance_id</i>, <i>whether process is locked to a
site</i>, site: <i>site_url</i> | url:
<div class="description">This page only contains information about the
current profile.</div>
<table>
<tbody>
<tr>
<td>Tab Count:</td>
<td id="tab-count"></td>
<td class="description">The number of WebContents objects in this
profile.</td>
</tr>
<tr>
<td>Frame Count:</td>
<td id="frame-count"></td>
<td class="description">The number of RenderFrameHosts in this
profile. Note that this does not include RenderFrameHosts that
are speculative or pending deletion.</td>
</tr>
<tr>
<td>OOPIF Count:</td>
<td id="oopif-count"></td>
<td class="description">The number of out-of-process iframes in
this profile (as a subset of the Frame Count).</td>
</tr>
<tr>
<td>Process Count:</td>
<td id="profile-process-count"></td>
<td class="description">The number of renderer processes in this
profile.</td>
</tr>
</tbody>
</table>
<div>Legend: Frame[<i>process_id</i>:<i>routing_id</i>]:
SI:<i>site_instance_id</i>, <i>is process locked to a
site?</i>, site: <i>site_url</i> | url:
<i>last_committed_url</i>
</div>
<cr-tree id="tree-view"></cr-tree>
Expand Down
51 changes: 46 additions & 5 deletions content/browser/resources/process/process_internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ async function loadProcessCountInfo() {
*/
let treeViewRoot: CrTreeElement|null = null;

/**
* Accumulators for tracking frame and process counts. Reset in
* loadWebContentsInfo.
*/
let totalFrameCount: number = 0;
let totalCrossProcessFrameCount: number = 0;
let processIdSet: Set<number> = new Set();

/**
* Initialize and return |treeViewRoot|.
*/
Expand All @@ -117,13 +125,22 @@ function getTreeViewRoot(): CrTreeElement {

/**
* Initialize and return a tree item representing a FrameInfo object and
* recursively creates its subframe objects.
* recursively creates its subframe objects. For subframes, pass the parent
* frame's process ID in `parentProcessId`.
*/
function frameToTreeItem(frame: FrameInfo):
function frameToTreeItem(frame: FrameInfo, parentProcessId: number = -1):
{item: CrTreeItemElement, count: number} {
// Count out-of-process iframes.
const isCrossProcessFrame: boolean =
parentProcessId !== -1 && parentProcessId !== frame.processId;
if (isCrossProcessFrame) {
totalCrossProcessFrameCount++;
}
processIdSet.add(frame.processId);

// Compose the string which will appear in the entry for this frame.
let itemLabel = `Frame[${frame.processId}:${frame.routingId}:${
frame.agentSchedulingGroupId}]:`;
const prefix = isCrossProcessFrame ? 'OOPIF' : 'Frame';
let itemLabel = `${prefix}[${frame.processId}:${frame.routingId}]:`;
if (frame.type === FrameInfo_Type.kBackForwardCache) {
itemLabel += ` bfcached`;
} else if (frame.type === FrameInfo_Type.kPrerender) {
Expand All @@ -133,6 +150,8 @@ function frameToTreeItem(frame: FrameInfo):
itemLabel += ` SI:${frame.siteInstance.id}`;
if (frame.siteInstance.locked) {
itemLabel += ', locked';
} else {
itemLabel += ', unlocked';
}
if (frame.siteInstance.siteUrl) {
itemLabel += `, site:${frame.siteInstance.siteUrl.url}`;
Expand Down Expand Up @@ -164,7 +183,7 @@ function frameToTreeItem(frame: FrameInfo):

let frameCount = 1;
for (const subframe of frame.subframes) {
const result = frameToTreeItem(subframe);
const result = frameToTreeItem(subframe, frame.processId);
const subItem = result.item;
const count = result.count;

Expand Down Expand Up @@ -230,6 +249,8 @@ function webContentsToTreeItem(webContents: WebContentsInfo):
}
item.label = itemLabel;

totalFrameCount += activeCount + cachedCount + prerenderCount;

return item;
}

Expand All @@ -254,9 +275,29 @@ function populateWebContentsTab(infos: WebContentsInfo[]) {
* current browser profile. The result is passed to populateWebContentsTab.
*/
async function loadWebContentsInfo() {
// Reset frame counts.
totalFrameCount = 0;
totalCrossProcessFrameCount = 0;
processIdSet = new Set();

assert(pageHandler);
const {infos} = await pageHandler.getAllWebContentsInfo();
populateWebContentsTab(infos);

// Post tab, frame, and process counts.
const tabCount = document.querySelector<HTMLElement>('#tab-count');
assert(tabCount);
tabCount.innerText = String(infos.length);
const frameCount = document.querySelector<HTMLElement>('#frame-count');
assert(frameCount);
frameCount.innerText = String(totalFrameCount);
const oopifCount = document.querySelector<HTMLElement>('#oopif-count');
assert(oopifCount);
oopifCount.innerText = String(totalCrossProcessFrameCount);
const processCount =
document.querySelector<HTMLElement>('#profile-process-count');
assert(processCount);
processCount.innerText = String(processIdSet.size);
}

/**
Expand Down

0 comments on commit 9cf7226

Please sign in to comment.