11#pragma once
2+ #include < assert.h>
23#include < json/json.h>
34#include < string>
45#include < variant>
56#include < vector>
6- #include < assert.h>
77
88namespace cortex ::hw {
99
@@ -26,6 +26,7 @@ struct CPU {
2626 int cores;
2727 std::string arch;
2828 std::string model;
29+ float usage;
2930 std::vector<std::string> instructions;
3031};
3132
@@ -34,6 +35,7 @@ inline Json::Value ToJson(const CPU& cpu) {
3435 res[" arch" ] = cpu.arch ;
3536 res[" cores" ] = cpu.cores ;
3637 res[" model" ] = cpu.model ;
38+ res[" usage" ] = cpu.usage ;
3739 Json::Value insts (Json::arrayValue);
3840 for (auto const & i : cpu.instructions ) {
3941 insts.append (i);
@@ -47,11 +49,16 @@ inline CPU FromJson(const Json::Value& root) {
4749 int cores = root[" cores" ].asInt ();
4850 std::string arch = root[" arch" ].asString ();
4951 std::string model = root[" model" ].asString ();
52+ float usage = root[" usage" ].asFloat ();
5053 std::vector<std::string> insts;
5154 for (auto const & i : root[" instructions" ]) {
5255 insts.emplace_back (i.asString ());
5356 }
54- return {.cores = cores, .arch = arch, .model = model, .instructions = insts};
57+ return {.cores = cores,
58+ .arch = arch,
59+ .model = model,
60+ .usage = usage,
61+ .instructions = insts};
5562}
5663} // namespace cpu
5764
@@ -64,6 +71,7 @@ struct AmdAddInfo {};
6471using GPUAddInfo = std::variant<NvidiaAddInfo, AmdAddInfo>;
6572struct GPU {
6673 std::string id;
74+ uint32_t device_id;
6775 std::string name;
6876 std::string version;
6977 GPUAddInfo add_info;
@@ -77,7 +85,7 @@ inline Json::Value ToJson(const std::vector<GPU>& gpus) {
7785 Json::Value res (Json::arrayValue);
7886 for (size_t i = 0 ; i < gpus.size (); i++) {
7987 Json::Value gpu;
80- gpu[" id" ] = std::to_string (i) ;
88+ gpu[" id" ] = gpus[i]. id ;
8189 gpu[" name" ] = gpus[i].name ;
8290 gpu[" version" ] = gpus[i].version ;
8391 Json::Value add_info;
@@ -142,7 +150,6 @@ inline OS FromJson(const Json::Value& root) {
142150}
143151} // namespace os
144152
145-
146153struct PowerInfo {
147154 std::string charging_status;
148155 int battery_life;
@@ -165,7 +172,6 @@ inline PowerInfo FromJson(const Json::Value& root) {
165172}
166173} // namespace power
167174
168-
169175namespace {
170176int64_t ByteToMiB (int64_t b) {
171177 return b / 1024 / 1024 ;
@@ -214,4 +220,4 @@ inline StorageInfo FromJson(const Json::Value& root) {
214220 .available = root[" available" ].asInt64 ()};
215221}
216222} // namespace storage
217- }
223+ } // namespace cortex::hw
0 commit comments