• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 INCLUDE_PERFETTO_TRACE_PROCESSOR_BASIC_TYPES_H_
18 #define INCLUDE_PERFETTO_TRACE_PROCESSOR_BASIC_TYPES_H_
19 
20 #include <assert.h>
21 #include <math.h>
22 #include <stdarg.h>
23 #include <stdint.h>
24 #include <functional>
25 #include <string>
26 
27 #include "perfetto/base/export.h"
28 #include "perfetto/base/logging.h"
29 
30 namespace perfetto {
31 namespace trace_processor {
32 
33 // Various places in trace processor assume a max number of CPUs to keep code
34 // simpler (e.g. use arrays instead of vectors).
35 constexpr size_t kMaxCpus = 128;
36 
37 // Struct for configuring a TraceProcessor instance (see trace_processor.h).
38 struct PERFETTO_EXPORT Config {
39   // When set to true, this option forces trace processor to perform a full
40   // sort ignoring any internal heureustics to skip sorting parts of the data.
41   bool force_full_sort = false;
42 
43   // When set to false, this option makes the trace processor not include ftrace
44   // events in the raw table; this makes converting events back to the systrace
45   // text format impossible. On the other hand, it also saves ~50% of memory
46   // usage of trace processor. For reference, Studio intends to use this option.
47   //
48   // Note: "generic" ftrace events will be parsed into the raw table even if
49   // this flag is false and all other events which parse into the raw table are
50   // unaffected by this flag.
51   bool ingest_ftrace_in_raw_table = true;
52 };
53 
54 // Represents a dynamically typed value returned by SQL.
55 struct PERFETTO_EXPORT SqlValue {
56   // Represents the type of the value.
57   enum Type {
58     kNull = 0,
59     kLong,
60     kDouble,
61     kString,
62     kBytes,
63   };
64 
65   SqlValue() = default;
66 
LongSqlValue67   static SqlValue Long(int64_t v) {
68     SqlValue value;
69     value.long_value = v;
70     value.type = Type::kLong;
71     return value;
72   }
73 
DoubleSqlValue74   static SqlValue Double(double v) {
75     SqlValue value;
76     value.double_value = v;
77     value.type = Type::kDouble;
78     return value;
79   }
80 
StringSqlValue81   static SqlValue String(const char* v) {
82     SqlValue value;
83     value.string_value = v;
84     value.type = Type::kString;
85     return value;
86   }
87 
AsDoubleSqlValue88   double AsDouble() const {
89     PERFETTO_CHECK(type == kDouble);
90     return double_value;
91   }
AsLongSqlValue92   int64_t AsLong() const {
93     PERFETTO_CHECK(type == kLong);
94     return long_value;
95   }
AsStringSqlValue96   const char* AsString() const {
97     PERFETTO_CHECK(type == kString);
98     return string_value;
99   }
AsBytesSqlValue100   const void* AsBytes() const {
101     PERFETTO_CHECK(type == kBytes);
102     return bytes_value;
103   }
104 
is_nullSqlValue105   bool is_null() const { return type == Type::kNull; }
106 
107   // Up to 1 of these fields can be accessed depending on |type|.
108   union {
109     // This string will be owned by the iterator that returned it and is valid
110     // as long until the subsequent call to Next().
111     const char* string_value;
112     int64_t long_value;
113     double double_value;
114     const void* bytes_value;
115   };
116   // The size of bytes_value. Only valid when |type == kBytes|.
117   size_t bytes_count = 0;
118   Type type = kNull;
119 };
120 
121 }  // namespace trace_processor
122 }  // namespace perfetto
123 
124 #endif  // INCLUDE_PERFETTO_TRACE_PROCESSOR_BASIC_TYPES_H_
125