package coq-lsp

  1. Overview
  2. Docs
Language Server Protocol native server for Coq

Install

Dune Dependency

Authors

Maintainers

Sources

coq-lsp-0.1.7.8.16.tbz
sha256=6a88fdb3e42994204f5d2cbc8f4e7da2ac7cf28568a93c8455464c05d1087022
sha512=38c417cc28a3a0d5eb4305ee5239a0cda6ba425d7f22a17f8d3ec7b9baf27598f57fd9d5ee9a44584a3730b6105128f774abeaf2eb560cfc8bb612aa95fcc0b7

doc/src/coq-lsp.fleche/stats.ml.html

Source file stats.ml

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
(************************************************************************)
(* Coq Language Server Protocol                                         *)
(* Copyright 2019 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+      *)
(* Copyright 2022 Inria           -- Dual License LGPL 2.1 / GPL3+      *)
(* Written by: Emilio J. Gallego Arias                                  *)
(************************************************************************)
(* Status: Experimental                                                 *)
(************************************************************************)

module Kind = struct
  type t =
    | Hashing
    | Parsing
    | Exec
end

let stats = Hashtbl.create 1000
let find kind = Hashtbl.find_opt stats kind |> Option.default 0.0

type t = float * float * float

let zero () = (0.0, 0.0, 0.0)
let dump () = (find Kind.Hashing, find Kind.Parsing, find Kind.Exec)

let restore (h, p, e) =
  Hashtbl.replace stats Kind.Hashing h;
  Hashtbl.replace stats Kind.Parsing p;
  Hashtbl.replace stats Kind.Exec e

let get_f (h, p, e) ~kind =
  match kind with
  | Kind.Hashing -> h
  | Parsing -> p
  | Exec -> e

let bump kind time =
  let acc = find kind in
  Hashtbl.replace stats kind (acc +. time)

let time f x =
  let before = Unix.gettimeofday () in
  let res = f x in
  let after = Unix.gettimeofday () in
  (res, after -. before)

let record ~kind ~f x =
  let res, time = time f x in
  bump kind time;
  (res, time)

let get ~kind = find kind

let to_string (h, p, e) =
  Format.asprintf "hashing: %f | parsing: %f | exec: %f" h p e

let reset () =
  Hashtbl.remove stats Kind.Hashing;
  Hashtbl.remove stats Kind.Parsing;
  Hashtbl.remove stats Kind.Exec;
  ()

let mb = 1024 * 1024

let pp_words fmt w =
  (* Format is not working great for floating point values... *)
  let w = int_of_float w in
  let value, spec =
    if w < 1024 then (w, "w ")
    else if w < mb then (w / 1024, "Kw")
    else (w / mb, "Mw")
  in
  Format.fprintf fmt "@[%4d %s@]" value spec
OCaml

Innovation. Community. Security.