diff options
author | Pablo Gamito <pablogamito@google.com> | 2023-05-23 16:41:23 +0000 |
---|---|---|
committer | Pablo Gamito <pablogamito@google.com> | 2023-05-23 16:41:25 +0000 |
commit | 9b0562b4d78dcb2552a8c7bf3e1695cce8c51728 (patch) | |
tree | 4717c68eb8a9b113f215d3efc5df987c04fe9dc8 | |
parent | c12b72ac707b30c3bc1b6804fba2635084147cc7 (diff) | |
download | development-9b0562b4d78dcb2552a8c7bf3e1695cce8c51728.tar.gz |
Format transition viewer timestamps to the right type
Bug: 277181336
Test: npm run test:all
Change-Id: I7eb981367191a47d3b50b31ee68492848572833a
6 files changed, 69 insertions, 46 deletions
diff --git a/tools/winscope/src/common/time_utils.ts b/tools/winscope/src/common/time_utils.ts index f2d903cd8..876c3c1e8 100644 --- a/tools/winscope/src/common/time_utils.ts +++ b/tools/winscope/src/common/time_utils.ts @@ -127,6 +127,19 @@ export class TimeUtils { ); } + static formattedKotlinTimestamp(time: any, timestampType: TimestampType): string { + console.log('time', time); + if (timestampType === TimestampType.ELAPSED) { + return TimeUtils.format(new ElapsedTimestamp(BigInt(time.elapsedNanos.toString()))); + } + + if (timestampType === TimestampType.REAL) { + return TimeUtils.format(new RealTimestamp(BigInt(time.unixNanos.toString()))); + } + + throw new Error('Unsupported timestamp'); + } + static TO_NANO = { ns: 1, ms: 1000000, diff --git a/tools/winscope/src/trace/trace.ts b/tools/winscope/src/trace/trace.ts index 236464859..dc1ad666e 100644 --- a/tools/winscope/src/trace/trace.ts +++ b/tools/winscope/src/trace/trace.ts @@ -124,6 +124,13 @@ export class Trace<T> { return this.parser.getDescriptors(); } + getTimestampType(): TimestampType { + if (this.timestampType === undefined) { + throw new Error('Trace no fully initialized yet!'); + } + return this.timestampType; + } + setFrameInfo(frameMap: FrameMap, framesRange: FramesRange | undefined) { if (frameMap.lengthEntries !== this.fullTrace.lengthEntries) { throw new Error('Attemped to set a frame map with incompatible number of entries'); diff --git a/tools/winscope/src/viewers/viewer_transitions/presenter.ts b/tools/winscope/src/viewers/viewer_transitions/presenter.ts index 8776b8c93..6a88bf6f7 100644 --- a/tools/winscope/src/viewers/viewer_transitions/presenter.ts +++ b/tools/winscope/src/viewers/viewer_transitions/presenter.ts @@ -17,7 +17,6 @@ import {assertDefined} from 'common/assert_utils'; import {TimeUtils} from 'common/time_utils'; import {LayerTraceEntry, Transition, WindowManagerState} from 'trace/flickerlib/common'; -import {ElapsedTimestamp} from 'trace/timestamp'; import {Trace} from 'trace/trace'; import {Traces} from 'trace/traces'; import {TraceEntryFinder} from 'trace/trace_entry_finder'; @@ -61,7 +60,17 @@ export class Presenter { const selectedTransition = this.uiData?.selectedTransition ?? undefined; const selectedTransitionPropertiesTree = this.uiData?.selectedTransitionPropertiesTree ?? undefined; - return new UiData(transitions, selectedTransition, selectedTransitionPropertiesTree); + + const timestampType = this.transitionTrace.getTimestampType(); + if (timestampType === undefined) { + throw new Error('Missing timestamp type in trace!'); + } + return new UiData( + transitions, + selectedTransition, + timestampType, + selectedTransitionPropertiesTree + ); } private makeSelectedTransitionPropertiesTree(transition: Transition): PropertiesTreeNode { @@ -124,47 +133,42 @@ export class Presenter { properties.push({propertyKey: 'handler', propertyValue: transition.handler}); } + const timestampType = this.transitionTrace.getTimestampType(); + if (!transition.createTime.isMin) { properties.push({ propertyKey: 'createTime', - propertyValue: TimeUtils.format( - new ElapsedTimestamp(BigInt(transition.createTime.elapsedNanos.toString())) - ), + propertyValue: TimeUtils.formattedKotlinTimestamp(transition.createTime, timestampType), }); } if (!transition.sendTime.isMin) { properties.push({ propertyKey: 'sendTime', - propertyValue: TimeUtils.format( - new ElapsedTimestamp(BigInt(transition.sendTime.elapsedNanos.toString())) - ), + propertyValue: TimeUtils.formattedKotlinTimestamp(transition.sendTime, timestampType), }); } if (!transition.dispatchTime.isMin) { properties.push({ propertyKey: 'dispatchTime', - propertyValue: TimeUtils.format( - new ElapsedTimestamp(BigInt(transition.dispatchTime.elapsedNanos.toString())) - ), + propertyValue: TimeUtils.formattedKotlinTimestamp(transition.dispatchTime, timestampType), }); } if (!transition.finishTime.isMax) { properties.push({ propertyKey: 'finishTime', - propertyValue: TimeUtils.format( - new ElapsedTimestamp(BigInt(transition.finishTime.elapsedNanos.toString())) - ), + propertyValue: TimeUtils.formattedKotlinTimestamp(transition.finishTime, timestampType), }); } if (transition.mergeRequestTime) { properties.push({ propertyKey: 'mergeRequestTime', - propertyValue: TimeUtils.format( - new ElapsedTimestamp(BigInt(transition.mergeRequestTime.elapsedNanos.toString())) + propertyValue: TimeUtils.formattedKotlinTimestamp( + transition.mergeRequestTime, + timestampType ), }); } @@ -172,18 +176,14 @@ export class Presenter { if (transition.shellAbortTime) { properties.push({ propertyKey: 'shellAbortTime', - propertyValue: TimeUtils.format( - new ElapsedTimestamp(BigInt(transition.shellAbortTime.elapsedNanos.toString())) - ), + propertyValue: TimeUtils.formattedKotlinTimestamp(transition.shellAbortTime, timestampType), }); } if (transition.mergeTime) { properties.push({ propertyKey: 'mergeTime', - propertyValue: TimeUtils.format( - new ElapsedTimestamp(BigInt(transition.mergeTime.elapsedNanos.toString())) - ), + propertyValue: TimeUtils.formattedKotlinTimestamp(transition.mergeTime, timestampType), }); } diff --git a/tools/winscope/src/viewers/viewer_transitions/ui_data.ts b/tools/winscope/src/viewers/viewer_transitions/ui_data.ts index 40c67a402..8676b99ec 100644 --- a/tools/winscope/src/viewers/viewer_transitions/ui_data.ts +++ b/tools/winscope/src/viewers/viewer_transitions/ui_data.ts @@ -15,22 +15,16 @@ */ import {Transition} from 'trace/flickerlib/common'; +import {TimestampType} from 'trace/timestamp'; import {PropertiesTreeNode} from 'viewers/common/ui_tree_utils'; export class UiData { constructor( - transitions: Transition[], - selectedTransition: Transition, - selectedTransitionPropertiesTree?: PropertiesTreeNode - ) { - this.entries = transitions; - this.selectedTransition = selectedTransition; - this.selectedTransitionPropertiesTree = selectedTransitionPropertiesTree; - } + public entries: Transition[], + public selectedTransition: Transition, + public timestampType: TimestampType, + public selectedTransitionPropertiesTree?: PropertiesTreeNode + ) {} - entries: Transition[] = []; - selectedTransition: Transition | undefined; - selectedTransitionPropertiesTree: PropertiesTreeNode | undefined; - - static EMPTY = new UiData([], undefined, undefined); + static EMPTY = new UiData([], undefined, TimestampType.REAL, undefined); } diff --git a/tools/winscope/src/viewers/viewer_transitions/viewer_transitions_component.ts b/tools/winscope/src/viewers/viewer_transitions/viewer_transitions_component.ts index f214bfc07..f64222309 100644 --- a/tools/winscope/src/viewers/viewer_transitions/viewer_transitions_component.ts +++ b/tools/winscope/src/viewers/viewer_transitions/viewer_transitions_component.ts @@ -17,7 +17,7 @@ import {Component, ElementRef, Inject, Input} from '@angular/core'; import {TimeUtils} from 'common/time_utils'; import {Transition} from 'trace/flickerlib/common'; -import {ElapsedTimestamp} from 'trace/timestamp'; +import {ElapsedTimestamp, TimestampType} from 'trace/timestamp'; import {Terminal} from 'viewers/common/ui_tree_utils'; import {Events} from './events'; import {UiData} from './ui_data'; @@ -49,7 +49,7 @@ import {UiData} from './ui_data'; </div> <div class="send-time"> <span *ngIf="!transition.sendTime.isMin" class="mat-body-1">{{ - formattedElapsedTime(transition.sendTime.elapsedNanos.toString()) + formattedTime(transition.sendTime, uiData.timestampType) }}</span> <span *ngIf="transition.sendTime.isMin"> n/a </span> </div> @@ -58,9 +58,10 @@ import {UiData} from './ui_data'; *ngIf="!transition.sendTime.isMin && !transition.finishTime.isMax" class="mat-body-1" >{{ - formattedElapsedTimeDiff( - transition.sendTime.elapsedNanos.toString(), - transition.finishTime.elapsedNanos.toString() + formattedTimeDiff( + transition.sendTime, + transition.finishTime, + uiData.timestampType ) }}</span > @@ -296,14 +297,15 @@ export class ViewerTransitionsComponent { return maxOfRange; } - formattedElapsedTime(timeStringNanos: string): string { - return TimeUtils.format(new ElapsedTimestamp(BigInt(timeStringNanos))); + formattedTime(time: any, timestampType: TimestampType): string { + return TimeUtils.formattedKotlinTimestamp(time, timestampType); } - formattedElapsedTimeDiff(timeStringNanos1: string, timeStringNanos2: string) { - return TimeUtils.format( - new ElapsedTimestamp(BigInt(timeStringNanos2) - BigInt(timeStringNanos1)) + formattedTimeDiff(time1: any, time2: any, timestampType: TimestampType): string { + const timeDiff = new ElapsedTimestamp( + BigInt(time2.elapsedNanos.toString()) - BigInt(time1.elapsedNanos.toString()) ); + return TimeUtils.format(timeDiff); } widthOf(transition: Transition) { diff --git a/tools/winscope/src/viewers/viewer_transitions/viewer_transitions_component_test.ts b/tools/winscope/src/viewers/viewer_transitions/viewer_transitions_component_test.ts index 229294b88..238862bbc 100644 --- a/tools/winscope/src/viewers/viewer_transitions/viewer_transitions_component_test.ts +++ b/tools/winscope/src/viewers/viewer_transitions/viewer_transitions_component_test.ts @@ -26,6 +26,7 @@ import { TransitionType, WmTransitionData, } from 'trace/flickerlib/common'; +import {TimestampType} from 'trace/timestamp'; import {UiData} from './ui_data'; import {ViewerTransitionsComponent} from './viewer_transitions_component'; @@ -80,8 +81,14 @@ function makeUiData(): UiData { const selectedTransition = undefined; const selectedTransitionPropertiesTree = undefined; + const timestampType = TimestampType.REAL; - return new UiData(transitions, selectedTransition, selectedTransitionPropertiesTree); + return new UiData( + transitions, + selectedTransition, + timestampType, + selectedTransitionPropertiesTree + ); } function createMockTransition( |