File: process_isoprofile.ml

package info (click to toggle)
coccinelle 1.0.8.deb-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 26,148 kB
  • sloc: ml: 136,392; ansic: 23,594; sh: 2,189; makefile: 2,157; perl: 1,576; lisp: 840; python: 823; awk: 70; csh: 12
file content (153 lines) | stat: -rw-r--r-- 5,359 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
(*
 * This file is part of Coccinelle, lincensed under the terms of the GPL v2.
 * See copyright.txt in the Coccinelle source code for more information.
 * The Coccinelle source code can be obtained at http://coccinelle.lip6.fr
 *)

(* This is for processing information created with the -profile_iso option.
Runs are assumed separated with a line beginning with =.
The first run is discarded *)

let is_marker l  = String.get l 0 = '='
let is_nothing l = String.sub l 0 2 = "ls"

let skip_start i = (* skip over the ========== at the beginning *)
  let rec loop _ =
    let l = input_line i in
    if not (is_marker l)
    then loop() in
  loop()

let get_data l =
  match Str.split (Str.regexp ":") l with
    [_;after] ->
      (match Str.split (Str.regexp " sec") after with
	[info;_] -> float_of_string info
      |	_ -> failwith "bad data")
  | _ -> failwith (Printf.sprintf "bad data %s" l)

type more = MORE | NOMORE | INFO of float * float * float * float | CONT

let read_data_one i =
  try
    let start = input_line i in (* three lines of header *)
    if is_marker start
    then MORE
    else if is_nothing start
    then CONT
    else
      let _ = input_line i in
      let _ = input_line i in
      (match
	List.sort compare
	  [input_line i;input_line i;input_line i;input_line i]
      with
	[asttoctl;full_engine;mysat;parse_cocci] ->
	  if String.get full_engine 0 = '*'
	  then (let _ = input_line i in CONT) (* hack!!! *)
	  else
	    let asttoctl = get_data asttoctl in
	    let full_engine = get_data full_engine in
	    let mysat = get_data mysat in
	    let parse_cocci = get_data parse_cocci in
	    INFO(full_engine,mysat,parse_cocci,asttoctl)
      |	_ -> failwith "not possible")
  with End_of_file -> NOMORE

let read_data i =
  skip_start i;
  let optcons x y = if x = [] then y else x::y in
  let rec loop all_acc acc =
    match read_data_one i with
      NOMORE -> optcons acc all_acc
    | MORE -> loop (optcons acc all_acc) []
    | CONT -> loop all_acc acc
    | INFO(a,b,c,d) -> loop all_acc ((a,b,c,d)::acc) in
  let table = loop [] [] in
  let all_infos = (* a list with a list of information for each file *)
    List.fold_left
      (function all_infos ->
	function one_run ->
	  List.map2 (function ainfo -> function orun -> orun::ainfo)
	    all_infos one_run)
      (List.map (function _ -> []) (List.hd table))
      table in
  let overheads =
    List.concat
      (List.map (List.map (function (_,x,y,z) -> x+.y+.z)) all_infos) in
  let total_times =
    List.concat
      (List.map (List.map (function (x,_,_,_) -> x)) all_infos) in
  let mysat_times =
    List.concat
      (List.map (List.map (function (_,x,_,_) -> x)) all_infos) in
  let parse_time =
    List.concat
      (List.map (List.map (function (_,_,x,y) -> x +. y)) all_infos) in
  (overheads,total_times,mysat_times,parse_time)

let percent pct = (int_of_float ((100.0 *. pct) +. 0.5)) - 100
let mpercent pct = (int_of_float ((100.0 *. pct) +. 0.5))
let minf l = List.fold_left min (List.hd l) l
let maxf l = List.fold_left max (List.hd l) l

let ave = function
    [] -> 0.0
  | l ->
      let total = List.fold_left (+.) 0.0 l in
      total /. (float_of_int(List.length l))

let process_files iso_file noiso_file =
  let i = open_in iso_file in
  let (iso_over,iso_total,iso_mysat,iso_parse) = read_data i in
  close_in i;
  let i = open_in noiso_file in
  let (noiso_over,noiso_total,noiso_mysat,noiso_parse) = read_data i in
  close_in i;
  Printf.printf "isos:   min %f max %f ave %f\n"
    (minf iso_total) (maxf iso_total) (ave iso_total);
  Printf.printf "noisos: min %f max %f ave %f\n"
    (minf noiso_total) (maxf noiso_total) (ave noiso_total);
  Printf.printf "Overhead in total time %d%%: min %f max %f\n"
    (percent (ave (List.map2 (/.) iso_total noiso_total)))
    (minf (List.map2 (-.) iso_total noiso_total))
    (maxf (List.map2 (-.) iso_total noiso_total));
  Printf.printf "Portion of overhead due to parsing %d%%: min %f max %f\n"
    (mpercent
       (ave (List.fold_left2
	       (function acc ->
		 (function (iso_total,iso_parse) ->
		   (function (noiso_total,noiso_parse) ->
		     let total_ovd = iso_total -. noiso_total in
		     let parse_ovd = iso_parse -. noiso_parse in
		     if total_ovd < 0.001 || parse_ovd > total_ovd ||
		       parse_ovd < 0.0
		     then acc
		     else (parse_ovd /. total_ovd) :: acc)))
	       []
	       (List.combine iso_total iso_parse)
	       (List.combine noiso_total noiso_parse))))
    (minf (List.map2 (-.) iso_parse noiso_parse))
    (maxf (List.map2 (-.) iso_parse noiso_parse));
  Printf.printf "Portion of overhead due to matching %d%%: min %f max %f\n\n"
    (mpercent
       (ave (List.fold_left2
	       (function acc ->
		 (function (iso_total,iso_mysat) ->
		   (function (noiso_total,noiso_mysat) ->
		     let total_ovd = iso_total -. noiso_total in
		     let mysat_ovd = iso_mysat -. noiso_mysat in
		     if total_ovd < 0.001 || mysat_ovd > total_ovd ||
		       mysat_ovd < 0.0
		     then acc
		     else (mysat_ovd /. total_ovd) :: acc)))
	       []
	       (List.combine iso_total iso_mysat)
	       (List.combine noiso_total noiso_mysat))))
    (minf (List.map2 (-.) iso_mysat noiso_mysat))
    (maxf (List.map2 (-.) iso_mysat noiso_mysat))

let _ =
  let iso = Array.get Sys.argv 1 in
  let noiso = Array.get Sys.argv 2 in
  process_files iso noiso