Skip to content

Commit b0cc0c7

Browse files
authored
Create dump-file-stats command (#115)
1 parent c1d51aa commit b0cc0c7

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/ocaml-index/bin/ocaml_index.ml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ let rewrite_root = ref false
1515
let store_shapes = ref false
1616
let do_not_use_cmt_loadpath = ref false
1717

18-
type command = Aggregate | Dump | Stats | Gather_shapes
18+
type command = Aggregate | Dump | Dump_file_stats | Stats | Gather_shapes
1919

2020
let parse_command = function
2121
| "aggregate" -> Some Aggregate
2222
| "dump" -> Some Dump
23+
| "dump-file-stats" -> Some Dump_file_stats
2324
| "stats" -> Some Stats
2425
| "gather-shapes" -> Some Gather_shapes
2526
| _ -> None
@@ -90,6 +91,19 @@ let () =
9091
List.iter
9192
(fun file -> Index_format.(read_exn ~file |> pp Format.std_formatter))
9293
(List.rev !input_files_rev)
94+
| Some Dump_file_stats ->
95+
List.iter
96+
(fun file ->
97+
let open Merlin_index_format.Index_format in
98+
let index = read_exn ~file in
99+
Printf.printf "File stats for index %S:\n" file;
100+
Stats.iter
101+
(fun file { mtime; size; source_digest } ->
102+
Printf.printf " %S: { mtime=%f; size=%d; source_digest=%S }\n" file
103+
mtime size
104+
(Option.value source_digest ~default:"none"))
105+
index.stats)
106+
(List.rev !input_files_rev)
93107
| Some Gather_shapes ->
94108
Index.gather_shapes ~output_file:!output_file (List.rev !input_files_rev)
95109
| Some Stats ->
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Test using the dump-file-stats subcommand
2+
3+
mtime will not be consistent between tests, so don't include it
4+
$ normalize () {
5+
> cat | sed -E "s/mtime=[0-9\.]+/mtime=<mtime>/g"
6+
> }
7+
8+
Create a small project
9+
$ mkdir foo
10+
$ cat > foo/a.ml << EOF
11+
> let hello = "hello"
12+
> EOF
13+
$ cat > foo/b.ml << EOF
14+
> let world = "world"
15+
> EOF
16+
17+
Compile the project and create an index file
18+
$ $OCAMLC -c -bin-annot -bin-annot-occurrences foo/a.ml foo/b.ml
19+
$ ocaml-index aggregate foo/a.cmt foo/b.cmt -o foo.merlin-index
20+
21+
Dump the file stats from the index
22+
$ ocaml-index dump-file-stats foo.merlin-index | normalize
23+
File stats for index "foo.merlin-index":
24+
"foo/a.ml": { mtime=<mtime>; size=20; source_digest="\147<\155xp\000:M2\170\163\134K`\235\226" }
25+
"foo/b.ml": { mtime=<mtime>; size=20; source_digest="erv\218\000\233\177\190e\189\199\026q\156\195#" }

0 commit comments

Comments
 (0)