• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 9 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/counter_values_table.h"
18 
19 namespace perfetto {
20 namespace trace_processor {
21 
CounterValuesTable(sqlite3 *,const TraceStorage * storage)22 CounterValuesTable::CounterValuesTable(sqlite3*, const TraceStorage* storage)
23     : storage_(storage) {}
24 
RegisterTable(sqlite3 * db,const TraceStorage * storage)25 void CounterValuesTable::RegisterTable(sqlite3* db,
26                                        const TraceStorage* storage) {
27   Table::Register<CounterValuesTable>(db, storage, "counter_values");
28 }
29 
CreateStorageSchema()30 StorageSchema CounterValuesTable::CreateStorageSchema() {
31   const auto& cs = storage_->counter_values();
32   return StorageSchema::Builder()
33       .AddGenericNumericColumn("id", RowIdAccessor(TableId::kCounterValues))
34       .AddNumericColumn("counter_id", &cs.counter_ids(),
35                         &cs.rows_for_counter_id())
36       .AddOrderedNumericColumn("ts", &cs.timestamps())
37       .AddNumericColumn("value", &cs.values())
38       .AddNumericColumn("arg_set_id", &cs.arg_set_ids())
39       .Build({"id"});
40 }
41 
RowCount()42 uint32_t CounterValuesTable::RowCount() {
43   return storage_->counter_values().size();
44 }
45 
BestIndex(const QueryConstraints & qc,BestIndexInfo * info)46 int CounterValuesTable::BestIndex(const QueryConstraints& qc,
47                                   BestIndexInfo* info) {
48   info->estimated_cost = EstimateCost(qc);
49 
50   info->order_by_consumed = true;
51   for (size_t i = 0; i < qc.constraints().size(); i++) {
52     info->omit[i] = true;
53   }
54 
55   return SQLITE_OK;
56 }
57 
EstimateCost(const QueryConstraints & qc)58 uint32_t CounterValuesTable::EstimateCost(const QueryConstraints& qc) {
59   if (HasEqConstraint(qc, "counter_id"))
60     return RowCount() / 100;
61   return RowCount();
62 }
63 
64 }  // namespace trace_processor
65 }  // namespace perfetto
66