1 (* for each marked thing, how often does it occur and in what files and
7 let l = input_line i
in
8 (if String.length
l > 2 && String.get
l 0 = '
+'
9 then info := (String.sub
l 1 (String.length
l - 1))::!info);
12 with End_of_file
-> List.rev
!info
15 let rec loop acc
= function
18 if String.get x
0 = '
+'
(* the start of a new file *)
20 (match Str.split (Str.regexp
" ") x
with
21 _
::x
::_
-> loop ((x
,[])::acc
) xs
22 | _
-> failwith
("no file: "^x
))
26 (file
,instances
)::rest
-> (file
,x
::instances
)::rest
27 | _
-> failwith
"not possible" in
29 let res = List.rev
(loop [] l) in
30 List.map
(function (x
,l) -> (x
,List.rev
l)) res
32 let detect_alloc_free str
l =
34 let (same
,diff
) = List.partition
(function (a1
,f1
) -> a
= a1
) l in
36 [(a1
,f1
)] -> if List.mem f f1
then l else (a1
,f
::f1
) :: diff
38 let rec loop acc = function
41 match Str.split (Str.regexp
(str^
"\", ")) x
with
47 (match Str.split (Str.regexp
"[, )]+") rest
with
48 alloc
::free
::_
-> try_add alloc free
acc
54 (List.map
(function (a
,f
) -> (a
,List.sort compare f
)) (loop [] l))
56 let rec iterate str
= function
63 List.partition
(function (x1
,l1
) -> l1
= info) rest
in
65 [(files
,info)] -> (x
::files
,info)::diff
66 | _
-> ([x
],info)::diff
)
67 (iterate str xs
) (detect_alloc_free str
l)
69 (* ------------------------------------------------------------------------ *)
71 let get_dir d
= Filename.dirname d
74 let pieces = Str.split (Str.regexp
"/") d
in
75 let front = List.hd
(List.tl
pieces) in
77 "arch" | "drivers" -> front ^
"/" ^
(List.hd
(List.tl
(List.tl
pieces)))
80 let rec remdup = function
82 | x
::xs
-> if List.mem x xs
then remdup xs
else x
:: remdup xs
86 (try let cell = Hashtbl.find tbl key
in cell
87 with Not_found
-> let c = ref 0 in Hashtbl.add tbl key
c; c) in
90 let files_per_protocol = Hashtbl.create
(10)
91 let dirs_per_protocol = Hashtbl.create
(10)
92 let subsystems_per_protocol = Hashtbl.create
(10)
93 let protocols_per_subsystem = Hashtbl.create
(10)
95 let collect_counts l =
97 (function (files
,(a
,fs
)) ->
98 let how_many_files = List.length files
in
99 let how_many_dirs = remdup (List.map
get_dir files
) in
100 let how_many_subsystems = remdup (List.map
get_subsystem files
) in
102 if how_many_files < 10
104 else ((how_many_files / 10) * 10) in
105 inc files_per_protocol ct;
106 inc dirs_per_protocol (List.length
how_many_dirs);
107 inc subsystems_per_protocol (List.length
how_many_subsystems);
108 List.iter
(inc protocols_per_subsystem) how_many_subsystems)
111 let print_hashtable f tbl
=
114 (function key
-> function vl
-> function rest
->
117 let l = List.sort compare
l in
119 (function (key
,vl
) ->
120 Printf.printf
" "; f key
; Printf.printf
": %d\n" vl
)
123 let print_range_int_hashtable range
=
127 then Printf.printf
"%d" x
128 else Printf.printf
"%d-%d" x
(x
+ range
- 1))
129 let print_int_hashtable =
130 print_hashtable (function x
-> Printf.printf
"%d" x
)
131 let print_string_hashtable =
132 print_hashtable (function x
-> Printf.printf
"%s" x
)
135 Printf.printf
"files per protocol:\n";
136 print_range_int_hashtable 10 files_per_protocol;
137 Printf.printf
"dirs per protocol:\n";
138 print_int_hashtable dirs_per_protocol;
139 Printf.printf
"subsystems per protocol:\n";
140 print_int_hashtable subsystems_per_protocol;
141 Printf.printf
"protocols per subsystem:\n";
142 print_string_hashtable protocols_per_subsystem
144 (* ------------------------------------------------------------------------ *)
148 let str = ref "detected allocator"
154 Arg.parse
(Arg.align
options) (fun x
-> file := x
) usage;
155 let i = open_in
!file in
159 let l = iterate !str l in