Snap for 10252918 from 09a1c31019 to udc-release

Change-Id: I5f5b19f15d3369a8b1c73b3037a61f7b74b65f9e
This commit is contained in:
Android Build Coastguard Worker
2023-06-03 02:05:50 +00:00
23 changed files with 338 additions and 21 deletions

8
PREUPLOAD.cfg Normal file
View File

@@ -0,0 +1,8 @@
# Per-project `repo upload` hook settings.
# https://android.googlesource.com/platform/tools/repohooks
[Options]
ignore_merged_commits = true
[Hook Scripts]
winscope = ./tools/winscope/hooks/pre-upload ${PREUPLOAD_FILES}

19
tools/winscope/hooks/pre-upload Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/sh
WINSCOPE_SRC_PATTERN="tools/winscope/"
match=false
for file in "$@"
do
if echo $file | grep --quiet "$WINSCOPE_SRC_PATTERN"
then
match=true
fi
done
# If there are changes to winscope files and npm is installed
if $match && (which node > /dev/null)
then
echo "Running winscope presubmit tests..."
npm run test:presubmit --prefix $WINSCOPE_SRC_PATTERN
fi

View File

@@ -19,6 +19,7 @@
"test:unit": "webpack --config webpack.config.unit_test.js && jasmine dist/unit_test/bundle.js",
"test:component": "npx karma start",
"test:e2e": "rm -rf dist/e2e_test && npx tsc -p ./src/test/e2e && npx protractor protractor.config.js",
"test:presubmit": "npm run test:unit && npm run test:component && npm run format:check && npm run tslint:check && npm run eslint:check && npm run deps_graph:check_cycles",
"test:all": "npm run test:unit && npm run test:component && npm run test:e2e && npm run format:check && npm run tslint:check && npm run eslint:check && npm run deps_graph:check_cycles"
},
"private": true,

View File

@@ -26,14 +26,15 @@ export class AbtChromeExtensionProtocol implements BuganizerAttachmentsDownloadE
static readonly ABT_EXTENSION_ID = 'mbbaofdfoekifkfpgehgffcpagbbjkmj';
private onAttachmentsDownloadStart: OnBuganizerAttachmentsDownloadStart =
FunctionUtils.DO_NOTHING;
private onttachmentsDownloaded: OnBuganizerAttachmentsDownloaded = FunctionUtils.DO_NOTHING_ASYNC;
private onAttachmentsDownloaded: OnBuganizerAttachmentsDownloaded =
FunctionUtils.DO_NOTHING_ASYNC;
setOnBuganizerAttachmentsDownloadStart(callback: OnBuganizerAttachmentsDownloadStart) {
this.onAttachmentsDownloadStart = callback;
}
setOnBuganizerAttachmentsDownloaded(callback: OnBuganizerAttachmentsDownloaded) {
this.onttachmentsDownloaded = callback;
this.onAttachmentsDownloaded = callback;
}
run() {
@@ -83,7 +84,7 @@ export class AbtChromeExtensionProtocol implements BuganizerAttachmentsDownloadE
});
const files = await Promise.all(filesBlobPromises);
await this.onttachmentsDownloaded(files);
await this.onAttachmentsDownloaded(files);
}
private isOpenBuganizerResponseMessage(

View File

@@ -356,7 +356,7 @@ export class AppComponent implements TraceDataListener {
return '';
}
return `${TRACE_INFO[trace.type].name} (${trace.descriptors.join(', ')})`;
return `${trace.descriptors.join(', ')}`;
}
private getActiveTrace(view: View): LoadedTrace | undefined {

View File

@@ -83,7 +83,7 @@ export class Mediator {
}
);
this.crossToolProtocol.setOnTimestampReceived(async (timestamp: Timestamp) => {
this.crossToolProtocol.setOnTimestampReceived((timestamp: Timestamp) => {
this.onRemoteTimestampReceived(timestamp);
});
@@ -203,7 +203,7 @@ export class Mediator {
private async processRemoteFilesReceived(files: File[]) {
this.resetAppToInitialState();
this.processFiles(files);
await this.processFiles(files);
}
private async processFiles(files: File[]) {

View File

@@ -30,6 +30,7 @@ const TAG_ICON = 'details';
const TRACE_ERROR_ICON = 'warning';
const EVENT_LOG_ICON = 'description';
const TRANSITION_ICON = 'animation';
const CUJ_ICON = 'label';
interface TraceInfoMap {
[key: number]: {
@@ -161,4 +162,10 @@ export const TRACE_INFO: TraceInfoMap = {
color: '#EC407A',
downloadArchiveDir: 'transition',
},
[TraceType.CUJS]: {
name: 'Cujs',
icon: CUJ_ICON,
color: '#EC407A',
downloadArchiveDir: 'eventlog',
},
};

View File

@@ -16,6 +16,7 @@
import {FunctionUtils, OnProgressUpdateType} from 'common/function_utils';
import {ParserError, ParserFactory} from 'parsers/parser_factory';
import {TracesParserCujs} from 'parsers/traces_parser_cujs';
import {TracesParserTransitions} from 'parsers/traces_parser_transitions';
import {FrameMapper} from 'trace/frame_mapper';
import {LoadedTrace} from 'trace/loaded_trace';
@@ -37,15 +38,21 @@ class TracePipeline {
traceFiles: TraceFile[],
onLoadProgressUpdate: OnProgressUpdateType = FunctionUtils.DO_NOTHING
): Promise<ParserError[]> {
traceFiles = await this.filterBugreportFilesIfNeeded(traceFiles);
const [parsers, parserErrors] = await this.parserFactory.createParsers(
traceFiles,
onLoadProgressUpdate
);
this.parsers = parsers.map((it) => it.parser);
const tracesParser = new TracesParserTransitions(this.parsers);
if (tracesParser.canProvideEntries()) {
this.parsers.push(tracesParser);
const tracesParsers = [
new TracesParserTransitions(this.parsers),
new TracesParserCujs(this.parsers),
];
for (const tracesParser of tracesParsers) {
if (tracesParser.canProvideEntries()) {
this.parsers.push(tracesParser);
}
}
for (const parser of parsers) {
@@ -111,6 +118,36 @@ class TracePipeline {
this.files = new Map<TraceType, TraceFile>();
}
private async filterBugreportFilesIfNeeded(files: TraceFile[]): Promise<TraceFile[]> {
const bugreportMainEntry = files.find((file) => file.file.name === 'main_entry.txt');
if (!bugreportMainEntry) {
return files;
}
const bugreportName = (await bugreportMainEntry.file.text()).trim();
const isBugreport = files.find((file) => file.file.name === bugreportName) !== undefined;
if (!isBugreport) {
return files;
}
const BUGREPORT_TRACE_DIRS = ['FS/data/misc/wmtrace/', 'FS/data/misc/perfetto-traces/'];
const isFileWithinBugreportTraceDir = (file: TraceFile) => {
for (const traceDir of BUGREPORT_TRACE_DIRS) {
if (file.file.name.startsWith(traceDir)) {
return true;
}
}
return false;
};
const fileBelongsToBugreport = (file: TraceFile) =>
file.parentArchive === bugreportMainEntry.parentArchive;
return files.filter((file) => {
return isFileWithinBugreportTraceDir(file) || !fileBelongsToBugreport(file);
});
}
private getCommonTimestampType(): TimestampType {
if (this.commonTimestampType !== undefined) {
return this.commonTimestampType;

View File

@@ -39,6 +39,74 @@ describe('TracePipeline', () => {
expect(traceEntries.get(TraceType.SURFACE_FLINGER)?.length).toBeGreaterThan(0);
});
it('can load bugreport and ignores non-trace dirs', async () => {
expect(tracePipeline.getLoadedTraces().length).toEqual(0);
// Could be any file, we just need an instance of File to be used as a fake bugreport archive
const bugreportArchive = await UnitTestUtils.getFixtureFile(
'bugreports/bugreport_stripped.zip'
);
const bugreportFiles = [
new TraceFile(
await UnitTestUtils.getFixtureFile('bugreports/main_entry.txt', 'main_entry.txt'),
bugreportArchive
),
new TraceFile(
await UnitTestUtils.getFixtureFile(
'bugreports/bugreport-codename_beta-UPB2.230407.019-2023-05-30-14-33-48.txt',
'bugreport-codename_beta-UPB2.230407.019-2023-05-30-14-33-48.txt'
),
bugreportArchive
),
new TraceFile(
await UnitTestUtils.getFixtureFile(
'traces/elapsed_and_real_timestamp/SurfaceFlinger.pb',
'FS/data/misc/wmtrace/surface_flinger.bp'
),
bugreportArchive
),
new TraceFile(
await UnitTestUtils.getFixtureFile(
'traces/elapsed_and_real_timestamp/Transactions.pb',
'FS/data/misc/wmtrace/transactions.bp'
),
bugreportArchive
),
new TraceFile(
await UnitTestUtils.getFixtureFile(
'traces/elapsed_and_real_timestamp/WindowManager.pb',
'FS/data/misc/ignored-dir/window_manager.bp'
),
bugreportArchive
),
];
// Corner case:
// A plain trace file is loaded along the bugreport -> trace file must not be ignored
//
// Note:
// The even weirder corner case where two bugreports are loaded at the same time is
// currently not properly handled.
const plainTraceFile = new TraceFile(
await UnitTestUtils.getFixtureFile(
'traces/elapsed_and_real_timestamp/InputMethodClients.pb',
'would-be-ignored-if-was-part-of-bugreport/input_method_clients.pb'
)
);
const mergedFiles = bugreportFiles.concat([plainTraceFile]);
const errors = await tracePipeline.loadTraceFiles(mergedFiles);
expect(errors.length).toEqual(0);
tracePipeline.buildTraces();
const traces = tracePipeline.getTraces();
expect(traces.getTrace(TraceType.SURFACE_FLINGER)).toBeDefined();
expect(traces.getTrace(TraceType.TRANSACTIONS)).toBeDefined();
expect(traces.getTrace(TraceType.WINDOW_MANAGER)).toBeUndefined(); // ignored
expect(traces.getTrace(TraceType.INPUT_METHOD_CLIENTS)).toBeDefined();
});
it('is robust to invalid trace files', async () => {
const invalidTraceFiles = [
new TraceFile(await UnitTestUtils.getFixtureFile('winscope_homepage.png')),

View File

@@ -61,9 +61,8 @@ class FileUtils {
// Ignore directories
continue;
} else {
const name = FileUtils.removeDirFromFileName(filename);
const fileBlob = await file.async('blob');
const unzippedFile = new File([fileBlob], name);
const unzippedFile = new File([fileBlob], filename);
unzippedFiles.push(unzippedFile);
}

View File

@@ -128,7 +128,6 @@ 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())));
}

View File

@@ -20,7 +20,7 @@ import {Timestamp, TimestampType} from 'trace/timestamp';
import {TraceFile} from 'trace/trace_file';
import {TraceType} from 'trace/trace_type';
abstract class AbstractParser implements Parser<object> {
abstract class AbstractParser<T extends object = object> implements Parser<object> {
protected traceFile: TraceFile;
protected decodedEntries: any[] = [];
private timestamps: Map<TimestampType, Timestamp[]> = new Map<TimestampType, Timestamp[]>();
@@ -78,7 +78,7 @@ abstract class AbstractParser implements Parser<object> {
return this.timestamps.get(type);
}
getEntry(index: number, timestampType: TimestampType): object {
getEntry(index: number, timestampType: TimestampType): T {
return this.processDecodedEntry(index, timestampType, this.decodedEntries[index]);
}

View File

@@ -19,7 +19,7 @@ import {RealTimestamp, Timestamp, TimestampType} from 'trace/timestamp';
import {TraceType} from 'trace/trace_type';
import {AbstractParser} from './abstract_parser';
class ParserEventLog extends AbstractParser {
class ParserEventLog extends AbstractParser<Event> {
override getTraceType(): TraceType {
return TraceType.EVENT_LOG;
}

View File

@@ -0,0 +1,90 @@
/*
* Copyright 2023, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Cuj, CujTrace, EventLog, Transition} from 'trace/flickerlib/common';
import {Parser} from 'trace/parser';
import {Timestamp, TimestampType} from 'trace/timestamp';
import {TraceType} from 'trace/trace_type';
import {AbstractTracesParser} from './abstract_traces_parser';
import {ParserEventLog} from './parser_eventlog';
export class TracesParserCujs extends AbstractTracesParser<Transition> {
private readonly eventLogTrace: ParserEventLog | undefined;
private readonly descriptors: string[];
constructor(parsers: Array<Parser<object>>) {
super(parsers);
const eventlogTraces = this.parsers.filter((it) => it.getTraceType() === TraceType.EVENT_LOG);
if (eventlogTraces.length > 0) {
this.eventLogTrace = eventlogTraces[0] as ParserEventLog;
}
if (this.eventLogTrace !== undefined) {
this.descriptors = this.eventLogTrace.getDescriptors();
} else {
this.descriptors = [];
}
}
override canProvideEntries(): boolean {
return this.eventLogTrace !== undefined;
}
getLengthEntries(): number {
return this.getDecodedEntries().length;
}
getEntry(index: number, timestampType: TimestampType): Transition {
return this.getDecodedEntries()[index];
}
private cujTrace: CujTrace | undefined;
getDecodedEntries(): Cuj[] {
if (this.eventLogTrace === undefined) {
throw new Error('eventLogTrace not defined');
}
if (this.cujTrace === undefined) {
const events: Event[] = [];
for (let i = 0; i < this.eventLogTrace.getLengthEntries(); i++) {
events.push(this.eventLogTrace.getEntry(i, TimestampType.REAL));
}
this.cujTrace = new EventLog(events).cujTrace;
}
return this.cujTrace.entries;
}
override getDescriptors(): string[] {
return this.descriptors;
}
getTraceType(): TraceType {
return TraceType.CUJS;
}
override getTimestamp(type: TimestampType, transition: Transition): undefined | Timestamp {
if (type === TimestampType.ELAPSED) {
return new Timestamp(type, BigInt(transition.timestamp.elapsedNanos.toString()));
} else if (type === TimestampType.REAL) {
return new Timestamp(type, BigInt(transition.timestamp.unixNanos.toString()));
}
return undefined;
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {assertDefined} from 'common/assert_utils';
import {UnitTestUtils} from 'test/unit/utils';
import {Cuj} from 'trace/flickerlib/common';
import {Parser} from 'trace/parser';
import {Timestamp, TimestampType} from 'trace/timestamp';
import {TraceType} from 'trace/trace_type';
import {TracesParserCujs} from './traces_parser_cujs';
describe('ParserCujs', () => {
let parser: Parser<Cuj>;
beforeAll(async () => {
const eventLogParser = assertDefined(
await UnitTestUtils.getParser('traces/eventlog.winscope')
) as Parser<Event>;
parser = new TracesParserCujs([eventLogParser]);
});
it('has expected trace type', () => {
expect(parser.getTraceType()).toEqual(TraceType.CUJS);
});
it('provides elapsed timestamps', () => {
const timestamps = parser.getTimestamps(TimestampType.ELAPSED)!;
expect(timestamps.length).toEqual(16);
const expected = [
new Timestamp(TimestampType.ELAPSED, 2661012770462n),
new Timestamp(TimestampType.ELAPSED, 2661012874914n),
new Timestamp(TimestampType.ELAPSED, 2661012903966n),
];
expect(timestamps.slice(0, 3)).toEqual(expected);
});
it('provides real timestamps', () => {
const expected = [
new Timestamp(TimestampType.REAL, 1681207048025446000n),
new Timestamp(TimestampType.REAL, 1681207048025551000n),
new Timestamp(TimestampType.REAL, 1681207048025580000n),
];
const timestamps = parser.getTimestamps(TimestampType.REAL)!;
expect(timestamps.length).toEqual(16);
expect(timestamps.slice(0, 3)).toEqual(expected);
});
});

View File

@@ -46,7 +46,11 @@ class FileImpl {
}
text(): Promise<string> {
throw new Error('Not implemented!');
const utf8Decoder = new TextDecoder();
const text = utf8Decoder.decode(this.buffer);
return new Promise<string>((resolve) => {
resolve(text);
});
}
}

View File

@@ -18,9 +18,12 @@ import * as path from 'path';
import {FileImpl} from './file_impl';
class CommonTestUtils {
static async getFixtureFile(filename: string): Promise<File> {
const buffer = CommonTestUtils.loadFixture(filename);
return new FileImpl(buffer, filename) as unknown as File;
static async getFixtureFile(
srcFilename: string,
dstFilename: string = srcFilename
): Promise<File> {
const buffer = CommonTestUtils.loadFixture(srcFilename);
return new FileImpl(buffer, dstFilename) as unknown as File;
}
static loadFixture(filename: string): ArrayBuffer {

View File

@@ -0,0 +1,6 @@
========================================================
== dumpstate: 2023-05-30 14:33:48
========================================================
# ORIGINAL CONTENTS REMOVED TO AVOID INFORMATION LEAKS

View File

@@ -0,0 +1 @@
bugreport-codename_beta-UPB2.230407.019-2023-05-30-14-33-48.txt

View File

@@ -62,6 +62,8 @@ const Event = require('flicker').android.tools.common.traces.events.Event;
const FlickerEvent = require('flicker').android.tools.common.traces.events.FlickerEvent;
const FocusEvent = require('flicker').android.tools.common.traces.events.FocusEvent;
const EventLogParser = require('flicker').android.tools.common.parsers.events.EventLogParser;
const CujTrace = require('flicker').android.tools.common.parsers.events.CujTrace;
const Cuj = require('flicker').android.tools.common.parsers.events.Cuj;
// Transitions
const Transition = require('flicker').android.tools.common.traces.wm.Transition;
@@ -313,6 +315,8 @@ export {
FlickerEvent,
FocusEvent,
EventLogParser,
CujTrace,
Cuj,
// Transitions
Transition,
TransitionType,

View File

@@ -14,11 +14,13 @@
* limitations under the License.
*/
import {FileUtils} from 'common/file_utils';
export class TraceFile {
constructor(public file: File, public parentArchive?: File) {}
getDescriptor(): string {
let descriptor = this.file.name;
let descriptor = FileUtils.removeDirFromFileName(this.file.name);
if (this.parentArchive?.name !== undefined) {
descriptor += ` (${this.parentArchive?.name})`;
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Event, Transition} from 'trace/flickerlib/common';
import {Cuj, Event, Transition} from 'trace/flickerlib/common';
import {LayerTraceEntry} from './flickerlib/layers/LayerTraceEntry';
import {WindowManagerState} from './flickerlib/windows/WindowManagerState';
import {LogMessage} from './protolog';
@@ -38,6 +38,7 @@ export enum TraceType {
WM_TRANSITION,
SHELL_TRANSITION,
TRANSITION,
CUJS,
TAG,
ERROR,
TEST_TRACE_STRING,
@@ -63,6 +64,7 @@ export interface TraceEntryTypeMap {
[TraceType.WM_TRANSITION]: object;
[TraceType.SHELL_TRANSITION]: object;
[TraceType.TRANSITION]: Transition;
[TraceType.CUJS]: Cuj;
[TraceType.TAG]: object;
[TraceType.ERROR]: object;
[TraceType.TEST_TRACE_STRING]: string;