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