Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2018 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/trace_storage.h" |
| 18 | |
| 19 | #include <string.h> |
| 20 | |
| 21 | namespace perfetto { |
| 22 | namespace trace_processor { |
| 23 | |
| 24 | void TraceStorage::AddSliceForCpu(uint32_t cpu, |
| 25 | uint64_t start_timestamp, |
| 26 | uint64_t duration, |
| 27 | const char* thread_name) { |
| 28 | if (cpu_events_.size() <= cpu) |
| 29 | cpu_events_.resize(cpu + 1); |
| 30 | |
| 31 | SlicesPerCpu* slices = &cpu_events_[cpu]; |
| 32 | slices->cpu_ = cpu; |
| 33 | slices->start_timestamps.emplace_back(start_timestamp); |
| 34 | slices->durations.emplace_back(duration); |
| 35 | |
| 36 | uint32_t hash = 0; |
| 37 | for (size_t i = 0; i < strlen(thread_name); ++i) { |
| 38 | hash = static_cast<uint32_t>(thread_name[i]) + (hash * 31); |
| 39 | } |
| 40 | auto id_it = string_pool_.find(hash); |
| 41 | if (id_it == string_pool_.end()) { |
| 42 | strings_.emplace_back(thread_name); |
| 43 | string_pool_.emplace(hash, strings_.size() - 1); |
| 44 | slices->thread_names.emplace_back(strings_.size() - 1); |
| 45 | } else { |
| 46 | slices->thread_names.emplace_back(id_it->second); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | } // namespace trace_processor |
| 51 | } // namespace perfetto |