Skip to content

Commit

Permalink
Merge "Dmabuf plugin skeleton" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Sep 30, 2024
2 parents 4e1ce2f + 5d0513d commit 27eed34
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions ui/src/plugins/dev.perfetto.AndroidDmabuf/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[email protected]
66 changes: 66 additions & 0 deletions ui/src/plugins/dev.perfetto.AndroidDmabuf/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (C) 2024 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import {Trace} from '../../public/trace';
import {PerfettoPlugin, PluginDescriptor} from '../../public/plugin';
import {
SimpleCounterTrack,
SimpleCounterTrackConfig,
} from '../../frontend/simple_counter_track';
import {TrackNode} from '../../public/workspace';
import {globals} from '../../frontend/globals';
import {getOrCreateGroupForProcess} from '../../public/standard_groups';
import {NUM} from '../../trace_processor/query_result';

class AndroidDmabuf implements PerfettoPlugin {
async onTraceLoad(ctx: Trace): Promise<void> {
const e = ctx.engine;
await e.query(`INCLUDE PERFETTO MODULE android.memory.dmabuf`);
await e.query(`
CREATE PERFETTO TABLE _android_memory_cumulative_dmabuf AS
SELECT upid, ts, SUM(buf_size) OVER(PARTITION BY upid ORDER BY ts) AS value
FROM android_dmabuf_allocs`);

const pids = await e.query(
`SELECT DISTINCT upid FROM _android_memory_cumulative_dmabuf`,
);
const it = pids.iter({upid: NUM});
for (; it.valid(); it.next()) {
const upid = it.upid;
const uri = `/android_process_dmabuf_${upid}`;
const config: SimpleCounterTrackConfig = {
data: {
sqlSource: `SELECT ts, value FROM _android_memory_cumulative_dmabuf WHERE upid = ${upid}`,
columns: ['ts', 'value'],
},
columns: {ts: 'ts', value: 'value'},
};

ctx.tracks.registerTrack({
uri,
title: `dmabuf allocs`,
track: new SimpleCounterTrack(ctx, {trackUri: uri}, config),
});
const track = new TrackNode({uri, title: 'mem.dmabuf.alloc'});
getOrCreateGroupForProcess(globals.workspace, upid).addChildInOrder(
track,
);
}
}
}

export const plugin: PluginDescriptor = {
pluginId: 'dev.perfetto.AndroidDmabuf',
plugin: AndroidDmabuf,
};

0 comments on commit 27eed34

Please sign in to comment.