-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproto_translation_table.h
More file actions
106 lines (85 loc) · 3.1 KB
/
proto_translation_table.h
File metadata and controls
106 lines (85 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SRC_FTRACE_READER_PROTO_TRANSLATION_TABLE_H_
#define SRC_FTRACE_READER_PROTO_TRANSLATION_TABLE_H_
#include <stdint.h>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "perfetto/base/scoped_file.h"
#include "src/ftrace_reader/event_info.h"
namespace perfetto {
class FtraceProcfs;
namespace protos {
namespace pbzero {
class FtraceEventBundle;
} // namespace pbzero
} // namespace protos
bool InferFtraceType(const std::string& type_and_name,
size_t size,
bool is_signed,
FtraceFieldType* out);
class ProtoTranslationTable {
public:
// This method mutates the |events| and |common_fields| vectors to
// fill some of the fields and to delete unused events/fields
// before std:move'ing them into the ProtoTranslationTable.
static std::unique_ptr<ProtoTranslationTable> Create(
const FtraceProcfs* ftrace_procfs,
std::vector<Event> events,
std::vector<Field> common_fields);
~ProtoTranslationTable();
ProtoTranslationTable(const std::vector<Event>& events,
std::vector<Field> common_fields);
size_t largest_id() const { return largest_id_; }
const std::vector<Field>& common_fields() const { return common_fields_; }
const Event* GetEventByName(const std::string& name) const {
if (!name_to_event_.count(name))
return nullptr;
return name_to_event_.at(name);
}
const std::vector<const Event*>* GetEventsByGroup(
const std::string& group) const {
if (!group_to_events_.count(group))
return nullptr;
return &group_to_events_.at(group);
}
const Event* GetEventById(size_t id) const {
if (id == 0 || id > largest_id_)
return nullptr;
if (!events_.at(id).ftrace_event_id)
return nullptr;
return &events_.at(id);
}
size_t EventNameToFtraceId(const std::string& name) const {
if (!name_to_event_.count(name))
return 0;
return name_to_event_.at(name)->ftrace_event_id;
}
const std::vector<Event>& events() { return events_; }
private:
ProtoTranslationTable(const ProtoTranslationTable&) = delete;
ProtoTranslationTable& operator=(const ProtoTranslationTable&) = delete;
const std::vector<Event> events_;
size_t largest_id_;
std::map<std::string, const Event*> name_to_event_;
std::map<std::string, std::vector<const Event*>> group_to_events_;
std::vector<Field> common_fields_;
};
} // namespace perfetto
#endif // SRC_FTRACE_READER_PROTO_TRANSLATION_TABLE_H_