xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTJSONStructs.cpp (revision 716fd348e01c5f2ba125f878a634a753436c2994)
1 //===-- TraceIntelPTJSONStructs.cpp ---------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "TraceIntelPTJSONStructs.h"
10 
11 #include "llvm/Support/JSON.h"
12 #include <string>
13 
14 using namespace lldb;
15 using namespace lldb_private;
16 using namespace lldb_private::trace_intel_pt;
17 using namespace llvm;
18 
19 namespace llvm {
20 namespace json {
21 
22 bool fromJSON(const Value &value, JSONTraceIntelPTSettings &plugin_settings,
23               Path path) {
24   ObjectMapper o(value, path);
25   return o && o.map("cpuInfo", plugin_settings.cpuInfo) &&
26          fromJSON(value, (JSONTracePluginSettings &)plugin_settings, path);
27 }
28 
29 bool fromJSON(const json::Value &value, JSONTraceIntelPTCPUInfo &cpu_info,
30               Path path) {
31   ObjectMapper o(value, path);
32   return o && o.map("vendor", cpu_info.vendor) &&
33          o.map("family", cpu_info.family) && o.map("model", cpu_info.model) &&
34          o.map("stepping", cpu_info.stepping);
35 }
36 
37 Value toJSON(const JSONTraceIntelPTCPUInfo &cpu_info) {
38   return Value(Object{{"family", cpu_info.family},
39                       {"model", cpu_info.model},
40                       {"stepping", cpu_info.stepping},
41                       {"vendor", cpu_info.vendor}});
42 }
43 
44 llvm::json::Value toJSON(const JSONTraceIntelPTTrace &trace) {
45   llvm::json::Object json_trace;
46   json_trace["type"] = trace.type;
47   json_trace["cpuInfo"] = toJSON(trace.cpuInfo);
48   return std::move(json_trace);
49 }
50 
51 llvm::json::Value toJSON(const JSONTraceIntelPTSession &session) {
52   llvm::json::Object json_session;
53   json_session["trace"] = toJSON(session.ipt_trace);
54   json_session["processes"] = toJSON(session.session_base);
55   return std::move(json_session);
56 }
57 
58 } // namespace json
59 } // namespace llvm
60