2828
2929namespace lldb_private {
3030
31+ using llvm::telemetry::Destination;
3132using llvm::telemetry::KindType;
33+ using llvm::telemetry::Serializer;
34+ using llvm::telemetry::TelemetryInfo;
3235
3336struct LldbEntryKind : public ::llvm::telemetry::EntryKind {
3437 static const KindType BaseInfo = 0b11000 ;
@@ -39,21 +42,44 @@ struct LldbEntryKind : public ::llvm::telemetry::EntryKind {
3942 static const KindType MiscInfo = 0b11110 ;
4043};
4144
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+
4372 // For dyn_cast, isa, etc operations.
4473 KindType getKind () const override { return LldbEntryKind::BaseInfo; }
4574
46- static bool classof (const TelemetryInfo *T ) {
47- if (T == nullptr )
75+ static bool classof (const TelemetryInfo *t ) {
76+ if (t == nullptr )
4877 return false ;
4978 // Subclasses of this is also acceptable.
50- return (T ->getKind () & LldbEntryKind::BaseInfo) == LldbEntryKind::BaseInfo;
79+ return (t ->getKind () & LldbEntryKind::BaseInfo) == LldbEntryKind::BaseInfo;
5180 }
5281
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 ;
5783};
5884
5985struct DebuggerTelemetryInfo : public LldbBaseTelemetryInfo {
@@ -62,6 +88,7 @@ struct DebuggerTelemetryInfo : public LldbBaseTelemetryInfo {
6288 std::string lldb_path;
6389 std::string cwd;
6490
91+ std::optional<ExitDescription> exit_desc;
6592 DebuggerTelemetryInfo () = default ;
6693
6794 // Provide a copy ctor because we may need to make a copy before
@@ -82,26 +109,30 @@ struct DebuggerTelemetryInfo : public LldbBaseTelemetryInfo {
82109 return T->getKind () == LldbEntryKind::DebuggerInfo;
83110 }
84111
85- llvm::json::Object serializeToJson () const override ;
86-
87- std::string ToString () const override ;
112+ void serialize (Serializer &serializer) const override ;
88113};
89114
90115struct TargetTelemetryInfo : public LldbBaseTelemetryInfo {
116+ lldb::ModuleSP exec_mod;
117+ Target *target_ptr;
118+
91119 // The same as the executable-module's UUID.
92120 std::string target_uuid;
93121 std::string file_format;
94122
95123 std::string binary_path;
96124 size_t binary_size;
97125
126+ std::optional<ExitDescription> exit_desc;
98127 TargetTelemetryInfo () = default ;
99128
100129 TargetTelemetryInfo (const TargetTelemetryInfo &other) {
130+ exec_mod = other.exec_mod ;
101131 target_uuid = other.target_uuid ;
102132 file_format = other.file_format ;
103133 binary_path = other.binary_path ;
104134 binary_size = other.binary_size ;
135+ exit_desc = other.exit_desc ;
105136 }
106137
107138 KindType getKind () const override { return LldbEntryKind::TargetInfo; }
@@ -112,9 +143,7 @@ struct TargetTelemetryInfo : public LldbBaseTelemetryInfo {
112143 return T->getKind () == LldbEntryKind::TargetInfo;
113144 }
114145
115- llvm::json::Object serializeToJson () const override ;
116-
117- std::string ToString () const override ;
146+ void serialize (Serializer &serializer) const override ;
118147};
119148
120149// Entry from client (eg., SB-API)
@@ -137,22 +166,13 @@ struct ClientTelemetryInfo : public LldbBaseTelemetryInfo {
137166 return T->getKind () == LldbEntryKind::ClientInfo;
138167 }
139168
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 ;
153170};
154171
155172struct CommandTelemetryInfo : public LldbBaseTelemetryInfo {
173+ Target *target_ptr;
174+ CommandReturnObject *result;
175+
156176 // If the command is/can be associated with a target entry,
157177 // this field contains that target's UUID.
158178 // <EMPTY> otherwise.
@@ -167,6 +187,7 @@ struct CommandTelemetryInfo : public LldbBaseTelemetryInfo {
167187 std::string original_command;
168188 std::string args;
169189
190+ std::optional<ExitDescription> exit_desc;
170191 lldb::ReturnStatus ret_status;
171192
172193 CommandTelemetryInfo () = default ;
@@ -177,6 +198,8 @@ struct CommandTelemetryInfo : public LldbBaseTelemetryInfo {
177198 command_name = other.command_name ;
178199 original_command = other.original_command ;
179200 args = other.args ;
201+ exit_desc = other.exit_desc ;
202+ ret_status = other.ret_status ;
180203 }
181204
182205 KindType getKind () const override { return LldbEntryKind::CommandInfo; }
@@ -187,9 +210,7 @@ struct CommandTelemetryInfo : public LldbBaseTelemetryInfo {
187210 return T->getKind () == LldbEntryKind::CommandInfo;
188211 }
189212
190- llvm::json::Object serializeToJson () const override ;
191-
192- std::string ToString () const override ;
213+ void serialize (Serializer &serializer) const override ;
193214};
194215
195216// / The "catch-all" entry to store a set of custom/non-standard
@@ -201,7 +222,7 @@ struct MiscTelemetryInfo : public LldbBaseTelemetryInfo {
201222 std::string target_uuid;
202223
203224 // / 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;
205226
206227 MiscTelemetryInfo () = default ;
207228
@@ -218,15 +239,13 @@ struct MiscTelemetryInfo : public LldbBaseTelemetryInfo {
218239 return T->getKind () == LldbEntryKind::MiscInfo;
219240 }
220241
221- llvm::json::Object serializeToJson () const override ;
222-
223- std::string ToString () const override ;
242+ void serialize (Serializer &serializer) const override ;
224243};
225244
226- // / The base Telemeter instance in LLDB.
245+ // / The base Telemetry manager instance in LLDB
227246// / This class declares additional instrumentation points
228247// / applicable to LLDB.
229- class LldbTelemeter : public llvm ::telemetry::Telemeter {
248+ class LldbTelemeter : public llvm ::telemetry::Manager {
230249public:
231250 // / Creates an instance of LldbTelemeter.
232251 // / This uses the plugin registry to find an instance:
@@ -239,65 +258,40 @@ class LldbTelemeter : public llvm::telemetry::Telemeter {
239258
240259 virtual ~LldbTelemeter () = default ;
241260
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;
246266
247- // / Invoked upon loading the main executable module
267+ // / To be invoked upon loading the main executable module.
248268 // / We log in a fire-n-forget fashion so that if the load
249269 // / 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) ;
255275
256276 // / Invoked for each command
257277 // / We log in a fire-n-forget fashion so that if the command execution
258278 // / 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;
268281
269282 virtual std::string GetNextUUID () = 0;
270283
271284 // / For client (eg., SB API) to send telemetry entries.
272285 virtual void
273286 LogClientTelemetry (const lldb_private::StructuredDataImpl &entry) = 0 ;
287+
288+ private:
289+ const std::string SessionId;
290+ std::vector<std::unique_ptr<Destination>> destinations;
274291};
275292
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.
301295llvm::telemetry::Config *GetTelemetryConfig ();
302296
303297} // namespace lldb_private
0 commit comments