fuchsia_trace_parser: Fixed counter scope

The scope of a counter id should be at the process level and not the
thread level.

Bug: 229608867
Change-Id: I52a1026eab5e1d3038e987fed40d7e7c1502b44d
diff --git a/src/trace_processor/importers/fuchsia/fuchsia_trace_parser.cc b/src/trace_processor/importers/fuchsia/fuchsia_trace_parser.cc
index 74de318..def414c 100644
--- a/src/trace_processor/importers/fuchsia/fuchsia_trace_parser.cc
+++ b/src/trace_processor/importers/fuchsia/fuchsia_trace_parser.cc
@@ -267,9 +267,8 @@
           break;
         }
         case kCounter: {
-          UniqueTid utid =
-              procs->UpdateThread(static_cast<uint32_t>(tinfo.tid),
-                                  static_cast<uint32_t>(tinfo.pid));
+          UniquePid upid =
+              procs->GetOrCreateProcess(static_cast<uint32_t>(tinfo.pid));
           std::string name_str =
               context_->storage->GetString(name).ToStdString();
           // Note: In the Fuchsia trace format, counter values are stored in the
@@ -315,8 +314,9 @@
             if (is_valid_value) {
               StringId counter_name_id = context_->storage->InternString(
                   base::StringView(counter_name_str));
-              TrackId track = context_->track_tracker->InternThreadCounterTrack(
-                  counter_name_id, utid);
+              TrackId track =
+                  context_->track_tracker->InternProcessCounterTrack(
+                      counter_name_id, upid);
               context_->event_tracker->PushCounter(ts, counter_value, track);
             }
           }
diff --git a/test/trace_processor/fuchsia/fuchsia_smoke_type.out b/test/trace_processor/fuchsia/fuchsia_smoke_type.out
new file mode 100644
index 0000000..ba17fcf
--- /dev/null
+++ b/test/trace_processor/fuchsia/fuchsia_smoke_type.out
@@ -0,0 +1,11 @@
+"id","name","type"
+0,"[NULL]","thread_track"
+1,"[NULL]","thread_track"
+2,"[NULL]","thread_track"
+3,"[NULL]","thread_track"
+4,"[NULL]","thread_track"
+5,"cpu_usage:average_cpu_percentage","process_counter_track"
+6,"[NULL]","thread_track"
+7,"[NULL]","thread_track"
+8,"[NULL]","thread_track"
+9,"[NULL]","thread_track"
diff --git a/test/trace_processor/fuchsia/index b/test/trace_processor/fuchsia/index
index bb89b30..05e4051 100644
--- a/test/trace_processor/fuchsia/index
+++ b/test/trace_processor/fuchsia/index
@@ -6,6 +6,7 @@
 ../../data/fuchsia_trace.fxt smoke_instants.sql fuchsia_smoke_instants.out
 ../../data/fuchsia_trace.fxt smoke_counters.sql fuchsia_smoke_counters.out
 ../../data/fuchsia_trace.fxt smoke_flow.sql fuchsia_smoke_flow.out
+../../data/fuchsia_trace.fxt smoke_type.sql fuchsia_smoke_type.out
 
 # Smoke test a high-CPU trace.
 ../../data/fuchsia_workstation.fxt ../common/smoke_slices.sql fuchsia_workstation_smoke_slices.out
diff --git a/test/trace_processor/fuchsia/smoke_type.sql b/test/trace_processor/fuchsia/smoke_type.sql
new file mode 100644
index 0000000..4a29c12
--- /dev/null
+++ b/test/trace_processor/fuchsia/smoke_type.sql
@@ -0,0 +1,21 @@
+--
+-- Copyright 2022 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
+--
+--     https://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.
+--
+select
+  id,
+  name,
+  type
+from track
+limit 10;