]> gitweb.factorcode.org Git - factor.git/commitdiff
unix.linux.proc: Handle a unified processor-info object for linux 2.6 and on. Add...
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 1 May 2013 19:25:00 +0000 (12:25 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 1 May 2013 19:25:49 +0000 (12:25 -0700)
basis/unix/linux/proc/proc-tests.factor [new file with mode: 0644]
basis/unix/linux/proc/proc.factor

diff --git a/basis/unix/linux/proc/proc-tests.factor b/basis/unix/linux/proc/proc-tests.factor
new file mode 100644 (file)
index 0000000..5fd8e37
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2013 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel tools.test unix.linux.proc ;
+IN: unix.linux.proc.tests
+
+{ } [ parse-proc-cmdline drop ] unit-test
+{ } [ parse-proc-cpuinfo drop ] unit-test
+{ } [ parse-proc-loadavg drop ] unit-test
+{ } [ parse-proc-meminfo drop ] unit-test
+{ } [ parse-proc-partitions drop ] unit-test
+{ } [ parse-proc-stat drop ] unit-test
+{ } [ parse-proc-swaps drop ] unit-test
+{ } [ parse-proc-uptime drop ] unit-test
index 7776d60b8595ad41e1d2b7d61b9dbce19d373754..78996a650369e0522c5926361e5ea0a75a170f11 100644 (file)
@@ -27,56 +27,77 @@ TUPLE: processor-info
     { microcode integer }
     { cpu-mhz number }
     { cache-size integer }
+    { fdiv-bug? boolean }
+    { hlt-bug? boolean }
+    { f00f-bug? boolean }
+    { coma-bug? boolean }
     { physical-id integer }
     { siblings integer }
     { core-id integer }
     { cpu-cores integer }
     { apicid integer }
     { initial-apicid integer }
-    { fpu string }
-    { fpu-expception string }
+    { fpu? boolean }
+    { fpu-exception? boolean }
     { cpuid-level integer }
-    { wp string }
+    { wp? boolean }
     { flags array }
     { bogomips number }
     { clflush-size integer }
-    { cache-alignent integer }
+    { cache-alignment integer }
     { address-sizes array }
     { power-management string } ;
 
+
+ERROR: unknown-cpuinfo-line string ;
+
+: line>processor-info ( processor-info string -- processor-info )
+    ":" split first2 swap
+    [ CHAR: \t = ] trim-tail [ [ CHAR: \s = ] trim ] bi@
+    {
+        { "address sizes" [
+            "," split [ [ CHAR: \s = ] trim " " split first string>number ] map
+            >>address-sizes
+        ] }
+        { "apicid" [ string>number >>apicid ] }
+        { "bogomips" [ string>number >>bogomips ] }
+        { "cache size" [
+            " " split first [ CHAR: \s = ] trim
+            string>number 1024 * >>cache-size
+        ] }
+        { "cache_alignment" [ string>number >>cache-alignment ] }
+        { "clflush size" [ string>number >>clflush-size ] }
+        { "coma_bug" [ "yes" = >>coma-bug? ] }
+        { "core id" [ string>number >>core-id ] }
+        { "cpu MHz" [ string>number >>cpu-mhz ] }
+        { "cpu cores" [ string>number >>cpu-cores ] }
+        { "cpu family" [ string>number >>cpu-family ] }
+        { "cpuid level" [ string>number >>cpuid-level ] }
+        { "f00f_bug" [ "yes" = >>f00f-bug? ] }
+        { "fdiv_bug" [ "yes" = >>fdiv-bug? ] }
+        { "flags" [ " " split harvest >>flags ] }
+        { "fpu" [ "yes" = >>fpu? ] }
+        { "fpu_exception" [ "yes" = >>fpu-exception? ] }
+        { "hlt_bug" [ "yes" = >>hlt-bug? ] }
+        { "initial apicid" [ string>number >>initial-apicid ] }
+        { "microcode" [ string>number >>microcode ] }
+        { "model" [ string>number >>model ] }
+        { "model name" [ >>model-name ] }
+        { "physical id" [ string>number >>physical-id ] }
+        { "power management" [ >>power-management ] }
+        { "processor" [ string>number >>processor ] }
+        { "siblings" [ string>number >>siblings ] }
+        { "stepping" [ string>number >>stepping ] }
+        { "vendor_id" [ >>vendor-id ] }
+        { "wp" [ "yes" = >>wp? ] }
+        [ unknown-cpuinfo-line ]
+    } case ;
+
+
 ! Linux 2.6 has fewer values than new kernels
 : lines>processor-info ( strings -- processor-info )
-    [ ":" split second [ CHAR: \s = ] trim ] map
-    25 f pad-tail
-    [
-        {
-            [ string>number ]
-            [ ]
-            [ string>number ]
-            [ string>number ]
-            [ ]
-            [ string>number ]
-            [ string>number ]
-            [ string>number ]
-            [ " " split first [ CHAR: \s = ] trim string>number 1024 * ]
-            [ string>number ]
-            [ string>number ]
-            [ string>number ]
-            [ string>number ]
-            [ string>number ]
-            [ string>number ]
-            [ ]
-            [ ]
-            [ string>number ]
-            [ ]
-            [ " " split harvest ]
-            [ string>number ]
-            [ string>number ]
-            [ string>number ]
-            [ "," split [ [ CHAR: \s = ] trim " " split first string>number ] map ]
-            [ ]
-        } spread
-    ] input<sequence processor-info boa ;
+    [ processor-info new ] dip
+    [ line>processor-info ] each ;
 
 : parse-proc-cpuinfo ( -- seq )
     "/proc/cpuinfo" utf8 file-lines