1 /* 2 * Copyright (C) 2019 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/syscalls/syscall_tracker.h" 18 19 #include <cinttypes> 20 #include <type_traits> 21 #include <utility> 22 23 #include "perfetto/ext/base/string_utils.h" 24 #include "src/kernel_utils/syscall_table.h" 25 #include "src/trace_processor/storage/stats.h" 26 27 namespace perfetto { 28 namespace trace_processor { 29 30 // TODO(primiano): The current design is broken in case of 32-bit processes 31 // running on 64-bit kernel. At least on ARM, the syscal numbers don't match 32 // and we should use the kSyscalls_Aarch32 table for those processes. But this 33 // means that the architecture is not a global property but is per-process. 34 // Which in turn means that somehow we need to figure out what is the bitness 35 // of each process from the trace. SyscallTracker(TraceProcessorContext * context)36SyscallTracker::SyscallTracker(TraceProcessorContext* context) 37 : context_(context) { 38 SetArchitecture(kUnknown); 39 } 40 41 SyscallTracker::~SyscallTracker() = default; 42 SetArchitecture(Architecture arch)43void SyscallTracker::SetArchitecture(Architecture arch) { 44 SyscallTable syscalls(arch); 45 46 for (size_t i = 0; i < kMaxSyscalls; i++) { 47 StringId id = kNullStringId; 48 const char* name = syscalls.GetById(i); 49 if (name && *name) { 50 id = context_->storage->InternString(name); 51 if (!strcmp(name, "sys_write")) 52 sys_write_string_id_ = id; 53 } else { 54 base::StackString<64> unknown_str("sys_%zu", i); 55 id = context_->storage->InternString(unknown_str.string_view()); 56 } 57 arch_syscall_to_string_id_[i] = id; 58 } 59 } 60 61 } // namespace trace_processor 62 } // namespace perfetto 63