Release coccinelle-0.2.3rc1
[bpt/coccinelle.git] / tools / process_isoprofile.ml
CommitLineData
9f8e26f4 1(*
ae4735db 2 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
9f8e26f4
C
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
5 *
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
9 *
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
20 *)
21
22
5636bb2c
C
23(*
24 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
25 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
26 * This file is part of Coccinelle.
27 *
28 * Coccinelle is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, according to version 2 of the License.
31 *
32 * Coccinelle is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
36 *
37 * You should have received a copy of the GNU General Public License
38 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
39 *
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
42 *)
43
44
34e49164
C
45(* This is for processing information created with the -profile_iso option.
46Runs are assumed separated with a line beginning with =.
47The first run is discarded *)
48
49let is_marker l = String.get l 0 = '='
50let is_nothing l = String.sub l 0 2 = "ls"
51
52let skip_start i = (* skip over the ========== at the beginning *)
53 let rec loop _ =
54 let l = input_line i in
55 if not (is_marker l)
56 then loop() in
57 loop()
58
59let get_data l =
60 match Str.split (Str.regexp ":") l with
61 [_;after] ->
62 (match Str.split (Str.regexp " sec") after with
63 [info;_] -> float_of_string info
64 | _ -> failwith "bad data")
65 | _ -> failwith (Printf.sprintf "bad data %s" l)
66
67type more = MORE | NOMORE | INFO of float * float * float * float | CONT
68
69let read_data_one i =
70 try
71 let start = input_line i in (* three lines of header *)
72 if is_marker start
73 then MORE
74 else if is_nothing start
75 then CONT
76 else
77 let _ = input_line i in
78 let _ = input_line i in
79 (match
80 List.sort compare
81 [input_line i;input_line i;input_line i;input_line i]
82 with
83 [asttoctl;full_engine;mysat;parse_cocci] ->
84 if String.get full_engine 0 = '*'
85 then (let _ = input_line i in CONT) (* hack!!! *)
86 else
87 let asttoctl = get_data asttoctl in
88 let full_engine = get_data full_engine in
89 let mysat = get_data mysat in
90 let parse_cocci = get_data parse_cocci in
91 INFO(full_engine,mysat,parse_cocci,asttoctl)
92 | _ -> failwith "not possible")
93 with End_of_file -> NOMORE
94
95let read_data i =
96 skip_start i;
97 let optcons x y = if x = [] then y else x::y in
98 let rec loop all_acc acc =
99 match read_data_one i with
100 NOMORE -> optcons acc all_acc
101 | MORE -> loop (optcons acc all_acc) []
102 | CONT -> loop all_acc acc
103 | INFO(a,b,c,d) -> loop all_acc ((a,b,c,d)::acc) in
104 let table = loop [] [] in
105 let all_infos = (* a list with a list of information for each file *)
106 List.fold_left
107 (function all_infos ->
108 function one_run ->
109 List.map2 (function ainfo -> function orun -> orun::ainfo)
110 all_infos one_run)
111 (List.map (function _ -> []) (List.hd table))
112 table in
113 let overheads =
114 List.concat
115 (List.map (List.map (function (_,x,y,z) -> x+.y+.z)) all_infos) in
116 let total_times =
117 List.concat
118 (List.map (List.map (function (x,_,_,_) -> x)) all_infos) in
119 let mysat_times =
120 List.concat
121 (List.map (List.map (function (_,x,_,_) -> x)) all_infos) in
122 let parse_time =
123 List.concat
124 (List.map (List.map (function (_,_,x,y) -> x +. y)) all_infos) in
125 (overheads,total_times,mysat_times,parse_time)
126
127let percent pct = (int_of_float ((100.0 *. pct) +. 0.5)) - 100
128let mpercent pct = (int_of_float ((100.0 *. pct) +. 0.5))
129let minf l = List.fold_left min (List.hd l) l
130let maxf l = List.fold_left max (List.hd l) l
131
132let ave = function
133 [] -> 0.0
134 | l ->
135 let total = List.fold_left (+.) 0.0 l in
136 total /. (float_of_int(List.length l))
137
138let process_files iso_file noiso_file =
139 let i = open_in iso_file in
140 let (iso_over,iso_total,iso_mysat,iso_parse) = read_data i in
141 close_in i;
142 let i = open_in noiso_file in
143 let (noiso_over,noiso_total,noiso_mysat,noiso_parse) = read_data i in
144 close_in i;
145 Printf.printf "isos: min %f max %f ave %f\n"
146 (minf iso_total) (maxf iso_total) (ave iso_total);
147 Printf.printf "noisos: min %f max %f ave %f\n"
148 (minf noiso_total) (maxf noiso_total) (ave noiso_total);
149 Printf.printf "Overhead in total time %d%%: min %f max %f\n"
150 (percent (ave (List.map2 (/.) iso_total noiso_total)))
151 (minf (List.map2 (-.) iso_total noiso_total))
152 (maxf (List.map2 (-.) iso_total noiso_total));
153 Printf.printf "Portion of overhead due to parsing %d%%: min %f max %f\n"
154 (mpercent
155 (ave (List.fold_left2
156 (function acc ->
157 (function (iso_total,iso_parse) ->
158 (function (noiso_total,noiso_parse) ->
159 let total_ovd = iso_total -. noiso_total in
160 let parse_ovd = iso_parse -. noiso_parse in
161 if total_ovd < 0.001 or parse_ovd > total_ovd or
162 parse_ovd < 0.0
163 then acc
164 else (parse_ovd /. total_ovd) :: acc)))
165 []
166 (List.combine iso_total iso_parse)
167 (List.combine noiso_total noiso_parse))))
168 (minf (List.map2 (-.) iso_parse noiso_parse))
169 (maxf (List.map2 (-.) iso_parse noiso_parse));
170 Printf.printf "Portion of overhead due to matching %d%%: min %f max %f\n\n"
171 (mpercent
172 (ave (List.fold_left2
173 (function acc ->
174 (function (iso_total,iso_mysat) ->
175 (function (noiso_total,noiso_mysat) ->
176 let total_ovd = iso_total -. noiso_total in
177 let mysat_ovd = iso_mysat -. noiso_mysat in
178 if total_ovd < 0.001 or mysat_ovd > total_ovd or
179 mysat_ovd < 0.0
180 then acc
181 else (mysat_ovd /. total_ovd) :: acc)))
182 []
183 (List.combine iso_total iso_mysat)
184 (List.combine noiso_total noiso_mysat))))
185 (minf (List.map2 (-.) iso_mysat noiso_mysat))
186 (maxf (List.map2 (-.) iso_mysat noiso_mysat))
187
188let _ =
189 let iso = Array.get Sys.argv 1 in
190 let noiso = Array.get Sys.argv 2 in
191 process_files iso noiso