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 m from 'mithril'; 16import {PerfettoPlugin} from '../../public/plugin'; 17import {Trace} from '../../public/trace'; 18import {ExplorePage, ExploreTableState} from './explore_page'; 19import {Chart} from '../../components/widgets/charts/chart'; 20import SqlModulesPlugin from '../dev.perfetto.SqlModules'; 21 22export default class implements PerfettoPlugin { 23 static readonly id = 'dev.perfetto.ExplorePage'; 24 static readonly dependencies = [SqlModulesPlugin]; 25 26 // The following allows us to have persistent 27 // state/charts for the lifecycle of a single 28 // trace. 29 private readonly state: ExploreTableState = {}; 30 private readonly charts: Chart[] = []; 31 32 async onTraceLoad(trace: Trace): Promise<void> { 33 trace.pages.registerPage({ 34 route: '/explore', 35 page: { 36 view: ({attrs}) => 37 m(ExplorePage, { 38 ...attrs, 39 state: this.state, 40 charts: this.charts, 41 }), 42 }, 43 }); 44 trace.sidebar.addMenuItem({ 45 section: 'current_trace', 46 text: 'Explore', 47 href: '#!/explore', 48 icon: 'data_exploration', 49 }); 50 } 51} 52