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