virt-ps working again.
[virt-mem.git] / extract / codegen / pahole_parser.ml
index 99e36de..029ecde 100644 (file)
@@ -437,11 +437,27 @@ let get_fields structures =
    *)
   let h = Hashtbl.create 13 in
 
+  (* A hash to check for fields which aren't always available by
+   * counting the number of times we see each field.
+   *)
+  let count, get =
+    let h = Hashtbl.create 13 in
+    let count field_name =
+      let r =
+       try Hashtbl.find h field_name
+       with Not_found -> let r = ref 0 in Hashtbl.add h field_name r; r in
+      incr r
+    in
+    let get field_name = try !(Hashtbl.find h field_name) with Not_found -> 0 in
+    count, get
+  in
+
   List.iter (
     fun ({kernel_version = version},
         {struct_name = struct_name; struct_fields = fields}) ->
       List.iter (
        fun {field_name = name; field_type = typ} ->
+         count name;
          try
            let (field_type, version_first_seen) = Hashtbl.find h name in
            if typ <> field_type then (
@@ -460,10 +476,13 @@ let get_fields structures =
       ) fields
   ) structures;
 
+  let nr_kernels = List.length structures in
+
   let fields =
     Hashtbl.fold (
       fun name (typ, _) fields ->
-       (name, typ) :: fields
+       let always_available = get name = nr_kernels in
+       (name, (typ, always_available)) :: fields
     ) h [] in
 
   List.sort fields