Browse Source

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.
Linus Groh 5 years ago
parent
commit
fc0ec60d82
1 changed files with 14 additions and 15 deletions
  1. 14 15
      Kernel/FileSystem/ProcFS.cpp

+ 14 - 15
Kernel/FileSystem/ProcFS.cpp

@@ -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();
 }