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/perf_text/perf_text_trace_parser_impl.h" 18 19 #include <cstdint> 20 21 #include "src/trace_processor/importers/common/process_tracker.h" 22 #include "src/trace_processor/importers/common/stack_profile_tracker.h" 23 #include "src/trace_processor/importers/perf_text/perf_text_event.h" 24 #include "src/trace_processor/storage/trace_storage.h" 25 #include "src/trace_processor/tables/profiler_tables_py.h" 26 #include "src/trace_processor/types/trace_processor_context.h" 27 28 namespace perfetto::trace_processor::perf_text_importer { 29 PerfTextTraceParserImpl(TraceProcessorContext * context)30PerfTextTraceParserImpl::PerfTextTraceParserImpl(TraceProcessorContext* context) 31 : context_(context) {} 32 33 PerfTextTraceParserImpl::~PerfTextTraceParserImpl() = default; 34 ParsePerfTextEvent(int64_t ts,PerfTextEvent evt)35void PerfTextTraceParserImpl::ParsePerfTextEvent(int64_t ts, 36 PerfTextEvent evt) { 37 auto* ss = context_->storage->mutable_cpu_profile_stack_sample_table(); 38 tables::CpuProfileStackSampleTable::Row row; 39 row.ts = ts; 40 row.callsite_id = evt.callsite_id; 41 row.utid = evt.pid 42 ? context_->process_tracker->UpdateThread(evt.tid, *evt.pid) 43 : context_->process_tracker->GetOrCreateThread(evt.tid); 44 if (evt.comm) { 45 context_->process_tracker->UpdateThreadNameAndMaybeProcessName( 46 evt.tid, *evt.comm, ThreadNamePriority::kOther); 47 } 48 ss->Insert(row); 49 } 50 51 } // namespace perfetto::trace_processor::perf_text_importer 52