28
28
29
29
namespace lldb_private {
30
30
31
+ using llvm::telemetry::Destination;
31
32
using llvm::telemetry::KindType;
33
+ using llvm::telemetry::Serializer;
34
+ using llvm::telemetry::TelemetryInfo;
32
35
33
36
struct LldbEntryKind : public ::llvm::telemetry::EntryKind {
34
37
static const KindType BaseInfo = 0b11000 ;
@@ -39,21 +42,44 @@ struct LldbEntryKind : public ::llvm::telemetry::EntryKind {
39
42
static const KindType MiscInfo = 0b11110 ;
40
43
};
41
44
42
- struct LldbBaseTelemetryInfo : public ::llvm::telemetry::TelemetryInfo {
45
+ // / Defines a convenient type for timestamp of various events.
46
+ // / This is used by the EventStats below.
47
+ using SteadyTimePoint = std::chrono::time_point<std::chrono::steady_clock>;
48
+
49
+ // / Various time (and possibly memory) statistics of an event.
50
+ struct EventStats {
51
+ // REQUIRED: Start time of an event
52
+ SteadyTimePoint start;
53
+ // OPTIONAL: End time of an event - may be empty if not meaningful.
54
+ std::optional<SteadyTimePoint> end;
55
+ // TBD: could add some memory stats here too?
56
+
57
+ EventStats () = default ;
58
+ EventStats (SteadyTimePoint start) : start(start) {}
59
+ EventStats (SteadyTimePoint start, SteadyTimePoint end)
60
+ : start(start), end(end) {}
61
+ };
62
+
63
+ // / Describes the exit signal of an event.
64
+ struct ExitDescription {
65
+ int exit_code;
66
+ std::string description;
67
+ };
68
+
69
+ struct LldbBaseTelemetryInfo : public TelemetryInfo {
70
+ EventStats stats;
71
+
43
72
// For dyn_cast, isa, etc operations.
44
73
KindType getKind () const override { return LldbEntryKind::BaseInfo; }
45
74
46
- static bool classof (const TelemetryInfo *T ) {
47
- if (T == nullptr )
75
+ static bool classof (const TelemetryInfo *t ) {
76
+ if (t == nullptr )
48
77
return false ;
49
78
// Subclasses of this is also acceptable.
50
- return (T ->getKind () & LldbEntryKind::BaseInfo) == LldbEntryKind::BaseInfo;
79
+ return (t ->getKind () & LldbEntryKind::BaseInfo) == LldbEntryKind::BaseInfo;
51
80
}
52
81
53
- // Returns a human-readable string description of the struct.
54
- // This is for debugging purposes only.
55
- // It is NOT meant as a data-serialisation method.
56
- virtual std::string ToString () const ;
82
+ void serialize (Serializer &serializer) const override ;
57
83
};
58
84
59
85
struct DebuggerTelemetryInfo : public LldbBaseTelemetryInfo {
@@ -62,6 +88,7 @@ struct DebuggerTelemetryInfo : public LldbBaseTelemetryInfo {
62
88
std::string lldb_path;
63
89
std::string cwd;
64
90
91
+ std::optional<ExitDescription> exit_desc;
65
92
DebuggerTelemetryInfo () = default ;
66
93
67
94
// Provide a copy ctor because we may need to make a copy before
@@ -82,26 +109,30 @@ struct DebuggerTelemetryInfo : public LldbBaseTelemetryInfo {
82
109
return T->getKind () == LldbEntryKind::DebuggerInfo;
83
110
}
84
111
85
- llvm::json::Object serializeToJson () const override ;
86
-
87
- std::string ToString () const override ;
112
+ void serialize (Serializer &serializer) const override ;
88
113
};
89
114
90
115
struct TargetTelemetryInfo : public LldbBaseTelemetryInfo {
116
+ lldb::ModuleSP exec_mod;
117
+ Target *target_ptr;
118
+
91
119
// The same as the executable-module's UUID.
92
120
std::string target_uuid;
93
121
std::string file_format;
94
122
95
123
std::string binary_path;
96
124
size_t binary_size;
97
125
126
+ std::optional<ExitDescription> exit_desc;
98
127
TargetTelemetryInfo () = default ;
99
128
100
129
TargetTelemetryInfo (const TargetTelemetryInfo &other) {
130
+ exec_mod = other.exec_mod ;
101
131
target_uuid = other.target_uuid ;
102
132
file_format = other.file_format ;
103
133
binary_path = other.binary_path ;
104
134
binary_size = other.binary_size ;
135
+ exit_desc = other.exit_desc ;
105
136
}
106
137
107
138
KindType getKind () const override { return LldbEntryKind::TargetInfo; }
@@ -112,9 +143,7 @@ struct TargetTelemetryInfo : public LldbBaseTelemetryInfo {
112
143
return T->getKind () == LldbEntryKind::TargetInfo;
113
144
}
114
145
115
- llvm::json::Object serializeToJson () const override ;
116
-
117
- std::string ToString () const override ;
146
+ void serialize (Serializer &serializer) const override ;
118
147
};
119
148
120
149
// Entry from client (eg., SB-API)
@@ -137,22 +166,13 @@ struct ClientTelemetryInfo : public LldbBaseTelemetryInfo {
137
166
return T->getKind () == LldbEntryKind::ClientInfo;
138
167
}
139
168
140
- llvm::json::Object serializeToJson () const override ;
141
-
142
- std::string ToString () const override ;
143
- };
144
-
145
- struct CommandExitDescription : public ::llvm::telemetry::ExitDescription {
146
- lldb::ReturnStatus ret_status;
147
- CommandExitDescription (int ret_code, std::string ret_desc,
148
- lldb::ReturnStatus status) {
149
- ExitCode = ret_code;
150
- Description = std::move (ret_desc);
151
- ret_status = status;
152
- }
169
+ void serialize (Serializer &serializer) const override ;
153
170
};
154
171
155
172
struct CommandTelemetryInfo : public LldbBaseTelemetryInfo {
173
+ Target *target_ptr;
174
+ CommandReturnObject *result;
175
+
156
176
// If the command is/can be associated with a target entry,
157
177
// this field contains that target's UUID.
158
178
// <EMPTY> otherwise.
@@ -167,6 +187,7 @@ struct CommandTelemetryInfo : public LldbBaseTelemetryInfo {
167
187
std::string original_command;
168
188
std::string args;
169
189
190
+ std::optional<ExitDescription> exit_desc;
170
191
lldb::ReturnStatus ret_status;
171
192
172
193
CommandTelemetryInfo () = default ;
@@ -177,6 +198,8 @@ struct CommandTelemetryInfo : public LldbBaseTelemetryInfo {
177
198
command_name = other.command_name ;
178
199
original_command = other.original_command ;
179
200
args = other.args ;
201
+ exit_desc = other.exit_desc ;
202
+ ret_status = other.ret_status ;
180
203
}
181
204
182
205
KindType getKind () const override { return LldbEntryKind::CommandInfo; }
@@ -187,9 +210,7 @@ struct CommandTelemetryInfo : public LldbBaseTelemetryInfo {
187
210
return T->getKind () == LldbEntryKind::CommandInfo;
188
211
}
189
212
190
- llvm::json::Object serializeToJson () const override ;
191
-
192
- std::string ToString () const override ;
213
+ void serialize (Serializer &serializer) const override ;
193
214
};
194
215
195
216
// / The "catch-all" entry to store a set of custom/non-standard
@@ -201,7 +222,7 @@ struct MiscTelemetryInfo : public LldbBaseTelemetryInfo {
201
222
std::string target_uuid;
202
223
203
224
// / Set of key-value pairs for any optional (or impl-specific) data
204
- std::unordered_map <std::string, std::string> meta_data;
225
+ std::map <std::string, std::string> meta_data;
205
226
206
227
MiscTelemetryInfo () = default ;
207
228
@@ -218,15 +239,13 @@ struct MiscTelemetryInfo : public LldbBaseTelemetryInfo {
218
239
return T->getKind () == LldbEntryKind::MiscInfo;
219
240
}
220
241
221
- llvm::json::Object serializeToJson () const override ;
222
-
223
- std::string ToString () const override ;
242
+ void serialize (Serializer &serializer) const override ;
224
243
};
225
244
226
- // / The base Telemeter instance in LLDB.
245
+ // / The base Telemetry manager instance in LLDB
227
246
// / This class declares additional instrumentation points
228
247
// / applicable to LLDB.
229
- class LldbTelemeter : public llvm ::telemetry::Telemeter {
248
+ class LldbTelemeter : public llvm ::telemetry::Manager {
230
249
public:
231
250
// / Creates an instance of LldbTelemeter.
232
251
// / This uses the plugin registry to find an instance:
@@ -239,65 +258,40 @@ class LldbTelemeter : public llvm::telemetry::Telemeter {
239
258
240
259
virtual ~LldbTelemeter () = default ;
241
260
242
- // / Invoked upon process exit
243
- virtual void LogProcessExit (int status, llvm::StringRef exit_string,
244
- llvm::telemetry::EventStats stats,
245
- Target *target_ptr) = 0;
261
+ // / To be invoked upon LLDB startup.
262
+ virtual void LogStartup (DebuggerTelemetryInfo *entry) = 0;
263
+
264
+ // / To be invoked upon LLDB exit.
265
+ virtual void LogExit (DebuggerTelemetryInfo *entry) = 0;
246
266
247
- // / Invoked upon loading the main executable module
267
+ // / To be invoked upon loading the main executable module.
248
268
// / We log in a fire-n-forget fashion so that if the load
249
269
// / crashes, we don't lose the entry.
250
- virtual void
251
- LogMainExecutableLoadStart (lldb::ModuleSP exec_mod,
252
- llvm::telemetry::EventStats stats) = 0 ;
253
- virtual void LogMainExecutableLoadEnd (lldb::ModuleSP exec_mod,
254
- llvm::telemetry::EventStats stats) = 0 ;
270
+ virtual void LogMainExecutableLoadStart (TargetTelemetryInfo *entry) = 0;
271
+ virtual void LogMainExecutableLoadEnd (TargetTelemetryInfo *entry) = 0;
272
+
273
+ // / To be invoked upon process exit.
274
+ virtual void LogProcessExit (TargetTelemetryInfo *entry) ;
255
275
256
276
// / Invoked for each command
257
277
// / We log in a fire-n-forget fashion so that if the command execution
258
278
// / crashes, we don't lose the entry.
259
- virtual void LogCommandStart (llvm::StringRef uuid,
260
- llvm::StringRef original_command,
261
- llvm::telemetry::EventStats stats,
262
- Target *target_ptr) = 0;
263
- virtual void LogCommandEnd (llvm::StringRef uuid, llvm::StringRef command_name,
264
- llvm::StringRef command_args,
265
- llvm::telemetry::EventStats stats,
266
- Target *target_ptr,
267
- CommandReturnObject *result) = 0;
279
+ virtual void LogCommandStart (CommandTelemetryInfo *entry) = 0;
280
+ virtual void LogCommandEnd (CommandTelemetryInfo *entry) = 0;
268
281
269
282
virtual std::string GetNextUUID () = 0;
270
283
271
284
// / For client (eg., SB API) to send telemetry entries.
272
285
virtual void
273
286
LogClientTelemetry (const lldb_private::StructuredDataImpl &entry) = 0 ;
287
+
288
+ private:
289
+ const std::string SessionId;
290
+ std::vector<std::unique_ptr<Destination>> destinations;
274
291
};
275
292
276
- // / Logger configs: LLDB users can also supply their own configs via:
277
- // / $HOME/.lldb_telemetry_config
278
- // /
279
- // / We can propose simple syntax: <field_name><colon><value>
280
- // / Eg.,
281
- // / enable_telemetry:true
282
- // / destination:stdout
283
- // / destination:stderr
284
- // / destination:/path/to/some/file
285
- // /
286
- // / The allowed field_name values are:
287
- // / * enable_telemetry
288
- // / If the fields are specified more than once, the last line will take
289
- // / precedence If enable_logging is set to false, no logging will occur.
290
- // / * destination.
291
- // / This is allowed to be specified multiple times - it will add to the
292
- // / default (ie, specified by vendor) list of destinations.
293
- // / The value can be either:
294
- // / + one of the two magic values "stdout" or "stderr".
295
- // / + a path to a local file
296
- // / !!NOTE!!: We decided to use a separate file instead of the existing settings
297
- // / file because that file is parsed too late in the process and by the
298
- // / there might have been lots of telemetry-entries that need to be
299
- // / sent already.
300
- // / This approach avoid losing log entries if LLDB crashes during init.
293
+ // / Logger configs. This should be overriden by vendor's specific config.
294
+ // / The default (upstream) config will have telemetry disabled.
301
295
llvm::telemetry::Config *GetTelemetryConfig ();
302
296
303
297
} // namespace lldb_private
0 commit comments