• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2024 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import {
16  NUM,
17  Plugin,
18  PluginContextTrace,
19  PluginDescriptor,
20  STR_NULL,
21} from '../../public';
22import {AsyncSliceTrack} from '../../core_plugins/async_slices/async_slice_track';
23import {ASYNC_SLICE_TRACK_KIND} from '../../public';
24
25// This plugin renders visualizations of runtime power state transitions for
26// Linux kernel devices (devices managed by Linux drivers).
27class LinuxKernelDevices implements Plugin {
28  async onTraceLoad(ctx: PluginContextTrace): Promise<void> {
29    const result = await ctx.engine.query(`
30      select
31        t.id as trackId,
32        t.name
33      from linux_device_track t
34      join _slice_track_summary using (id)
35      order by t.name;
36    `);
37
38    const it = result.iter({
39      name: STR_NULL,
40      trackId: NUM,
41    });
42
43    for (; it.valid(); it.next()) {
44      const trackId = it.trackId;
45      const displayName = it.name ?? `${trackId}`;
46
47      ctx.registerStaticTrack({
48        uri: `org.kernel.LinuxKernelDevices#${displayName}`,
49        displayName,
50        trackIds: [trackId],
51        kind: ASYNC_SLICE_TRACK_KIND,
52        trackFactory: ({trackKey}) => {
53          return new AsyncSliceTrack(
54            {
55              engine: ctx.engine,
56              trackKey,
57            },
58            0,
59            [trackId],
60          );
61        },
62        groupName: `Linux Kernel Devices`,
63      });
64    }
65  }
66}
67
68export const plugin: PluginDescriptor = {
69  pluginId: 'org.kernel.LinuxKernelDevices',
70  plugin: LinuxKernelDevices,
71};
72