blob: 0412e194c02f4b5806a189b7d984453265d5e7d5 [file] [log] [blame]
// 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 {Plugin, PluginContextTrace, PluginDescriptor} from '../../public';
import {addDebugCounterTrack} from '../../frontend/debug_tracks/debug_tracks';
class PixelMemory implements Plugin {
async onTraceLoad(ctx: PluginContextTrace): Promise<void> {
ctx.registerCommand({
id: 'dev.perfetto.PixelMemory#ShowTotalMemory',
name: 'Add tracks: show a process total memory',
callback: async (pid) => {
if (pid === undefined) {
pid = prompt('Enter a process pid', '');
if (pid === null) return;
}
const RSS_ALL = `
INCLUDE PERFETTO MODULE memory.linux.process;
INCLUDE PERFETTO MODULE memory.android.gpu;
DROP TABLE IF EXISTS process_mem_rss_anon_file_shmem_swap_gpu;
CREATE VIRTUAL TABLE process_mem_rss_anon_file_shmem_swap_gpu
USING
SPAN_OUTER_JOIN(
memory_gpu_per_process PARTITIONED upid, memory_rss_and_swap_per_process PARTITIONED upid);
`;
await ctx.engine.query(RSS_ALL);
await addDebugCounterTrack(
ctx,
{
sqlSource: `
SELECT
ts,
COALESCE(rss_and_swap, 0) + COALESCE(gpu_memory, 0) AS value
FROM process_mem_rss_anon_file_shmem_swap_gpu
WHERE pid = ${pid}
`,
columns: ['ts', 'value'],
},
pid + '_rss_anon_file_swap_shmem_gpu',
{ts: 'ts', value: 'value'},
);
},
});
}
}
export const plugin: PluginDescriptor = {
pluginId: 'com.google.PixelMemory',
plugin: PixelMemory,
};