blob: 6539e9a62bc45d2cb0c856b482a01543f662af94 [file] [log] [blame]
Primiano Tucci4e01f632020-06-11 17:03:05 +01001/*
2 * Copyright (C) 2020 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/iterator_impl.h"
18
19#include "perfetto/base/time.h"
20#include "perfetto/trace_processor/trace_processor_storage.h"
21#include "src/trace_processor/storage/trace_storage.h"
22#include "src/trace_processor/trace_processor_impl.h"
23
24namespace perfetto {
25namespace trace_processor {
26
27IteratorImpl::IteratorImpl(TraceProcessorImpl* trace_processor,
28 sqlite3* db,
29 ScopedStmt stmt,
30 uint32_t column_count,
31 util::Status status,
32 uint32_t sql_stats_row)
33 : trace_processor_(trace_processor),
34 db_(db),
35 stmt_(std::move(stmt)),
36 column_count_(column_count),
37 status_(status),
38 sql_stats_row_(sql_stats_row) {}
39
40IteratorImpl::~IteratorImpl() {
41 if (trace_processor_) {
Primiano Tucci4e01f632020-06-11 17:03:05 +010042 base::TimeNanos t_end = base::GetWallTimeNs();
Lalit Magantib834f8c2020-06-17 11:43:17 +010043 auto* sql_stats =
44 trace_processor_.get()->context_.storage->mutable_sql_stats();
Primiano Tucci4e01f632020-06-11 17:03:05 +010045 sql_stats->RecordQueryEnd(sql_stats_row_, t_end.count());
46 }
47}
48
Primiano Tucci4e01f632020-06-11 17:03:05 +010049void IteratorImpl::RecordFirstNextInSqlStats() {
50 base::TimeNanos t_first_next = base::GetWallTimeNs();
Lalit Magantib834f8c2020-06-17 11:43:17 +010051 auto* sql_stats =
52 trace_processor_.get()->context_.storage->mutable_sql_stats();
Primiano Tucci4e01f632020-06-11 17:03:05 +010053 sql_stats->RecordQueryFirstNext(sql_stats_row_, t_first_next.count());
54}
55
56Iterator::Iterator(std::unique_ptr<IteratorImpl> iterator)
57 : iterator_(std::move(iterator)) {}
58Iterator::~Iterator() = default;
59
60Iterator::Iterator(Iterator&&) noexcept = default;
61Iterator& Iterator::operator=(Iterator&&) = default;
62
63bool Iterator::Next() {
64 return iterator_->Next();
65}
66
67SqlValue Iterator::Get(uint32_t col) {
68 return iterator_->Get(col);
69}
70
71std::string Iterator::GetColumnName(uint32_t col) {
72 return iterator_->GetColumnName(col);
73}
74
75uint32_t Iterator::ColumnCount() {
76 return iterator_->ColumnCount();
77}
78
79util::Status Iterator::Status() {
80 return iterator_->Status();
81}
82
83} // namespace trace_processor
84} // namespace perfetto