package js_of_ocaml

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file performance.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
(* Js_of_ocaml library
 * http://www.ocsigen.org/js_of_ocaml/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, with linking exception;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *)

open! Import

class type performanceEntry = object
  inherit PerformanceObserver.performanceEntry
end

class type ['detail] performanceMark = object
  inherit performanceEntry

  method detail : 'detail Js.opt Js.readonly_prop
end

class type ['detail] performanceMeasure = object
  inherit performanceEntry

  method detail : 'detail Js.opt Js.readonly_prop
end

class type ['detail] performanceMarkOptions = object
  method detail : 'detail Js.writeonly_prop

  method startTime : Js.number_t Js.writeonly_prop
end

class type ['detail] performanceMeasureOptions = object
  method detail : 'detail Js.writeonly_prop

  method start : Js.js_string Js.t Js.writeonly_prop

  method start_time : Js.number_t Js.writeonly_prop

  method _end : Js.js_string Js.t Js.writeonly_prop

  method end_time : Js.number_t Js.writeonly_prop

  method duration : Js.number_t Js.writeonly_prop
end

class type performance = object
  method timeOrigin : Js.number_t Js.readonly_prop

  method now : Js.number_t Js.meth

  method mark : 'a. Js.js_string Js.t -> 'a performanceMark Js.t Js.meth

  method mark_options :
    'a.
    Js.js_string Js.t -> 'a performanceMarkOptions Js.t -> 'a performanceMark Js.t Js.meth

  method measure :
    'a.
       Js.js_string Js.t
    -> Js.js_string Js.t Js.optdef
    -> Js.js_string Js.t Js.optdef
    -> 'a performanceMeasure Js.t Js.meth

  method measure_options :
    'a.
       Js.js_string Js.t
    -> 'a performanceMeasureOptions Js.t
    -> 'a performanceMeasure Js.t Js.meth

  method clearMarks : unit Js.meth

  method clearMarks_named : Js.js_string Js.t -> unit Js.meth

  method clearMeasures : unit Js.meth

  method clearMeasures_named : Js.js_string Js.t -> unit Js.meth

  method clearResourceTimings : unit Js.meth

  method getEntries : performanceEntry Js.t Js.js_array Js.t Js.meth

  method getEntriesByName :
    Js.js_string Js.t -> performanceEntry Js.t Js.js_array Js.t Js.meth

  method getEntriesByName_type :
       Js.js_string Js.t
    -> Js.js_string Js.t
    -> performanceEntry Js.t Js.js_array Js.t Js.meth

  method getEntriesByType :
    Js.js_string Js.t -> performanceEntry Js.t Js.js_array Js.t Js.meth

  method setResourceTimingBufferSize : int -> unit Js.meth
end

let performance : performance Js.t = Js.Unsafe.global##.performance

let is_supported () = Js.Optdef.test Js.Unsafe.global##.performance

let mark ?detail ?startTime (perf : performance Js.t) name =
  let opts : _ performanceMarkOptions Js.t = Js.Unsafe.obj [||] in
  Option.iter (fun v -> opts##.detail := v) detail;
  Option.iter (fun v -> opts##.startTime := v) startTime;
  perf##mark_options name opts

let makeMeasureOptions ?detail ?start ?start_time ?_end ?end_time ?duration () =
  if Option.is_some start && Option.is_some start_time
  then invalid_arg "Performance.makeMeasureOptions: both ?start and ?start_time given";
  if Option.is_some _end && Option.is_some end_time
  then invalid_arg "Performance.makeMeasureOptions: both ?_end and ?end_time given";
  let opts : _ performanceMeasureOptions Js.t = Js.Unsafe.obj [||] in
  Option.iter (fun v -> opts##.detail := v) detail;
  Option.iter (fun v -> opts##.start := v) start;
  Option.iter (fun v -> opts##.start_time := v) start_time;
  Option.iter (fun v -> opts##._end := v) _end;
  Option.iter (fun v -> opts##.end_time := v) end_time;
  Option.iter (fun v -> opts##.duration := v) duration;
  opts