<commit_before>
open Printf
open Ld_util
open Ld_known_modules

let cache_file = ".ld.ocaml.cache"

let t0 = Unix.gettimeofday ()

let sys_catalog =
  try
    load_catalog (Filename.concat (Sys.getenv "HOME") cache_file)
  with
    | Not_found (* no HOME *) -> build_catalog default_dirs
    | Sys_error _ ->
        let cat = build_catalog default_dirs in
          save_catalog cat (Filename.concat (Sys.getenv "HOME") cache_file);
          cat

let catalog =
  try
    let extra = Str.split (Str.regexp ":") (Sys.getenv "LD_OCAML_LIBRARY_PATH") in
      merge_catalogs
        [ sys_catalog;
          build_catalog
            (List.filter (fun d -> not (List.mem d default_dirs)) extra) ]
  with Not_found -> (* no extra paths *) sys_catalog

let () =
  debug :=
    try
      int_of_string (Sys.getenv "LD_OCAML_VERBOSE")
    with Not_found -> 0
      | _ -> 1

let () = if !debug >= 2 then display_catalog catalog

let () =
  let state = state_of_known_modules ~known_interfaces ~known_implementations in
  let rec extract_cmxs_args = function
    | f :: tl when is_cmxs f -> f :: extract_cmxs_args tl
    | _ -> [] in
  let cmxs = extract_cmxs_args (List.tl (Array.to_list (Sys.argv))) in
    (* TODO: should rewrite Sys.argv instead, need to extract cmxs args in C
     * code before initializing the caml runtime *)
    Arg.current := 1 + List.length cmxs;
    let sol = resolve catalog state cmxs in
      if !debug >= 1 then begin
        eprintf "Needed %8.5fs so far.\n" (Unix.gettimeofday () -. t0);
        eprintf "Loading:\n";
        List.iter (eprintf "  %s\n") cmxs;
        display_solution sol;
        flush stderr;
      end;
      load_deps sol;
      List.iter do_load cmxs<commit_msg>ld_ocaml: report catalog generation and symbol resolution times.<commit_after>
open Printf
open Ld_util
open Ld_known_modules

let cache_file = ".ld.ocaml.cache"

let t0 = Unix.gettimeofday ()

let sys_catalog =
  try
    load_catalog (Filename.concat (Sys.getenv "HOME") cache_file)
  with
    | Not_found (* no HOME *) -> build_catalog default_dirs
    | Sys_error _ ->
        let cat = build_catalog default_dirs in
          save_catalog cat (Filename.concat (Sys.getenv "HOME") cache_file);
          cat

let catalog =
  try
    let extra = Str.split (Str.regexp ":") (Sys.getenv "LD_OCAML_LIBRARY_PATH") in
      merge_catalogs
        [ sys_catalog;
          build_catalog
            (List.filter (fun d -> not (List.mem d default_dirs)) extra) ]
  with Not_found -> (* no extra paths *) sys_catalog

let () =
  debug :=
    try
      int_of_string (Sys.getenv "LD_OCAML_VERBOSE")
    with Not_found -> 0
      | _ -> 1

let () = if !debug >= 2 then display_catalog catalog

let () =
  let state = state_of_known_modules ~known_interfaces ~known_implementations in
  let rec extract_cmxs_args = function
    | f :: tl when is_cmxs f -> f :: extract_cmxs_args tl
    | _ -> [] in
  let cmxs = extract_cmxs_args (List.tl (Array.to_list (Sys.argv))) in
    (* TODO: should rewrite Sys.argv instead, need to extract cmxs args in C
     * code before initializing the caml runtime *)
    Arg.current := 1 + List.length cmxs;
    if !debug >= 1 then
      eprintf "Built DLL catalog in %8.5fs.\n" (Unix.gettimeofday () -. t0);
    let t0 = Unix.gettimeofday () in
    let sol = resolve catalog state cmxs in
      if !debug >= 1 then begin
        eprintf "Needed %8.5fs for symbol resolution.\n" (Unix.gettimeofday () -. t0);
        eprintf "Loading:\n";
        List.iter (eprintf "  %s\n") cmxs;
        display_solution sol;
        flush stderr;
      end;
      load_deps sol;
      List.iter do_load cmxs
{'fraction_non_alphanumeric': 0.10275482093663912, 'fraction_numerical': 0.006336088154269973, 'mean_word_length': 2.645582329317269, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1112398', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1211, 'n_words': 359}