2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
26 * Copyright 2010, INRIA, University of Copenhagen
27 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
28 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
29 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
30 * This file is part of Coccinelle.
32 * Coccinelle is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation, according to version 2 of the License.
36 * Coccinelle is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
41 * You should have received a copy of the GNU General Public License
42 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
44 * The authors reserve the right to distribute this or future versions of
45 * Coccinelle under other licenses.
49 (* for each marked thing, how often does it occur and in what files and
55 let l = input_line i
in
56 (if String.length
l > 2 && String.get
l 0 = '
+'
57 then info := (String.sub
l 1 (String.length
l - 1))::!info);
60 with End_of_file
-> List.rev
!info
63 let rec loop acc
= function
66 if String.get x
0 = '
+'
(* the start of a new file *)
68 (match Str.split (Str.regexp
" ") x
with
69 _
::x
::_
-> loop ((x
,[])::acc
) xs
70 | _
-> failwith
("no file: "^x
))
74 (file
,instances
)::rest
-> (file
,x
::instances
)::rest
75 | _
-> failwith
"not possible" in
77 let res = List.rev
(loop [] l) in
78 List.map
(function (x
,l) -> (x
,List.rev
l)) res
80 let detect_alloc_free str
l =
82 let (same
,diff
) = List.partition
(function (a1
,f1
) -> a
= a1
) l in
84 [(a1
,f1
)] -> if List.mem f f1
then l else (a1
,f
::f1
) :: diff
86 let rec loop acc = function
89 match Str.split (Str.regexp
(str^
"\", ")) x
with
95 (match Str.split (Str.regexp
"[, )]+") rest
with
96 alloc
::free
::_
-> try_add alloc free
acc
100 | _
-> loop acc xs
in
102 (List.map
(function (a
,f
) -> (a
,List.sort compare f
)) (loop [] l))
104 let rec iterate str
= function
111 List.partition
(function (x1
,l1
) -> l1
= info) rest
in
113 [(files
,info)] -> (x
::files
,info)::diff
114 | _
-> ([x
],info)::diff
)
115 (iterate str xs
) (detect_alloc_free str
l)
117 (* ------------------------------------------------------------------------ *)
119 let get_dir d
= Filename.dirname d
121 let get_subsystem d
=
122 let pieces = Str.split (Str.regexp
"/") d
in
123 let front = List.hd
(List.tl
pieces) in
125 "arch" | "drivers" -> front ^
"/" ^
(List.hd
(List.tl
(List.tl
pieces)))
128 let rec remdup = function
130 | x
::xs
-> if List.mem x xs
then remdup xs
else x
:: remdup xs
134 (try let cell = Hashtbl.find tbl key
in cell
135 with Not_found
-> let c = ref 0 in Hashtbl.add tbl key
c; c) in
138 let files_per_protocol = Hashtbl.create
(10)
139 let dirs_per_protocol = Hashtbl.create
(10)
140 let subsystems_per_protocol = Hashtbl.create
(10)
141 let protocols_per_subsystem = Hashtbl.create
(10)
143 let collect_counts l =
145 (function (files
,(a
,fs
)) ->
146 let how_many_files = List.length files
in
147 let how_many_dirs = remdup (List.map
get_dir files
) in
148 let how_many_subsystems = remdup (List.map
get_subsystem files
) in
150 if how_many_files < 10
152 else ((how_many_files / 10) * 10) in
153 inc files_per_protocol ct;
154 inc dirs_per_protocol (List.length
how_many_dirs);
155 inc subsystems_per_protocol (List.length
how_many_subsystems);
156 List.iter
(inc protocols_per_subsystem) how_many_subsystems)
159 let print_hashtable f tbl
=
162 (function key
-> function vl
-> function rest
->
165 let l = List.sort compare
l in
167 (function (key
,vl
) ->
168 Printf.printf
" "; f key
; Printf.printf
": %d\n" vl
)
171 let print_range_int_hashtable range
=
175 then Printf.printf
"%d" x
176 else Printf.printf
"%d-%d" x
(x
+ range
- 1))
177 let print_int_hashtable =
178 print_hashtable (function x
-> Printf.printf
"%d" x
)
179 let print_string_hashtable =
180 print_hashtable (function x
-> Printf.printf
"%s" x
)
183 Printf.printf
"files per protocol:\n";
184 print_range_int_hashtable 10 files_per_protocol;
185 Printf.printf
"dirs per protocol:\n";
186 print_int_hashtable dirs_per_protocol;
187 Printf.printf
"subsystems per protocol:\n";
188 print_int_hashtable subsystems_per_protocol;
189 Printf.printf
"protocols per subsystem:\n";
190 print_string_hashtable protocols_per_subsystem
192 (* ------------------------------------------------------------------------ *)
196 let str = ref "detected allocator"
202 Arg.parse
(Arg.align
options) (fun x
-> file := x
) usage;
203 let i = open_in
!file in
207 let l = iterate !str l in