X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=extract%2Fcodegen%2Fpahole_parser.ml;h=029ecdea3c4d79dd55047260711111475198b8c5;hb=fea04ba6838a7fb1f7f6df9ea5b9603603205f3d;hp=f8b5bd1dfba53d5c5e56817a23d49fd8e7851802;hpb=0ab39a448da6dd9bca3c2730f1221fad0718ac36;p=virt-mem.git diff --git a/extract/codegen/pahole_parser.ml b/extract/codegen/pahole_parser.ml index f8b5bd1..029ecde 100644 --- a/extract/codegen/pahole_parser.ml +++ b/extract/codegen/pahole_parser.ml @@ -27,6 +27,7 @@ let (//) = Filename.concat type pathname = string type info = { + kv_i : int; kernel_version : string; arch : string; basename : string; @@ -54,7 +55,7 @@ and f_type = | FString of int let string_of_info i = - sprintf "%s: %s %s" i.basename i.kernel_version i.arch + sprintf "%s: %s (%d) %s" i.basename i.kernel_version i.kv_i i.arch let rec string_of_structure s = let fields = List.map string_of_field s.struct_fields in @@ -92,8 +93,8 @@ let list_kernels path = (* Parse in the *.info files. These have historically had a few different * formats that we need to support. *) - let infos = List.map ( - fun filename -> + let infos = List.mapi ( + fun i filename -> (* Get the basename (for getting the .data file later on). *) let basename = Filename.chop_suffix filename ".info" in @@ -146,7 +147,8 @@ let list_kernels path = (*printf "%s -> %s %s\n%!" basename version arch;*) - { basename = basename; arch = arch; + { kv_i = i; + basename = basename; arch = arch; kernel_version = version } ) infos in infos @@ -435,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 ( @@ -458,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