blob: e54cf3caa835084fbdfd24833264298688f8c7c8 [file] [log] [blame]
Lalit Maganticaed37e2018-06-01 03:03:08 +01001/*
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
21namespace perfetto {
22namespace trace_processor {
23
Isabelle Taylor47328cf2018-06-12 14:33:59 +010024TraceStorage::TraceStorage() {
Lalit Maganti1f64cfa2018-09-18 13:20:02 +010025 // Upid/utid 0 is reserved for idle processes/threads.
Primiano Tuccib75dcee2018-08-08 12:21:36 +010026 unique_processes_.emplace_back(0);
27 unique_threads_.emplace_back(0);
28
29 // Reserve string ID 0 for the empty string.
Primiano Tucci2da5d2e2018-08-10 14:23:31 +010030 InternString("");
Isabelle Taylor47328cf2018-06-12 14:33:59 +010031}
32
Lalit Maganti35622b72018-06-06 12:03:11 +010033TraceStorage::~TraceStorage() {}
Lalit Maganticaed37e2018-06-01 03:03:08 +010034
Primiano Tucci2da5d2e2018-08-10 14:23:31 +010035StringId TraceStorage::InternString(base::StringView str) {
36 auto hash = str.Hash();
Lalit Maganti35622b72018-06-06 12:03:11 +010037 auto id_it = string_index_.find(hash);
38 if (id_it != string_index_.end()) {
Primiano Tucci2da5d2e2018-08-10 14:23:31 +010039 PERFETTO_DCHECK(base::StringView(string_pool_[id_it->second]) == str);
Lalit Maganti35622b72018-06-06 12:03:11 +010040 return id_it->second;
Lalit Maganticaed37e2018-06-01 03:03:08 +010041 }
Primiano Tucci2da5d2e2018-08-10 14:23:31 +010042 string_pool_.emplace_back(str.ToStdString());
Lalit Maganti35622b72018-06-06 12:03:11 +010043 StringId string_id = string_pool_.size() - 1;
44 string_index_.emplace(hash, string_id);
45 return string_id;
Lalit Maganticaed37e2018-06-01 03:03:08 +010046}
47
Isabelle Taylora0a22972018-08-03 12:06:12 +010048void TraceStorage::ResetStorage() {
49 *this = TraceStorage();
50}
51
Primiano Tucci5cb84f82018-10-31 21:46:36 -070052void TraceStorage::SqlStats::RecordQueryBegin(const std::string& query,
53 uint64_t time_queued,
54 uint64_t time_started) {
55 if (queries_.size() >= kMaxLogEntries) {
56 queries_.pop_front();
57 times_queued_.pop_front();
58 times_started_.pop_front();
59 times_ended_.pop_front();
60 }
61 queries_.push_back(query);
62 times_queued_.push_back(time_queued);
63 times_started_.push_back(time_started);
64 times_ended_.push_back(0);
65}
66
67void TraceStorage::SqlStats::RecordQueryEnd(uint64_t time_ended) {
68 PERFETTO_DCHECK(!times_ended_.empty());
69 PERFETTO_DCHECK(times_ended_.back() == 0);
70 times_ended_.back() = time_ended;
71}
72
Lalit Maganticaed37e2018-06-01 03:03:08 +010073} // namespace trace_processor
74} // namespace perfetto