• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2019 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 {perfetto} from '../gen/protos';
16
17// In this file are contained a few functions to simplify the proto parsing.
18
19export function extractTraceConfig(enableTracingRequest: Uint8Array):
20    Uint8Array|undefined {
21  try {
22    const enableTracingObject =
23        perfetto.protos.EnableTracingRequest.decode(enableTracingRequest);
24    if (!enableTracingObject.traceConfig) return undefined;
25    return perfetto.protos.TraceConfig.encode(enableTracingObject.traceConfig)
26        .finish();
27  } catch (e) {  // This catch is for possible proto encoding/decoding issues.
28    console.error('Error extracting the config: ', e.message);
29    return undefined;
30  }
31}
32
33export function extractDurationFromTraceConfig(traceConfigProto: Uint8Array) {
34  try {
35    return perfetto.protos.TraceConfig.decode(traceConfigProto).durationMs;
36  } catch (e) {  // This catch is for possible proto encoding/decoding issues.
37    return undefined;
38  }
39}