• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
24 namespace perfetto {
25 namespace trace_processor {
26 
IteratorImpl(TraceProcessorImpl * trace_processor,sqlite3 * db,ScopedStmt stmt,uint32_t column_count,util::Status status,uint32_t sql_stats_row)27 IteratorImpl::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 
~IteratorImpl()40 IteratorImpl::~IteratorImpl() {
41   if (trace_processor_) {
42     base::TimeNanos t_end = base::GetWallTimeNs();
43     auto* sql_stats =
44         trace_processor_.get()->context_.storage->mutable_sql_stats();
45     sql_stats->RecordQueryEnd(sql_stats_row_, t_end.count());
46   }
47 }
48 
RecordFirstNextInSqlStats()49 void IteratorImpl::RecordFirstNextInSqlStats() {
50   base::TimeNanos t_first_next = base::GetWallTimeNs();
51   auto* sql_stats =
52       trace_processor_.get()->context_.storage->mutable_sql_stats();
53   sql_stats->RecordQueryFirstNext(sql_stats_row_, t_first_next.count());
54 }
55 
Iterator(std::unique_ptr<IteratorImpl> iterator)56 Iterator::Iterator(std::unique_ptr<IteratorImpl> iterator)
57     : iterator_(std::move(iterator)) {}
58 Iterator::~Iterator() = default;
59 
60 Iterator::Iterator(Iterator&&) noexcept = default;
61 Iterator& Iterator::operator=(Iterator&&) = default;
62 
Next()63 bool Iterator::Next() {
64   return iterator_->Next();
65 }
66 
Get(uint32_t col)67 SqlValue Iterator::Get(uint32_t col) {
68   return iterator_->Get(col);
69 }
70 
GetColumnName(uint32_t col)71 std::string Iterator::GetColumnName(uint32_t col) {
72   return iterator_->GetColumnName(col);
73 }
74 
ColumnCount()75 uint32_t Iterator::ColumnCount() {
76   return iterator_->ColumnCount();
77 }
78 
Status()79 util::Status Iterator::Status() {
80   return iterator_->Status();
81 }
82 
83 }  // namespace trace_processor
84 }  // namespace perfetto
85