• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
16import {Component} from '@angular/core';
17import {
18  EnableConfiguration,
19  SelectionConfiguration,
20  TraceConfiguration,
21} from 'trace_collection/trace_collection_utils';
22import {TracingConfig} from 'trace_collection/tracing_config';
23
24@Component({
25  selector: 'trace-config',
26  template: `
27    <h3 class="mat-subheading-2">Trace targets</h3>
28
29    <div class="checkboxes">
30      <mat-checkbox
31        *ngFor="let traceKey of objectKeys(tracingConfig.getTraceConfig())"
32        color="primary"
33        class="trace-checkbox"
34        [checked]="tracingConfig.getTraceConfig()[traceKey].run"
35        [indeterminate]="
36          tracingConfig.getTraceConfig()[traceKey].isTraceCollection
37            ? someTraces(tracingConfig.getTraceConfig()[traceKey])
38            : false
39        "
40        (change)="changeRunTrace($event.checked, tracingConfig.getTraceConfig()[traceKey])"
41        >{{ tracingConfig.getTraceConfig()[traceKey].name }}</mat-checkbox
42      >
43    </div>
44
45    <ng-container *ngFor="let traceKey of advancedConfigTraces()">
46      <mat-divider></mat-divider>
47
48      <h3 class="mat-subheading-2">
49        {{ tracingConfig.getTraceConfig()[traceKey].name }} configuration
50      </h3>
51
52      <div
53        *ngIf="tracingConfig.getTraceConfig()[traceKey].config?.enableConfigs.length > 0"
54        class="enable-config-opt">
55        <mat-checkbox
56          *ngFor="let enableConfig of traceEnableConfigs(tracingConfig.getTraceConfig()[traceKey])"
57          color="primary"
58          class="enable-config"
59          [disabled]="
60            !tracingConfig.getTraceConfig()[traceKey].run &&
61            !tracingConfig.getTraceConfig()[traceKey].isTraceCollection
62          "
63          [(ngModel)]="enableConfig.enabled"
64          (change)="changeTraceCollectionConfig(tracingConfig.getTraceConfig()[traceKey])"
65          >{{ enableConfig.name }}</mat-checkbox
66        >
67      </div>
68
69      <div
70        *ngIf="tracingConfig.getTraceConfig()[traceKey].config?.selectionConfigs.length > 0"
71        class="selection-config-opt">
72        <mat-form-field
73          *ngFor="
74            let selectionConfig of traceSelectionConfigs(tracingConfig.getTraceConfig()[traceKey])
75          "
76          class="config-selection"
77          appearance="fill">
78          <mat-label>{{ selectionConfig.name }}</mat-label>
79
80          <mat-select
81            class="selected-value"
82            [(value)]="selectionConfig.value"
83            [disabled]="!tracingConfig.getTraceConfig()[traceKey].run">
84            <mat-option *ngFor="let option of selectionConfig.options" value="{{ option }}">{{
85              option
86            }}</mat-option>
87          </mat-select>
88        </mat-form-field>
89      </div>
90    </ng-container>
91  `,
92  styles: [
93    `
94      .checkboxes {
95        display: grid;
96        grid-template-columns: repeat(3, 1fr);
97        column-gap: 10px;
98      }
99      .enable-config-opt,
100      .selection-config-opt {
101        display: flex;
102        flex-direction: row;
103        flex-wrap: wrap;
104        gap: 10px;
105      }
106    `,
107  ],
108})
109export class TraceConfigComponent {
110  objectKeys = Object.keys;
111  tracingConfig = TracingConfig.getInstance();
112
113  advancedConfigTraces() {
114    const advancedConfigs: string[] = [];
115    Object.keys(this.tracingConfig.getTraceConfig()).forEach((traceKey: string) => {
116      if (this.tracingConfig.getTraceConfig()[traceKey].config) {
117        advancedConfigs.push(traceKey);
118      }
119    });
120    return advancedConfigs;
121  }
122
123  traceEnableConfigs(trace: TraceConfiguration): EnableConfiguration[] {
124    if (trace.config) {
125      return trace.config.enableConfigs;
126    } else {
127      return [];
128    }
129  }
130
131  traceSelectionConfigs(trace: TraceConfiguration): SelectionConfiguration[] {
132    if (trace.config) {
133      return trace.config.selectionConfigs;
134    } else {
135      return [];
136    }
137  }
138
139  someTraces(trace: TraceConfiguration): boolean {
140    return this.traceEnableConfigs(trace).filter((trace) => trace.enabled).length > 0 && !trace.run;
141  }
142
143  changeRunTrace(run: boolean, trace: TraceConfiguration): void {
144    trace.run = run;
145    if (trace.isTraceCollection) {
146      this.traceEnableConfigs(trace).forEach((c: EnableConfiguration) => (c.enabled = run));
147    }
148  }
149
150  changeTraceCollectionConfig(trace: TraceConfiguration): void {
151    if (trace.isTraceCollection) {
152      trace.run = this.traceEnableConfigs(trace).every((c: EnableConfiguration) => c.enabled);
153    }
154  }
155}
156