946075b4b0f46d248ba9074d95a40772ac648c1a
[ocaml-ancient.git] / test_ancient_weblogs.ml
1 (* Load in large weblogs and see if they can still be used.
2  * $Id: test_ancient_weblogs.ml,v 1.1 2006-09-27 14:05:07 rich Exp $
3  *)
4
5 open Printf
6
7 open ExtList
8
9 let gc_stats = true (* If true, print GC stats before processing each day. *)
10
11 let (//) = Filename.concat
12
13 let rec range a b =
14   if a > b then []
15   else a :: range (succ a) b
16
17 (* Cartesian join of two lists. *)
18 let cartesian xs ys =
19   List.flatten (
20     List.map (
21       fun x ->
22         List.map (
23           fun y -> x, y
24         ) ys
25     ) xs
26   )
27
28 let file_readable filename =
29   try Unix.access filename [Unix.R_OK]; true
30   with Unix.Unix_error _ -> false
31
32 (* Suppress warning messages. *)
33 let () = Weblogs.quiet := true
34
35 let gc_compact () =
36   eprintf "compacting ... %!";
37   Gc.compact ();
38   if gc_stats then (
39     let stat = Gc.stat () in
40     let live_words = stat.Gc.live_words in
41     eprintf "live words = %d (%d MB)\n%!"
42       live_words (live_words * 8 / 1024 / 1024)
43   )
44
45 (* Find the list of files.  Some which should exist don't, so
46  * warnings about those so we can chase up.
47  *)
48 let files =
49   let dir = "/home/rich/oversized-logfiles/perrys" in
50   let drivers =
51     [ "burns"; "gronholm"; "rohrl"; "sainz"; "solberg"; "vatanen" ] in
52   let dates = range 1 31 in
53   let dates = List.map (fun day -> sprintf "200608%02d" day) dates in
54   let files = cartesian drivers dates in
55   let files =
56     List.map (fun (driver, date) ->
57                 sprintf "%s-perrys-access.log.%s.gz" driver date) files in
58   let files =
59     List.filter_map (
60       fun filename ->
61         let path = dir // filename in
62         if not (file_readable path) then (
63           prerr_endline ("warning: " ^ filename ^ " not found - ignored");
64           None
65         ) else (
66           Some path
67         )
68     ) files in
69
70   eprintf "number of files = %d\n%!" (List.length files);
71
72   files
73
74 (* Load each file into memory and make it ancient. *)
75 let () =
76   let files =
77     List.map (
78       fun filename ->
79         eprintf "Importing file %s\n%!" filename;
80         let rows =
81           let rows = Weblogs.import_file filename in
82           Ancient.mark rows in
83         gc_compact ();
84         rows
85     ) files in
86
87   ignore (files)
88