10#include "llvm/Support/JSON.h"
21namespace trace_intel_pt {
23std::optional<std::vector<lldb::cpu_id_t>>
27 std::vector<lldb::cpu_id_t> cpu_ids;
29 cpu_ids.push_back(cpu.id);
34 json::Object json_module;
37 json_module[
"file"] = *module.
file;
40 json_module[
"uuid"] = *module.
uuid;
41 return std::move(json_module);
45 ObjectMapper o(value, path);
46 return o && o.map(
"systemPath", module.
system_path) &&
47 o.map(
"file", module.
file) &&
49 o.map(
"uuid", module.
uuid);
53 json::Object obj{{
"tid", thread.
tid}};
60 ObjectMapper o(value, path);
61 return o && o.map(
"tid", thread.
tid) && o.map(
"iptTrace", thread.
ipt_trace);
67 {
"triple", process.
triple},
74 ObjectMapper o(value, path);
75 return o && o.map(
"pid", process.
pid) && o.map(
"triple", process.
triple) &&
76 o.map(
"threads", process.
threads) && o.map(
"modules", process.
modules);
88 ObjectMapper o(value, path);
90 if (!(o && o.map(
"id", cpu_id) && o.map(
"iptTrace", cpu.
ipt_trace) &&
97json::Value
toJSON(
const pt_cpu &cpu_info) {
99 {
"vendor", cpu_info.vendor == pcv_intel ?
"GenuineIntel" :
"Unknown"},
100 {
"family", cpu_info.family},
101 {
"model", cpu_info.model},
102 {
"stepping", cpu_info.stepping},
106bool fromJSON(
const json::Value &value, pt_cpu &cpu_info, Path path) {
107 ObjectMapper o(value, path);
109 uint64_t family, model, stepping;
110 if (!(o && o.map(
"vendor", vendor) && o.map(
"family", family) &&
111 o.map(
"model", model) && o.map(
"stepping", stepping)))
113 cpu_info.vendor = vendor ==
"GenuineIntel" ? pcv_intel : pcv_unknown;
114 cpu_info.family = family;
115 cpu_info.model = model;
116 cpu_info.stepping = stepping;
121 json::Object json_module;
124 json_module[
"file"] = kernel.
file;
125 return std::move(json_module);
129 ObjectMapper o(value, path);
130 return o && o.map(
"loadAddress", kernel.
load_address) &&
131 o.map(
"file", kernel.
file);
136 {
"type", bundle_description.
type},
137 {
"processes", bundle_description.
processes},
141 {
"cpus", bundle_description.
cpus},
143 {
"kernel", bundle_description.
kernel}};
148 ObjectMapper o(value, path);
149 if (!(o && o.map(
"processes", bundle_description.
processes) &&
150 o.map(
"type", bundle_description.
type) &&
151 o.map(
"cpus", bundle_description.
cpus) &&
152 o.map(
"tscPerfZeroConversion",
154 o.map(
"kernel", bundle_description.
kernel)))
158 "\"tscPerfZeroConversion\" is required when \"cpus\" is provided");
163 if (!
fromJSON(*value.getAsObject()->get(
"cpuInfo"),
164 bundle_description.
cpu_info, path.field(
"cpuInfo")))
170 if (bundle_description.
kernel) {
172 !bundle_description.
processes->empty()) {
173 path.report(
"\"processes\" must be empty when \"kernel\" is provided");
176 if (!bundle_description.
cpus) {
177 path.report(
"\"cpus\" is required when \"kernel\" is provided");
180 }
else if (!bundle_description.
processes) {
182 path.report(
"\"processes\" is required when \"kernel\" is not provided");
bool fromJSON(const json::Value &value, JSONModule &module, Path path)
json::Value toJSON(const JSONModule &module)
A class that represents a running process on the host machine.
std::string context_switch_trace
std::optional< JSONUINT64 > load_address
std::optional< std::string > uuid
std::optional< std::string > file
std::optional< std::string > triple
std::vector< JSONModule > modules
std::vector< JSONThread > threads
std::optional< std::string > ipt_trace
std::optional< std::vector< lldb::cpu_id_t > > GetCpuIds()
std::optional< std::vector< JSONCpu > > cpus
std::optional< LinuxPerfZeroTscConversion > tsc_perf_zero_conversion
std::optional< JSONKernel > kernel
std::optional< std::vector< JSONProcess > > processes