10 #include "llvm/Support/JSON.h"
20 namespace trace_intel_pt {
22 Optional<std::vector<lldb::cpu_id_t>> JSONTraceBundleDescription::GetCpuIds() {
25 std::vector<lldb::cpu_id_t> cpu_ids;
26 for (
const JSONCpu &cpu : *cpus)
27 cpu_ids.push_back(cpu.id);
32 json::Object json_module;
35 json_module[
"file"] = *module.
file;
38 json_module[
"uuid"] = *module.
uuid;
39 return std::move(json_module);
43 ObjectMapper o(value, path);
44 return o && o.map(
"systemPath", module.
system_path) &&
45 o.map(
"file", module.
file) &&
47 o.map(
"uuid", module.
uuid);
51 json::Object obj{{
"tid", thread.
tid}};
58 ObjectMapper o(value, path);
59 return o && o.map(
"tid", thread.
tid) && o.map(
"iptTrace", thread.
ipt_trace);
65 {
"triple", process.
triple},
72 ObjectMapper o(value, path);
73 return o && o.map(
"pid", process.
pid) && o.map(
"triple", process.
triple) &&
74 o.map(
"threads", process.
threads) && o.map(
"modules", process.
modules);
86 ObjectMapper o(value, path);
88 if (!(o && o.map(
"id", cpu_id) && o.map(
"iptTrace", cpu.
ipt_trace) &&
95 json::Value
toJSON(
const pt_cpu &cpu_info) {
97 {
"vendor", cpu_info.vendor == pcv_intel ?
"GenuineIntel" :
"Unknown"},
98 {
"family", cpu_info.family},
99 {
"model", cpu_info.model},
100 {
"stepping", cpu_info.stepping},
104 bool fromJSON(
const json::Value &value, pt_cpu &cpu_info, Path path) {
105 ObjectMapper o(value, path);
107 uint64_t family, model, stepping;
108 if (!(o && o.map(
"vendor", vendor) && o.map(
"family", family) &&
109 o.map(
"model", model) && o.map(
"stepping", stepping)))
111 cpu_info.vendor = vendor ==
"GenuineIntel" ? pcv_intel : pcv_unknown;
112 cpu_info.family = family;
113 cpu_info.model = model;
114 cpu_info.stepping = stepping;
119 json::Object json_module;
122 json_module[
"file"] = kernel.
file;
123 return std::move(json_module);
127 ObjectMapper o(value, path);
128 return o && o.map(
"loadAddress", kernel.
load_address) &&
129 o.map(
"file", kernel.
file);
134 {
"type", bundle_description.
type},
135 {
"processes", bundle_description.
processes},
139 {
"cpus", bundle_description.
cpus},
141 {
"kernel", bundle_description.
kernel}};
146 ObjectMapper o(value, path);
147 if (!(o && o.map(
"processes", bundle_description.
processes) &&
148 o.map(
"type", bundle_description.
type) &&
149 o.map(
"cpus", bundle_description.
cpus) &&
150 o.map(
"tscPerfZeroConversion",
152 o.map(
"kernel", bundle_description.
kernel)))
156 "\"tscPerfZeroConversion\" is required when \"cpus\" is provided");
161 if (!
fromJSON(*value.getAsObject()->get(
"cpuInfo"),
162 bundle_description.
cpu_info, path.field(
"cpuInfo")))
168 if (bundle_description.
kernel) {
170 !bundle_description.
processes->empty()) {
171 path.report(
"\"processes\" must be empty when \"kernel\" is provided");
174 if (!bundle_description.
cpus) {
175 path.report(
"\"cpus\" is required when \"kernel\" is provided");
178 }
else if (!bundle_description.
processes) {
180 path.report(
"\"processes\" is required when \"kernel\" is not provided");