• 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 {LONG, NUM} from '../../trace_processor/query_result';
16import {CpuProfileSampleFlamegraphDetailsPanel} from './cpu_profile_details_panel';
17import {Trace} from '../../public/trace';
18import {DatasetSliceTrack} from '../../components/tracks/dataset_slice_track';
19import {SourceDataset} from '../../trace_processor/dataset';
20import {Time} from '../../base/time';
21import {getColorForSample} from '../../components/colorizer';
22
23export function createCpuProfileTrack(trace: Trace, uri: string, utid: number) {
24  return new DatasetSliceTrack({
25    trace,
26    uri,
27    dataset: new SourceDataset({
28      schema: {
29        id: NUM,
30        ts: LONG,
31        callsite_id: NUM,
32      },
33      src: `cpu_profile_stack_sample`,
34      filter: {
35        col: 'utid',
36        eq: utid,
37      },
38    }),
39    sliceName: () => 'CPU Sample',
40    colorizer: (row) => getColorForSample(row.callsite_id),
41    detailsPanel: (row) => {
42      return new CpuProfileSampleFlamegraphDetailsPanel(
43        trace,
44        Time.fromRaw(row.ts),
45        utid,
46      );
47    },
48  });
49}
50