blob: e4c375be1e7c4f5b156294add403663de17c59ea [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 Cui4f41df62016-06-01 17:29:06 -070044struct TracingFormat {
45 std::string system_name;
46 std::string name;
47 uint64_t id;
48 std::vector<TracingField> fields;
49
Yabin Cui6965d422016-06-15 11:41:42 -070050 void GetField(const std::string& name, TracingFieldPlace& place) {
Yabin Cui4f41df62016-06-01 17:29:06 -070051 const TracingField& field = GetField(name);
Yabin Cui6965d422016-06-15 11:41:42 -070052 place.offset = field.offset;
53 place.size = field.elem_size;
Yabin Cui4f41df62016-06-01 17:29:06 -070054 }
55
56 private:
57 const TracingField& GetField(const std::string& name) {
58 for (const auto& field : fields) {
59 if (field.name == name) {
60 return field;
61 }
62 }
63 LOG(FATAL) << "Couldn't find field " << name << "in TracingFormat of "
64 << this->name;
65 return fields[0];
66 }
67};
68
69class TracingFile;
70
71class Tracing {
72 public:
Chih-Hung Hsieh5674ed82016-07-12 11:35:16 -070073 explicit Tracing(const std::vector<char>& data);
Yabin Cui4f41df62016-06-01 17:29:06 -070074 ~Tracing();
75 void Dump(size_t indent);
76 TracingFormat GetTracingFormatHavingId(uint64_t trace_event_id);
77 std::string GetTracingEventNameHavingId(uint64_t trace_event_id);
78 const std::string& GetKallsyms() const;
79 uint32_t GetPageSize() const;
80
81 private:
82 TracingFile* tracing_file_;
83 std::vector<TracingFormat> tracing_formats_;
84};
85
Yabin Cui877751b2016-06-13 18:03:47 -070086bool GetTracingData(const std::vector<const EventType*>& event_types,
Yabin Cui4f41df62016-06-01 17:29:06 -070087 std::vector<char>* data);
88
89#endif // SIMPLE_PERF_TRACING_H_