1/* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {assertDefined} from 'common/assert_utils'; 18import {WinscopeEvent} from 'messaging/winscope_event'; 19import {EmitEvent} from 'messaging/winscope_event_emitter'; 20import {Trace} from 'trace/trace'; 21import {Traces} from 'trace/traces'; 22import {TraceType} from 'trace/trace_type'; 23import {PropertyTreeNode} from 'trace/tree_node/property_tree_node'; 24import {TimestampClickDetail, ViewerEvents} from 'viewers/common/viewer_events'; 25import {View, Viewer, ViewType} from 'viewers/viewer'; 26import {Presenter} from './presenter'; 27import {UiData} from './ui_data'; 28 29class ViewerTransactions implements Viewer { 30 static readonly DEPENDENCIES: TraceType[] = [TraceType.TRANSACTIONS]; 31 32 private readonly trace: Trace<PropertyTreeNode>; 33 private readonly htmlElement: HTMLElement; 34 private readonly presenter: Presenter; 35 private readonly view: View; 36 37 constructor( 38 trace: Trace<PropertyTreeNode>, 39 traces: Traces, 40 storage: Storage, 41 ) { 42 this.trace = trace; 43 this.htmlElement = document.createElement('viewer-transactions'); 44 45 this.presenter = new Presenter(trace, storage, (data: UiData) => { 46 (this.htmlElement as any).inputData = data; 47 }); 48 49 this.htmlElement.addEventListener( 50 ViewerEvents.VSyncIdFilterChanged, 51 (event) => { 52 this.presenter.onVSyncIdFilterChanged((event as CustomEvent).detail); 53 }, 54 ); 55 56 this.htmlElement.addEventListener( 57 ViewerEvents.PidFilterChanged, 58 (event) => { 59 this.presenter.onPidFilterChanged((event as CustomEvent).detail); 60 }, 61 ); 62 63 this.htmlElement.addEventListener( 64 ViewerEvents.UidFilterChanged, 65 (event) => { 66 this.presenter.onUidFilterChanged((event as CustomEvent).detail); 67 }, 68 ); 69 70 this.htmlElement.addEventListener( 71 ViewerEvents.TypeFilterChanged, 72 (event) => { 73 this.presenter.onTypeFilterChanged((event as CustomEvent).detail); 74 }, 75 ); 76 77 this.htmlElement.addEventListener( 78 ViewerEvents.LayerIdFilterChanged, 79 (event) => { 80 this.presenter.onLayerIdFilterChanged((event as CustomEvent).detail); 81 }, 82 ); 83 84 this.htmlElement.addEventListener( 85 ViewerEvents.WhatFilterChanged, 86 (event) => { 87 this.presenter.onWhatFilterChanged((event as CustomEvent).detail); 88 }, 89 ); 90 91 this.htmlElement.addEventListener( 92 ViewerEvents.TransactionIdFilterChanged, 93 (event) => { 94 this.presenter.onTransactionIdFilterChanged( 95 (event as CustomEvent).detail, 96 ); 97 }, 98 ); 99 100 this.htmlElement.addEventListener(ViewerEvents.LogClicked, (event) => { 101 this.presenter.onEntryClicked((event as CustomEvent).detail); 102 }); 103 this.htmlElement.addEventListener( 104 ViewerEvents.LogChangedByKeyPress, 105 (event) => { 106 this.presenter.onEntryChangedByKeyPress((event as CustomEvent).detail); 107 }, 108 ); 109 this.htmlElement.addEventListener( 110 ViewerEvents.TimestampClick, 111 async (event) => { 112 const detail: TimestampClickDetail = (event as CustomEvent).detail; 113 await this.presenter.onLogTimestampClicked(assertDefined(detail.index)); 114 }, 115 ); 116 117 this.htmlElement.addEventListener( 118 ViewerEvents.PropertiesUserOptionsChange, 119 (event) => 120 this.presenter.onPropertiesUserOptionsChange( 121 (event as CustomEvent).detail.userOptions, 122 ), 123 ); 124 125 this.view = new View( 126 ViewType.TAB, 127 this.getTraces(), 128 this.htmlElement, 129 'Transactions', 130 ); 131 } 132 133 async onWinscopeEvent(event: WinscopeEvent) { 134 await this.presenter.onAppEvent(event); 135 } 136 137 setEmitEvent(callback: EmitEvent) { 138 this.presenter.setEmitEvent(callback); 139 } 140 141 getViews(): View[] { 142 return [this.view]; 143 } 144 145 getTraces(): Array<Trace<PropertyTreeNode>> { 146 return [this.trace]; 147 } 148} 149 150export {ViewerTransactions}; 151