ProcFS: JSONify /proc/cpuinfo

To be more in line with other parts of Serenity's procfs, the
"key: value" format of /proc/cpuinfo was replaced with JSON, namely
an array of objects (one for each core).

The available keys remain the same, though "features" has been changed
from a space-separated string to an array of strings.
This commit is contained in:
Linus Groh 2020-07-11 20:52:10 +01:00 committed by Andreas Kling
parent 43d955014d
commit fc0ec60d82
Notes: sideshowbarker 2024-07-19 04:56:10 +09:00

View file

@ -732,27 +732,26 @@ Optional<KBuffer> procfs$df(InodeIdentifier)
Optional<KBuffer> procfs$cpuinfo(InodeIdentifier)
{
KBufferBuilder builder;
bool first = true;
JsonArraySerializer array { builder };
Processor::for_each(
[&](Processor& proc) -> IterationDecision
{
if (first)
first = false;
else
builder.append('\n');
auto& info = proc.info();
builder.appendf("processor: %u\n", proc.id());
builder.appendf("cpuid: %s\n", info.cpuid().characters());
builder.appendf("family: %u\n", info.display_family());
builder.appendf("features: %s\n", info.features().characters());
builder.appendf("model: %u\n", info.display_model());
builder.appendf("stepping: %u\n", info.stepping());
builder.appendf("type: %u\n", info.type());
builder.appendf("brandstr: \"%s\"\n", info.brandstr().characters());
auto obj = array.add_object();
JsonArray features;
for (auto& feature : info.features().split(' '))
features.append(feature);
obj.add("processor", proc.id());
obj.add("cpuid", info.cpuid());
obj.add("family", info.display_family());
obj.add("features", features);
obj.add("model", info.display_model());
obj.add("stepping", info.stepping());
obj.add("type", info.type());
obj.add("brandstr", info.brandstr());
return IterationDecision::Continue;
});
array.finish();
return builder.build();
}