1 /* 2 * Copyright (C) 2024 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 */ 16 17 #include "src/trace_processor/importers/common/cpu_tracker.h" 18 19 #include "perfetto/base/logging.h" 20 #include "perfetto/public/compiler.h" 21 22 #include "src/trace_processor/importers/common/machine_tracker.h" 23 24 namespace perfetto::trace_processor { 25 CpuTracker(TraceProcessorContext * context)26CpuTracker::CpuTracker(TraceProcessorContext* context) : context_(context) { 27 // Preallocate ucpu of this machine for maintaining the relative order between 28 // ucpu and cpu. 29 auto machine_id = context_->machine_tracker->machine_id(); 30 if (machine_id.has_value()) 31 ucpu_offset_ = machine_id->value * kMaxCpusPerMachine; 32 33 for (auto id = 0u; id < kMaxCpusPerMachine; id++) { 34 // Only populate the |machine_id| column. The |cpu| column is update only 35 // when the CPU is present. 36 tables::CpuTable::Row cpu_row; 37 cpu_row.machine_id = machine_id; 38 context_->storage->mutable_cpu_table()->Insert(cpu_row); 39 } 40 } 41 42 CpuTracker::~CpuTracker() = default; 43 SetCpuInfo(uint32_t cpu,base::StringView processor,uint32_t cluster_id)44tables::CpuTable::Id CpuTracker::SetCpuInfo(uint32_t cpu, 45 base::StringView processor, 46 uint32_t cluster_id) { 47 auto cpu_id = GetOrCreateCpu(cpu); 48 49 auto cpu_row = context_->storage->mutable_cpu_table()->FindById(cpu_id); 50 PERFETTO_DCHECK(cpu_row.has_value()); 51 52 if (!processor.empty()) { 53 auto string_id = context_->storage->InternString(processor); 54 cpu_row->set_processor(string_id); 55 } 56 cpu_row->set_cluster_id(cluster_id); 57 58 return cpu_id; 59 } 60 61 } // namespace perfetto::trace_processor 62