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 | |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 24 | TraceStorage::TraceStorage() { |
Lalit Maganti | 1f64cfa | 2018-09-18 13:20:02 +0100 | [diff] [blame^] | 25 | // Upid/utid 0 is reserved for idle processes/threads. |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 26 | unique_processes_.emplace_back(0); |
| 27 | unique_threads_.emplace_back(0); |
| 28 | |
| 29 | // Reserve string ID 0 for the empty string. |
Primiano Tucci | 2da5d2e | 2018-08-10 14:23:31 +0100 | [diff] [blame] | 30 | InternString(""); |
Primiano Tucci | 463af6f | 2018-09-09 15:10:42 +0100 | [diff] [blame] | 31 | |
| 32 | // Initialize all CPUs @ freq 0Hz. |
| 33 | for (size_t cpu = 0; cpu < base::kMaxCpus; cpu++) |
| 34 | cpu_freq_[cpu].emplace_back(0, 0); |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 37 | TraceStorage::~TraceStorage() {} |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 38 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 39 | void TraceStorage::AddSliceToCpu(uint32_t cpu, |
| 40 | uint64_t start_ns, |
| 41 | uint64_t duration_ns, |
Isabelle Taylor | 14674d4 | 2018-09-07 11:33:11 +0100 | [diff] [blame] | 42 | UniqueTid utid, |
| 43 | uint64_t cycles) { |
Lalit Maganti | 9dacc85 | 2018-09-18 13:28:32 +0100 | [diff] [blame] | 44 | slices_.AddSlice(cpu, start_ns, duration_ns, utid, cycles); |
| 45 | } |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 46 | |
Primiano Tucci | 2da5d2e | 2018-08-10 14:23:31 +0100 | [diff] [blame] | 47 | StringId TraceStorage::InternString(base::StringView str) { |
| 48 | auto hash = str.Hash(); |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 49 | auto id_it = string_index_.find(hash); |
| 50 | if (id_it != string_index_.end()) { |
Primiano Tucci | 2da5d2e | 2018-08-10 14:23:31 +0100 | [diff] [blame] | 51 | PERFETTO_DCHECK(base::StringView(string_pool_[id_it->second]) == str); |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 52 | return id_it->second; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 53 | } |
Primiano Tucci | 2da5d2e | 2018-08-10 14:23:31 +0100 | [diff] [blame] | 54 | string_pool_.emplace_back(str.ToStdString()); |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 55 | StringId string_id = string_pool_.size() - 1; |
| 56 | string_index_.emplace(hash, string_id); |
| 57 | return string_id; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 60 | void TraceStorage::ResetStorage() { |
| 61 | *this = TraceStorage(); |
| 62 | } |
| 63 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 64 | } // namespace trace_processor |
| 65 | } // namespace perfetto |