Home | History | Annotate | Download | only in trace_processor
      1 /*
      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 #ifndef SRC_TRACE_PROCESSOR_THREAD_TABLE_H_
     18 #define SRC_TRACE_PROCESSOR_THREAD_TABLE_H_
     19 
     20 #include <limits>
     21 #include <memory>
     22 
     23 #include "src/trace_processor/table.h"
     24 #include "src/trace_processor/trace_storage.h"
     25 
     26 namespace perfetto {
     27 namespace trace_processor {
     28 
     29 // The implementation of the SQLite table containing each unique process with
     30 // the metadata for those processes.
     31 class ThreadTable : public Table {
     32  public:
     33   enum Column { kUtid = 0, kUpid = 1, kName = 2, kTid = 3, kStartTs = 4 };
     34   class Cursor : public Table::Cursor {
     35    public:
     36     Cursor(ThreadTable* table);
     37 
     38     // Implementation of Table::Cursor.
     39     int Filter(const QueryConstraints&, sqlite3_value**) override;
     40     int Next() override;
     41     int Eof() override;
     42     int Column(sqlite3_context*, int N) override;
     43 
     44    private:
     45     Cursor(Cursor&) = delete;
     46     Cursor& operator=(const Cursor&) = delete;
     47 
     48     Cursor(Cursor&&) noexcept = default;
     49     Cursor& operator=(Cursor&&) = default;
     50 
     51     UniqueTid min;
     52     UniqueTid max;
     53     UniqueTid current;
     54     bool desc;
     55 
     56     const TraceStorage* storage_ = nullptr;
     57     ThreadTable* table_ = nullptr;
     58   };
     59 
     60   static void RegisterTable(sqlite3* db, const TraceStorage* storage);
     61 
     62   ThreadTable(sqlite3*, const TraceStorage*);
     63 
     64   // Table implementation.
     65   base::Optional<Table::Schema> Init(int, const char* const*) override;
     66   std::unique_ptr<Table::Cursor> CreateCursor() override;
     67   int BestIndex(const QueryConstraints&, BestIndexInfo*) override;
     68 
     69  private:
     70   const TraceStorage* const storage_;
     71 };
     72 }  // namespace trace_processor
     73 }  // namespace perfetto
     74 
     75 #endif  // SRC_TRACE_PROCESSOR_THREAD_TABLE_H_
     76