Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 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" |
Lalit Maganti | 6e0c50c | 2023-06-22 18:13:58 +0100 | [diff] [blame] | 21 | #include "src/trace_processor/perfetto_sql/engine/perfetto_sql_engine.h" |
Lalit Maganti | 9546598 | 2022-01-27 22:41:15 +0000 | [diff] [blame] | 22 | #include "src/trace_processor/sqlite/scoped_db.h" |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 23 | #include "src/trace_processor/storage/trace_storage.h" |
| 24 | #include "src/trace_processor/trace_processor_impl.h" |
| 25 | |
| 26 | namespace perfetto { |
| 27 | namespace trace_processor { |
| 28 | |
Lalit Maganti | 842d361 | 2023-05-26 01:30:37 +0100 | [diff] [blame] | 29 | IteratorImpl::IteratorImpl( |
| 30 | TraceProcessorImpl* trace_processor, |
| 31 | base::StatusOr<PerfettoSqlEngine::ExecutionResult> result, |
| 32 | uint32_t sql_stats_row) |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 33 | : trace_processor_(trace_processor), |
Lalit Maganti | 842d361 | 2023-05-26 01:30:37 +0100 | [diff] [blame] | 34 | result_(std::move(result)), |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 35 | sql_stats_row_(sql_stats_row) {} |
| 36 | |
| 37 | IteratorImpl::~IteratorImpl() { |
| 38 | if (trace_processor_) { |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 39 | base::TimeNanos t_end = base::GetWallTimeNs(); |
Lalit Maganti | b834f8c | 2020-06-17 11:43:17 +0100 | [diff] [blame] | 40 | auto* sql_stats = |
| 41 | trace_processor_.get()->context_.storage->mutable_sql_stats(); |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 42 | sql_stats->RecordQueryEnd(sql_stats_row_, t_end.count()); |
| 43 | } |
| 44 | } |
| 45 | |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 46 | void IteratorImpl::RecordFirstNextInSqlStats() { |
| 47 | base::TimeNanos t_first_next = base::GetWallTimeNs(); |
Lalit Maganti | b834f8c | 2020-06-17 11:43:17 +0100 | [diff] [blame] | 48 | auto* sql_stats = |
| 49 | trace_processor_.get()->context_.storage->mutable_sql_stats(); |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 50 | sql_stats->RecordQueryFirstNext(sql_stats_row_, t_first_next.count()); |
| 51 | } |
| 52 | |
| 53 | Iterator::Iterator(std::unique_ptr<IteratorImpl> iterator) |
| 54 | : iterator_(std::move(iterator)) {} |
| 55 | Iterator::~Iterator() = default; |
| 56 | |
| 57 | Iterator::Iterator(Iterator&&) noexcept = default; |
Lalit Maganti | 9546598 | 2022-01-27 22:41:15 +0000 | [diff] [blame] | 58 | Iterator& Iterator::operator=(Iterator&&) noexcept = default; |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 59 | |
| 60 | bool Iterator::Next() { |
| 61 | return iterator_->Next(); |
| 62 | } |
| 63 | |
| 64 | SqlValue Iterator::Get(uint32_t col) { |
| 65 | return iterator_->Get(col); |
| 66 | } |
| 67 | |
| 68 | std::string Iterator::GetColumnName(uint32_t col) { |
| 69 | return iterator_->GetColumnName(col); |
| 70 | } |
| 71 | |
| 72 | uint32_t Iterator::ColumnCount() { |
| 73 | return iterator_->ColumnCount(); |
| 74 | } |
| 75 | |
Lalit Maganti | 8eb4597 | 2022-01-27 14:34:50 +0000 | [diff] [blame] | 76 | base::Status Iterator::Status() { |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 77 | return iterator_->Status(); |
| 78 | } |
| 79 | |
Lalit Maganti | 9546598 | 2022-01-27 22:41:15 +0000 | [diff] [blame] | 80 | uint32_t Iterator::StatementCount() { |
| 81 | return iterator_->StatementCount(); |
| 82 | } |
| 83 | |
| 84 | uint32_t Iterator::StatementWithOutputCount() { |
| 85 | return iterator_->StatementCountWithOutput(); |
| 86 | } |
| 87 | |
Igor Kraskevich | 5ef8e58 | 2023-06-21 14:37:01 +0000 | [diff] [blame] | 88 | std::string Iterator::LastStatementSql() { |
| 89 | return iterator_->LastStatementSql(); |
| 90 | } |
| 91 | |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 92 | } // namespace trace_processor |
| 93 | } // namespace perfetto |