Merge "ui: Add generic slice/counter aggregations plugin" into main
diff --git a/ui/src/core/default_plugins.ts b/ui/src/core/default_plugins.ts
index 8a17ad3..fe97a70 100644
--- a/ui/src/core/default_plugins.ts
+++ b/ui/src/core/default_plugins.ts
@@ -44,6 +44,7 @@
   'dev.perfetto.FlagsPage',
   'dev.perfetto.Frames',
   'dev.perfetto.Ftrace',
+  'dev.perfetto.GenericAggregations',
   'dev.perfetto.GpuFreq',
   'dev.perfetto.HeapProfile',
   'dev.perfetto.InstrumentsSamplesProfile',
@@ -61,8 +62,8 @@
   'dev.perfetto.RestorePinnedTrack',
   'dev.perfetto.Sched',
   'dev.perfetto.Screenshots',
-  'dev.perfetto.StandardGroups',
   'dev.perfetto.SqlModules',
+  'dev.perfetto.StandardGroups',
   'dev.perfetto.SysUIWorkspace',
   'dev.perfetto.Thread',
   'dev.perfetto.ThreadState',
diff --git a/ui/src/plugins/dev.perfetto.TraceProcessorTrack/counter_selection_aggregator.ts b/ui/src/plugins/dev.perfetto.GenericAggregations/counter_selection_aggregator.ts
similarity index 100%
rename from ui/src/plugins/dev.perfetto.TraceProcessorTrack/counter_selection_aggregator.ts
rename to ui/src/plugins/dev.perfetto.GenericAggregations/counter_selection_aggregator.ts
diff --git a/ui/src/plugins/dev.perfetto.GenericAggregations/index.ts b/ui/src/plugins/dev.perfetto.GenericAggregations/index.ts
new file mode 100644
index 0000000..1d802f0
--- /dev/null
+++ b/ui/src/plugins/dev.perfetto.GenericAggregations/index.ts
@@ -0,0 +1,36 @@
+// Copyright (C) 2021 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 {PerfettoPlugin} from '../../public/plugin';
+import {Trace} from '../../public/trace';
+import {CounterSelectionAggregator} from './counter_selection_aggregator';
+import {SliceSelectionAggregator} from './slice_selection_aggregator';
+
+/**
+ * This plugin adds the generic aggregations for slice tracks and counter
+ * tracks.
+ */
+export default class implements PerfettoPlugin {
+  static readonly id = 'dev.perfetto.GenericAggregations';
+
+  async onTraceLoad(ctx: Trace): Promise<void> {
+    ctx.selection.registerAreaSelectionAggregator(
+      new CounterSelectionAggregator(),
+    );
+
+    ctx.selection.registerAreaSelectionAggregator(
+      new SliceSelectionAggregator(),
+    );
+  }
+}
diff --git a/ui/src/plugins/dev.perfetto.TraceProcessorTrack/slice_selection_aggregator.ts b/ui/src/plugins/dev.perfetto.GenericAggregations/slice_selection_aggregator.ts
similarity index 100%
rename from ui/src/plugins/dev.perfetto.TraceProcessorTrack/slice_selection_aggregator.ts
rename to ui/src/plugins/dev.perfetto.GenericAggregations/slice_selection_aggregator.ts
diff --git a/ui/src/plugins/dev.perfetto.TraceProcessorTrack/index.ts b/ui/src/plugins/dev.perfetto.TraceProcessorTrack/index.ts
index afb7e9f..615b87e 100644
--- a/ui/src/plugins/dev.perfetto.TraceProcessorTrack/index.ts
+++ b/ui/src/plugins/dev.perfetto.TraceProcessorTrack/index.ts
@@ -21,11 +21,9 @@
 import {NUM, NUM_NULL, STR, STR_NULL} from '../../trace_processor/query_result';
 import ProcessThreadGroupsPlugin from '../dev.perfetto.ProcessThreadGroups';
 import StandardGroupsPlugin from '../dev.perfetto.StandardGroups';
-import {CounterSelectionAggregator} from './counter_selection_aggregator';
 import {SLICE_TRACK_SCHEMAS} from './slice_tracks';
 import {TraceProcessorCounterTrack} from './trace_processor_counter_track';
 import {COUNTER_TRACK_SCHEMAS} from './counter_tracks';
-import {SliceSelectionAggregator} from './slice_selection_aggregator';
 import {TraceProcessorSliceTrack} from './trace_processor_slice_track';
 import {TopLevelTrackGroup, TrackGroupSchema} from './types';
 import {removeFalsyValues} from '../../base/array_utils';
@@ -41,10 +39,6 @@
     await this.addCounters(ctx);
     await this.addSlices(ctx);
 
-    ctx.selection.registerAreaSelectionAggregator(
-      new CounterSelectionAggregator(),
-    );
-
     ctx.selection.registerSqlSelectionResolver({
       sqlTableName: 'slice',
       callback: async (id: number) => {
@@ -73,10 +67,6 @@
         };
       },
     });
-
-    ctx.selection.registerAreaSelectionAggregator(
-      new SliceSelectionAggregator(),
-    );
   }
 
   private async addCounters(ctx: Trace) {