Admin/isatest_statistics.ML
author haftmann
Tue Sep 19 15:21:42 2006 +0200 (2006-09-19)
changeset 20588 c847c56edf0c
parent 20359 517236b1bb1d
permissions -rw-r--r--
added operational equality
berghofe@20347
     1
(*  Title:      Admin/isatest_statistics.ML
berghofe@20347
     2
    ID:         $Id$
berghofe@20347
     3
    Author:     Stefan Berghofer, TU Muenchen
berghofe@20347
     4
berghofe@20347
     5
Script for producing Gnuplot data files describing runtimes of Isabelle
berghofe@20347
     6
sessions from the logfiles generated by isatest.
berghofe@20347
     7
*)
berghofe@20347
     8
berghofe@20347
     9
structure Statistics =
berghofe@20347
    10
struct
berghofe@20347
    11
berghofe@20347
    12
fun read_dir s =
berghofe@20347
    13
  let
berghofe@20347
    14
    val d = OS.FileSys.openDir s;
berghofe@20347
    15
    fun read_all () = (case OS.FileSys.readDir d of
berghofe@20347
    16
        NONE => []
berghofe@20347
    17
      | SOME s => s :: read_all ());
berghofe@20347
    18
    val xs = read_all ();
berghofe@20347
    19
    val _ = OS.FileSys.closeDir d
berghofe@20347
    20
  in xs end;
berghofe@20347
    21
berghofe@20347
    22
fun is_suffix eq xs ys = is_prefix eq (rev xs) (rev ys);
berghofe@20347
    23
berghofe@20347
    24
fun int_of_string s = the (Int.fromString s);
berghofe@20347
    25
berghofe@20347
    26
fun get_files dir year compiler =
berghofe@20347
    27
  let
berghofe@20347
    28
    val fs = read_dir dir;
berghofe@20347
    29
    val subdirs = filter (is_prefix op = (explode year) o explode) fs
berghofe@20347
    30
    val fs' = List.concat (map (fn d =>
berghofe@20347
    31
      map (pair (dir ^ "/" ^ d)) (read_dir (dir ^ "/" ^ d))) subdirs);
berghofe@20347
    32
    val prfx = explode ("isatest-makeall-" ^ compiler ^ "-");
berghofe@20347
    33
    val sfx = explode ".gz";
berghofe@20347
    34
    val k = length prfx;
berghofe@20347
    35
    val fs'' = List.mapPartial (fn (d, f) =>
berghofe@20347
    36
      let val xs = explode f
berghofe@20347
    37
      in
berghofe@20347
    38
        if is_prefix op = prfx xs andalso is_suffix op = sfx xs then
berghofe@20347
    39
          let
berghofe@20347
    40
            val (_, xs1) = chop k xs;
berghofe@20347
    41
            val (year', xs2) = chop 4 xs1;
berghofe@20347
    42
            val (_ :: month, xs3) = chop 3 xs2;
berghofe@20347
    43
            val (_ :: day, _) = chop 3 xs3
berghofe@20347
    44
          in
berghofe@20347
    45
            if year = implode year' then SOME (d, f,
berghofe@20347
    46
              (int_of_string (implode year'),
berghofe@20347
    47
               (int_of_string (implode month),
berghofe@20347
    48
                int_of_string (implode day))))
berghofe@20347
    49
            else NONE
berghofe@20347
    50
          end
berghofe@20347
    51
        else NONE
berghofe@20347
    52
      end) (map (pair dir) fs @ fs')
berghofe@20347
    53
  in sort (prod_ord int_ord (prod_ord int_ord int_ord) o pairself #3) fs'' end;
berghofe@20347
    54
berghofe@20347
    55
fun get_times f =
berghofe@20347
    56
  let
berghofe@20359
    57
    val s = execute ("zcat " ^ f ^ " | grep Finished | grep \"elapsed time\"");
berghofe@20347
    58
    val xs = filter_out (equal "") (space_explode "\n" s);
berghofe@20347
    59
    fun get_time s =
berghofe@20347
    60
      let
berghofe@20347
    61
        val xs = explode s;
berghofe@20347
    62
        val (_, _ :: xs1) = take_prefix (not o equal " ") xs;
berghofe@20347
    63
        val (logic, _ :: _ :: h :: _ :: m1 :: m2 :: _ :: s1 :: s2 :: xs2) =
berghofe@20347
    64
          take_prefix (not o equal " ") xs1;
berghofe@20359
    65
        val cpu = case take_prefix (not o equal ",") xs2 of
berghofe@20359
    66
            (_, _ :: _ :: h' :: _ :: m1' :: m2' :: _ :: s1' :: s2' :: _) =>
berghofe@20359
    67
              SOME (int_of_string h',
berghofe@20359
    68
                int_of_string (m1' ^ m2'), int_of_string (s1' ^ s2'))
berghofe@20359
    69
          | _ => NONE
berghofe@20347
    70
      in (implode logic,
berghofe@20347
    71
        ((int_of_string h, int_of_string (m1 ^ m2), int_of_string (s1 ^ s2)),
berghofe@20359
    72
         cpu))
berghofe@20347
    73
      end
berghofe@20347
    74
  in
berghofe@20347
    75
    map get_time xs
berghofe@20347
    76
  end;
berghofe@20347
    77
berghofe@20347
    78
fun mk_table tab logic =
berghofe@20347
    79
  let
berghofe@20347
    80
    fun mk_entry (times, (y, (M, D))) = (case AList.lookup op = times logic of
berghofe@20359
    81
        SOME (t, t') =>
berghofe@20347
    82
          let
berghofe@20359
    83
            val (h, m, s) = the_default t t';
berghofe@20347
    84
            val date = (100 * ((M - 1) * 31 + D - 1)) div 31;
berghofe@20347
    85
            val time = (100 * (h * 3600 + 60 * m + s)) div 60
berghofe@20347
    86
          in
berghofe@20347
    87
            SOME (Int.toString (date div 100) ^ "." ^ Int.toString (date mod 100) ^ " " ^
berghofe@20347
    88
              Int.toString (time div 100) ^ "." ^ Int.toString (time mod 100))
berghofe@20347
    89
          end
berghofe@20347
    90
      | NONE => (warning ("No session " ^ quote logic ^ " in logfile for " ^
berghofe@20347
    91
          Int.toString y ^ "-" ^ Int.toString M ^ "-" ^ Int.toString D); NONE));
berghofe@20347
    92
  in
berghofe@20347
    93
    space_implode "\n" (List.mapPartial mk_entry tab) ^ "\n"
berghofe@20347
    94
  end;
berghofe@20347
    95
berghofe@20347
    96
fun mk_tables dir targetdir year compiler =
berghofe@20347
    97
  let
berghofe@20347
    98
    val files = get_files dir year compiler;
berghofe@20347
    99
    val tab = map (fn (d, f, date) => (get_times (d ^ "/" ^ f), date)) files;
berghofe@20347
   100
    val logics = map fst (fst (hd tab))
berghofe@20347
   101
  in
berghofe@20347
   102
    Library.seq (fn logic =>
berghofe@20347
   103
      File.write (Path.append (Path.unpack targetdir) (Path.unpack (logic ^ ".dat")))
berghofe@20347
   104
        (mk_table tab logic)) logics
berghofe@20347
   105
  end;
berghofe@20347
   106
berghofe@20347
   107
end
berghofe@20347
   108
berghofe@20347
   109
berghofe@20347
   110
(**** Example *****
berghofe@20347
   111
berghofe@20347
   112
In ML:
berghofe@20347
   113
berghofe@20347
   114
Statistics.mk_tables "/home/isatest/log" "/tmp" "2006" "at-poly";
berghofe@20347
   115
berghofe@20347
   116
In Gnuplot:
berghofe@20347
   117
berghofe@20347
   118
plot [0:8] [0:40] '/tmp/HOL.dat' smooth sbezier title "HOL", '/tmp/HOL-Auth.dat' smooth sbezier title "HOL-Auth", '/tmp/HOL-Complex.dat' smooth sbezier title "HOL-Complex", '/tmp/HOL-UNITY.dat' smooth sbezier title "HOL-UNITY", '/tmp/HOL-Bali.dat' smooth sbezier title "HOL-Bali", '/tmp/HOL-MicroJava.dat' smooth sbezier title "HOL-MicroJava"
berghofe@20347
   119
berghofe@20347
   120
*******************)