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