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