cfd7735e3ef1d2ed91b2e40a751377031e8f33eb
[bpt/coccinelle.git] / tools / process_isoprofile.ml
1 (*
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.
7 *
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.
11 *
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.
16 *
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/>.
19 *
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
22 *)
23
24
25 (* This is for processing information created with the -profile_iso option.
26 Runs are assumed separated with a line beginning with =.
27 The first run is discarded *)
28
29 let is_marker l = String.get l 0 = '='
30 let is_nothing l = String.sub l 0 2 = "ls"
31
32 let skip_start i = (* skip over the ========== at the beginning *)
33 let rec loop _ =
34 let l = input_line i in
35 if not (is_marker l)
36 then loop() in
37 loop()
38
39 let get_data l =
40 match Str.split (Str.regexp ":") l with
41 [_;after] ->
42 (match Str.split (Str.regexp " sec") after with
43 [info;_] -> float_of_string info
44 | _ -> failwith "bad data")
45 | _ -> failwith (Printf.sprintf "bad data %s" l)
46
47 type more = MORE | NOMORE | INFO of float * float * float * float | CONT
48
49 let read_data_one i =
50 try
51 let start = input_line i in (* three lines of header *)
52 if is_marker start
53 then MORE
54 else if is_nothing start
55 then CONT
56 else
57 let _ = input_line i in
58 let _ = input_line i in
59 (match
60 List.sort compare
61 [input_line i;input_line i;input_line i;input_line i]
62 with
63 [asttoctl;full_engine;mysat;parse_cocci] ->
64 if String.get full_engine 0 = '*'
65 then (let _ = input_line i in CONT) (* hack!!! *)
66 else
67 let asttoctl = get_data asttoctl in
68 let full_engine = get_data full_engine in
69 let mysat = get_data mysat in
70 let parse_cocci = get_data parse_cocci in
71 INFO(full_engine,mysat,parse_cocci,asttoctl)
72 | _ -> failwith "not possible")
73 with End_of_file -> NOMORE
74
75 let read_data i =
76 skip_start i;
77 let optcons x y = if x = [] then y else x::y in
78 let rec loop all_acc acc =
79 match read_data_one i with
80 NOMORE -> optcons acc all_acc
81 | MORE -> loop (optcons acc all_acc) []
82 | CONT -> loop all_acc acc
83 | INFO(a,b,c,d) -> loop all_acc ((a,b,c,d)::acc) in
84 let table = loop [] [] in
85 let all_infos = (* a list with a list of information for each file *)
86 List.fold_left
87 (function all_infos ->
88 function one_run ->
89 List.map2 (function ainfo -> function orun -> orun::ainfo)
90 all_infos one_run)
91 (List.map (function _ -> []) (List.hd table))
92 table in
93 let overheads =
94 List.concat
95 (List.map (List.map (function (_,x,y,z) -> x+.y+.z)) all_infos) in
96 let total_times =
97 List.concat
98 (List.map (List.map (function (x,_,_,_) -> x)) all_infos) in
99 let mysat_times =
100 List.concat
101 (List.map (List.map (function (_,x,_,_) -> x)) all_infos) in
102 let parse_time =
103 List.concat
104 (List.map (List.map (function (_,_,x,y) -> x +. y)) all_infos) in
105 (overheads,total_times,mysat_times,parse_time)
106
107 let percent pct = (int_of_float ((100.0 *. pct) +. 0.5)) - 100
108 let mpercent pct = (int_of_float ((100.0 *. pct) +. 0.5))
109 let minf l = List.fold_left min (List.hd l) l
110 let maxf l = List.fold_left max (List.hd l) l
111
112 let ave = function
113 [] -> 0.0
114 | l ->
115 let total = List.fold_left (+.) 0.0 l in
116 total /. (float_of_int(List.length l))
117
118 let process_files iso_file noiso_file =
119 let i = open_in iso_file in
120 let (iso_over,iso_total,iso_mysat,iso_parse) = read_data i in
121 close_in i;
122 let i = open_in noiso_file in
123 let (noiso_over,noiso_total,noiso_mysat,noiso_parse) = read_data i in
124 close_in i;
125 Printf.printf "isos: min %f max %f ave %f\n"
126 (minf iso_total) (maxf iso_total) (ave iso_total);
127 Printf.printf "noisos: min %f max %f ave %f\n"
128 (minf noiso_total) (maxf noiso_total) (ave noiso_total);
129 Printf.printf "Overhead in total time %d%%: min %f max %f\n"
130 (percent (ave (List.map2 (/.) iso_total noiso_total)))
131 (minf (List.map2 (-.) iso_total noiso_total))
132 (maxf (List.map2 (-.) iso_total noiso_total));
133 Printf.printf "Portion of overhead due to parsing %d%%: min %f max %f\n"
134 (mpercent
135 (ave (List.fold_left2
136 (function acc ->
137 (function (iso_total,iso_parse) ->
138 (function (noiso_total,noiso_parse) ->
139 let total_ovd = iso_total -. noiso_total in
140 let parse_ovd = iso_parse -. noiso_parse in
141 if total_ovd < 0.001 or parse_ovd > total_ovd or
142 parse_ovd < 0.0
143 then acc
144 else (parse_ovd /. total_ovd) :: acc)))
145 []
146 (List.combine iso_total iso_parse)
147 (List.combine noiso_total noiso_parse))))
148 (minf (List.map2 (-.) iso_parse noiso_parse))
149 (maxf (List.map2 (-.) iso_parse noiso_parse));
150 Printf.printf "Portion of overhead due to matching %d%%: min %f max %f\n\n"
151 (mpercent
152 (ave (List.fold_left2
153 (function acc ->
154 (function (iso_total,iso_mysat) ->
155 (function (noiso_total,noiso_mysat) ->
156 let total_ovd = iso_total -. noiso_total in
157 let mysat_ovd = iso_mysat -. noiso_mysat in
158 if total_ovd < 0.001 or mysat_ovd > total_ovd or
159 mysat_ovd < 0.0
160 then acc
161 else (mysat_ovd /. total_ovd) :: acc)))
162 []
163 (List.combine iso_total iso_mysat)
164 (List.combine noiso_total noiso_mysat))))
165 (minf (List.map2 (-.) iso_mysat noiso_mysat))
166 (maxf (List.map2 (-.) iso_mysat noiso_mysat))
167
168 let _ =
169 let iso = Array.get Sys.argv 1 in
170 let noiso = Array.get Sys.argv 2 in
171 process_files iso noiso