blob: db3f04afaa80480009e38b41c7a5083d2fc32765 [file] [log] [blame]
Yabin Cui4f41df62016-06-01 17:29:06 -07001/*
2 * Copyright (C) 2016 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 SIMPLE_PERF_TRACING_H_
18#define SIMPLE_PERF_TRACING_H_
19
20#include <vector>
21
22#include <android-base/logging.h>
23
24#include "event_type.h"
Yabin Cui6965d422016-06-15 11:41:42 -070025#include "utils.h"
Yabin Cui4f41df62016-06-01 17:29:06 -070026
27struct TracingField {
28 std::string name;
29 size_t offset;
30 size_t elem_size;
31 size_t elem_count;
32 bool is_signed;
33};
34
Yabin Cui6965d422016-06-15 11:41:42 -070035struct TracingFieldPlace {
36 uint32_t offset;
37 uint32_t size;
38
39 uint64_t ReadFromData(const char* raw_data) {
40 return ConvertBytesToValue(raw_data + offset, size);
41 }
42};
43
Yabin Cuibbaa5122018-03-19 13:58:51 -070044struct StringTracingFieldPlace {
45 uint32_t offset;
46 uint32_t size;
47
48 std::string ReadFromData(const char* raw_data) {
49 char s[size + 1];
50 s[size] = '\0';
51 memcpy(s, raw_data + offset, size);
52 return s;
53 }
54};
55
Yabin Cui4f41df62016-06-01 17:29:06 -070056struct TracingFormat {
57 std::string system_name;
58 std::string name;
59 uint64_t id;
60 std::vector<TracingField> fields;
61
Yabin Cui6965d422016-06-15 11:41:42 -070062 void GetField(const std::string& name, TracingFieldPlace& place) {
Yabin Cui4f41df62016-06-01 17:29:06 -070063 const TracingField& field = GetField(name);
Yabin Cui6965d422016-06-15 11:41:42 -070064 place.offset = field.offset;
65 place.size = field.elem_size;
Yabin Cui4f41df62016-06-01 17:29:06 -070066 }
67
Yabin Cuibbaa5122018-03-19 13:58:51 -070068 void GetField(const std::string& name, StringTracingFieldPlace& place) {
69 const TracingField& field = GetField(name);
70 place.offset = field.offset;
71 place.size = field.elem_count;
72 }
73
Yabin Cui4f41df62016-06-01 17:29:06 -070074 private:
75 const TracingField& GetField(const std::string& name) {
76 for (const auto& field : fields) {
77 if (field.name == name) {
78 return field;
79 }
80 }
81 LOG(FATAL) << "Couldn't find field " << name << "in TracingFormat of "
82 << this->name;
83 return fields[0];
84 }
85};
86
87class TracingFile;
88
89class Tracing {
90 public:
Chih-Hung Hsieh5674ed82016-07-12 11:35:16 -070091 explicit Tracing(const std::vector<char>& data);
Yabin Cui4f41df62016-06-01 17:29:06 -070092 ~Tracing();
93 void Dump(size_t indent);
94 TracingFormat GetTracingFormatHavingId(uint64_t trace_event_id);
95 std::string GetTracingEventNameHavingId(uint64_t trace_event_id);
96 const std::string& GetKallsyms() const;
97 uint32_t GetPageSize() const;
98
99 private:
100 TracingFile* tracing_file_;
101 std::vector<TracingFormat> tracing_formats_;
102};
103
Yabin Cui877751b2016-06-13 18:03:47 -0700104bool GetTracingData(const std::vector<const EventType*>& event_types,
Yabin Cui4f41df62016-06-01 17:29:06 -0700105 std::vector<char>* data);
106
107#endif // SIMPLE_PERF_TRACING_H_