blob: 79d8417dc1154f410739417bd3129bdbddf9c8e6 [file] [log] [blame]
Hector Dearman4544f372018-09-19 12:32:36 +01001// Copyright (C) 2018 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 * as m from 'mithril';
16
17import {createPage} from './pages';
18
19const RECORD_COMMAND_LINE =
20 'echo CgYIgKAGIAESIwohCgxsaW51eC5mdHJhY2UQAKIGDhIFc2NoZWQSBWlucHV0GJBOMh0KFnBlcmZldHRvLnRyYWNlZF9wcm9iZXMQgCAYBEAASAA= | base64 --decode | adb shell "perfetto -c - -o /data/misc/perfetto-traces/trace" && adb pull /data/misc/perfetto-traces/trace /tmp/trace';
21
22async function copyToClipboard(text: string): Promise<void> {
23 try {
24 // TODO(hjd): Fix typescript type for navigator.
25 // tslint:disable-next-line no-any
26 await(navigator as any).clipboard.writeText(text);
27 } catch (err) {
28 console.error(`Failed to copy "${text}" to clipboard: ${err}`);
29 }
30}
31
Deepanjan Roy97f63242018-09-20 15:32:01 -040032interface CodeSampleAttrs {
33 text: string;
34}
35
36class CodeSample implements m.ClassComponent<CodeSampleAttrs> {
37 view({attrs}: m.CVnode<CodeSampleAttrs>) {
Hector Dearman4544f372018-09-19 12:32:36 +010038 return m(
39 '.example-code',
40 m('code', attrs.text),
41 m('button',
42 {
43 onclick: () => copyToClipboard(attrs.text),
44 },
45 'Copy to clipboard'), );
Deepanjan Roy97f63242018-09-20 15:32:01 -040046 }
47}
Hector Dearman4544f372018-09-19 12:32:36 +010048
49export const RecordPage = createPage({
50 view() {
51 return m(
52 '.text-column',
53 'To collect a 10 second Perfetto trace from an Android phone run this',
54 ' command:',
55 m(CodeSample, {text: RECORD_COMMAND_LINE}),
56 'Then click "Open trace file" in the menu to the left and select',
57 ' "/tmp/trace".');
58 }
59});