text stringlengths 12 786k |
|---|
module Stable = struct module Span = Span . Stable module Ofday = Ofday . Stable end |
module Int64_set = Set . Make ( struct type t = int64 let compare = compare end ) |
module Span_set = Diet . Make ( struct type t = Timedesc . Span . t let compare = Timedesc . Span . compare let zero = Timedesc . Span . zero let pred = Timedesc . Span . pred let succ = Timedesc . Span . succ let sub = Timedesc . Span . sub let add = Timedesc . Span . add let to... |
module Alco = struct let suite = [ ] end |
module Qc = struct let slice_start = QCheck . Test . make ~ count : 10_000 ~ name " : slice_start " QCheck . ( pair pos_timestamp sorted_time_slots_maybe_gaps ) ( fun ( start , l ) -> l |> CCList . to_seq |> Time . Intervals . Slice . slice ~ start |> OSeq . for_all ( fun (... |
module type Zone = sig module Time : Time0_intf . S include Zone . S with type t = Zone . t and module Time_in_seconds := Time val abbreviation : t -> Time . t -> string val absolute_time_of_date_and_ofday : t -> Time . Date_and_ofday . t -> Time . t val date_and_ofday_of_absolute_time : t -> ... |
module type Basic = sig module Time : Time0_intf . S include module type of struct include Time end [ @ ocaml . remove_aliases ] val now : unit -> t module Zone : Zone with module Time := Time val add : t -> Span . t -> t val sub : t -> Span . t -> t val diff : t -> t -> Span . t val abs_d... |
module type Shared = sig type t include Quickcheck . S_range with type t := t module Span : sig type t end module Ofday : sig type t end val is_earlier : t -> than : t -> bool val is_later : t -> than : t -> bool val of_date_ofday : zone : Zone . t -> Date . t -> Ofday . t -> t val of_date_ofda... |
module type S = sig include Basic include Shared with type t := t with module Span := Span with module Ofday := Ofday end |
module type Time = sig module type S = S module Make ( Time : Time0_intf . S ) : S with module Time := Time end |
module type S = sig val duration : Measurement . key -> ( unit -> ' a ) -> ' a val duration_lwt : Measurement . key -> ( unit -> ' a Lwt . t ) -> ' a Lwt . t val timestamp_pre : Measurement . key -> ( unit -> ' a ) -> ' a val flush : unit -> unit Lwt . t end |
module Make ( S : State . S with type elt := Measurement . t ) ( P : Publisher . S ) ( C : Clock . S ) : S = struct let span start stop = stop . - start let duration ( label , metadata ) f = let start = C . current_time ( ) in let res = f ( ) in let stop = C . current... |
let arch_sixtyfour = Sys . word_size = 64 |
let add = Span . ( + ) |
let sub = Span . ( - ) |
let diff = Span . ( - ) |
let abs_diff t u = Span . abs ( diff t u ) |
let to_span_since_epoch t = t |
let of_span_since_epoch s = s |
let to_int63_ns_since_epoch t : Int63 . t = Span . to_int63_ns ( to_span_since_epoch t ) |
let of_int63_ns_since_epoch i = of_span_since_epoch ( Span . of_int63_ns i ) |
let is_earlier t1 ~ than : t2 = t1 < t2 |
let is_later t1 ~ than : t2 = t1 > t2 |
let add_overflowed x y ~ sum = if Span . ( > ) y Span . zero then Span . ( < ) sum x else Span . ( > ) sum x ; ; |
let sub_overflowed x y ~ diff = if Span . ( > ) y Span . zero then Span . ( > ) diff x else Span . ( < ) diff x ; ; |
let add_exn x y = let sum = add x y in if add_overflowed x y ~ sum then overflow ( ) else sum ; ; |
let sub_exn x y = let diff = sub x y in if sub_overflowed x y ~ diff then overflow ( ) else diff ; ; |
let add_saturating x y = let sum = add x y in if add_overflowed x y ~ sum then if Span . ( y > zero ) then Span . max_value_representable else Span . min_value_representable else sum ; ; |
let sub_saturating x y = let diff = sub x y in if sub_overflowed x y ~ diff then if Span . ( y > zero ) then Span . min_value_representable else Span . max_value_representable else diff ; ; |
let to_int_ns_since_epoch = if arch_sixtyfour then fun t -> Int63 . to_int_exn ( to_int63_ns_since_epoch t ) else fun _ -> failwith " Time_ns . to_int_ns_since_epoch : unsupported on 32bit machines " ; ; |
let of_int_ns_since_epoch i = of_int63_ns_since_epoch ( Int63 . of_int i ) |
let to_time_float_round_nearest t = Time_float . of_span_since_epoch ( Span . to_span_float_round_nearest ( to_span_since_epoch t ) ) ; ; |
let to_time_float_round_nearest_microsecond t = Time_float . of_span_since_epoch ( Span . to_span_float_round_nearest_microsecond ( to_span_since_epoch t ) ) ; ; |
let min_time_value_for_1us_rounding = to_time_float_round_nearest min_value_for_1us_rounding ; ; |
let max_time_value_for_1us_rounding = to_time_float_round_nearest max_value_for_1us_rounding ; ; |
let check_before_conversion_for_1us_rounding time = if Time_float . ( < ) time min_time_value_for_1us_rounding || Time_float . ( > ) time max_time_value_for_1us_rounding then failwiths ~ here [ :% here ] " Time_ns does not support this time " time [ % sexp_of : Time_float . Stable . Wi... |
let of_time_float_round_nearest time = of_span_since_epoch ( Span . of_span_float_round_nearest ( Time_float . to_span_since_epoch time ) ) ; ; |
let of_time_float_round_nearest_microsecond time = check_before_conversion_for_1us_rounding time ; of_span_since_epoch ( Span . of_span_float_round_nearest_microsecond ( Time_float . to_span_since_epoch time ) ) ; ; failwiths ~ here [ :% here ] " Time_ns . next_multiple got nonpositive inte... |
let next_multiple_internal ~ can_equal_after ~ base ~ after ~ interval = if Span . ( <= ) interval Span . zero then raise_next_multiple_got_nonpositive_interval interval ; let base_to_after = diff after base in if Span . ( < ) base_to_after Span . zero then base else ( let next = add base (... |
let next_multiple ( ? can_equal_after = false ) ~ base ~ after ~ interval ( ) = next_multiple_internal ~ can_equal_after ~ base ~ after ~ interval ; ; |
let prev_multiple ( ? can_equal_before = false ) ~ base ~ before ~ interval ( ) = next_multiple_internal ~ can_equal_after ( : not can_equal_before ) ~ base ~ after ( : sub before interval ) ~ interval ; ; |
let random ? state ( ) = Span . random ? state ( ) |
module Utc : sig val to_date_and_span_since_start_of_day : t -> Date0 . t * Span . t val of_date_and_span_since_start_of_day : Date0 . t -> Span . t -> t let to_date_and_span_since_start_of_day t = let open Int63 . O in let ( !< ) i = Int63 . of_int_exn i in let ( !> ) t = Int63 . to_i... |
module Alternate_sexp = struct type nonrec t = t module Ofday_as_span = struct open Int . O let seconds_to_string seconds_span = let seconds = Span . to_int_sec seconds_span in let h = seconds / 3600 in let m = seconds / 60 % 60 in let s = seconds % 60 in sprintf " % 02d :% 02d :% 02d " h ... |
module Stable = struct module Alternate_sexp = Alternate_sexp . Stable module Span = Span . Stable module Ofday = Ofday . Stable end |
module To_and_of_string : sig val of_date_ofday : zone : Zone . t -> Date . t -> Ofday . t -> t val of_date_ofday_precise : Date . t -> Ofday . t -> zone : Zone . t -> [ ` Once of t | ` Twice of t * t | ` Never of t ] val to_date_ofday : t -> zone : Zone . t -> Date . t * Of... |
let min_value_representable = of_span_since_epoch Span . min_value_representable |
let max_value_representable = of_span_since_epoch Span . max_value_representable |
module For_ppx_module_timer = struct open Ppx_module_timer_runtime let ( ) = Duration . format := ( module struct let duration_of_span s = s |> Span . to_int63_ns |> Duration . of_nanoseconds let span_of_duration d = d |> Duration . to_nanoseconds |> Span . of_int63_ns let of_string string = s... |
module type Span = sig type t = private Int63 . t [ @@ deriving hash ] include Span_intf . S with type underlying = Int63 . t and type t := t val of_sec_with_microsecond_precision : float -> t val of_int_us : int -> t val of_int_ms : int -> t val to_int_us : t -> int val to_int_ms : t -> int va... |
module type Ofday = sig module Span : Span type t = private Int63 . t include Ofday_intf . S with type underlying = Int63 . t and type t := t and module Span := Span val approximate_end_of_day : t val add_exn : t -> Span . t -> t val sub_exn : t -> Span . t -> t val every : Span . t -> start ... |
module type Time_ns = sig module Span : Span module Ofday : Ofday with module Span := Span type t = private Int63 . t [ @@ deriving hash , typerep , bin_io ] include Comparisons . S with type t := t module Alternate_sexp : sig type nonrec t = t [ @@ deriving sexp ] end include Time_intf . Sh... |
let x = Tezos_time_measurement_runtime . Default . Time_measurement . duration " label42 " ( fun ( ) -> 40 + 2 ) ] } ) * |
type measurement_key = { label : string ; metadata : expression Option . t } |
type rewriter = | Duration of measurement_key * location | Duration_lwt of measurement_key * location | Timestamp_pre of measurement_key * location | Flush of location |
type rewriter_constants = { fn_name : string ; attribute_name : string } |
let duration key loc = Duration ( key , loc ) |
let duration_lwt key loc = Duration_lwt ( key , loc ) |
let timestamp_pre key loc = Timestamp_pre ( key , loc ) |
let flush loc = Flush loc |
let create_rewriter_constants fn_name = let namespaced name = " time " ^ " . " ^ name in { fn_name ; attribute_name = namespaced fn_name } |
let duration_constants = create_rewriter_constants " duration " |
let duration_lwt_constants = create_rewriter_constants " duration_lwt " |
let timestamp_pre_constants = create_rewriter_constants " timestamp_pre " |
let flush_constants = create_rewriter_constants " flush " |
let attribute_names = [ duration_constants . attribute_name ; duration_lwt_constants . attribute_name ; timestamp_pre_constants . attribute_name ; flush_constants . attribute_name ; ] |
let constants_of_rewriter = function | Duration _ -> duration_constants | Duration_lwt _ -> duration_lwt_constants | Timestamp_pre _ -> timestamp_pre_constants | Flush _ -> flush_constants |
let labeled_rewriter_of_attr_name name = if name = duration_constants . attribute_name then Some duration else if name = duration_lwt_constants . attribute_name then Some duration_lwt else if name = timestamp_pre_constants . attribute_name then Some timestamp_pre else None |
let locaction_of_rewriter = function | Duration ( _ , loc ) -> loc | Duration_lwt ( _ , loc ) -> loc | Timestamp_pre ( _ , loc ) -> loc | Flush loc -> loc |
let error loc err = let open Format in let ( msg , hint ) = match err with | ` Too_many_Detection attribute_name -> ( sprintf " Attribute [ @% s ] detected several times on the same expression . " attribute_name , sprintf " A same expression can only be annotated once with [ @% s ] att... |
let get_attribute_name attribute = attribute . attr_name . txt |
let has_attribute_name attribute name = get_attribute_name attribute = name |
let filter_attribute_with_name name = List . filter ( fun attr -> not @@ has_attribute_name attr name ) |
let filter_attribute_with_names names attributes = List . fold_left ( fun filtered name -> filter_attribute_with_name name filtered ) attributes names |
let fresh_identifier = let counter = ref 0 in fun prefix -> let fresh = prefix ^ string_of_int ! counter in counter := ! counter + 1 ; fresh |
let key_of_payload loc = function | PStr [ [ % stri [ % e ? { pexp_desc = Pexp_ident { txt = Lident label ; _ } ; _ } ] ] ] -> { label ; metadata = None } Tezos_time_measurement_runtime . Default . Time_measurement . duration ( " fun_app " , [ ] ) ( fun ( ... |
let check_empty_payload loc = function | PStr [ ] -> ( ) | _ -> error loc ` Non_empty_payload |
let rewriter_of_attribute ( { attr_payload ; attr_loc ; _ } as attribute ) = match get_attribute_name attribute |> labeled_rewriter_of_attr_name with | Some rwt -> let label = key_of_payload attr_loc attr_payload in Some ( rwt label attr_loc ) | None -> if has_attribute_name attribute flush_cons... |
let extract_rewriters = List . filter_map rewriter_of_attribute |
let validate_rewriters rewriters = let duration_flag = ref false in let duration_lwt_flag = ref false in let timestamp_flag = ref false in let flush_flag = ref false in let check_visited flag name loc = if ! flag then error loc ( ` Too_many_Detection name ) else flag := true in let flag_of_rewriter = fun... |
let argument_of_key key loc = let label = Ast_helper . ( Exp . constant @@ Const . string key . label ) in let metadata = match key . metadata with Some expr -> expr | None -> [ % expr [ ] ] in [ % expr [ % e label ] , [ % e metadata ] ] |
let ldot_of_non_empty_list ( x , xs ) = List . fold_left ( fun acc ident -> Ldot ( acc , ident ) ) ( Lident x ) xs |
let time_measurement_longident name = ldot_of_non_empty_list ( " Tezos_time_measurement_runtime " , [ " Default " ; " Time_measurement " ; name ] ) |
let wrap_with_labelled_call expr loc key fn = let open Ast_helper in let fn_longident = time_measurement_longident fn in let fexpr = Exp . ident @@ { txt = fn_longident ; loc } in let last_arg = [ % expr fun ( ) -> [ % e expr ] ] in let args = [ ( Nolabel , argument_of_key key loc ) ... |
let bind_with_flush_call expr loc = let open Ast_helper in let identifier = fresh_identifier " __flush__id__ " in let id_pattern = Pat . var { txt = identifier ; loc } in let id_expr = Exp . ident { txt = Lident identifier ; loc } in [ % expr [ % e expr ] >>= fun [ % p id_pattern ... |
let rewrite rewriters initial_expr = let loc = initial_expr . pexp_loc in validate_rewriters rewriters ; List . fold_left ( fun expr rewriter -> let { fn_name ; _ } = constants_of_rewriter rewriter in match rewriter with | Duration ( key , _ ) | Duration_lwt ( key , _ ) | Timestamp_p... |
let remove_attributes expr = { expr with pexp_attributes = filter_attribute_with_names attribute_names expr . pexp_attributes ; } |
let mapper = object inherit Ast_traverse . map as super method ! expression e = let detected_rewriters = extract_rewriters e . pexp_attributes in remove_attributes e |> rewrite detected_rewriters |> super # expression end |
let ( ) = Driver . register_transformation " time_measurement " ~ impl : mapper # structure |
let ( ) = register_error_kind ` Permanent ~ id " : timestamp_add " ~ title " : Timestamp add " ~ description " : Overflow when adding timestamps . " ~ pp ( : fun ppf ( ) -> Format . fprintf ppf " Overflow when adding timestamps . " ) Data_encoding . empty ( function Tim... |
let of_seconds_string s = Option . map Time . of_seconds ( Int64 . of_string_opt s ) |
let to_seconds_string s = Int64 . to_string ( to_seconds s ) |
let ( +? ) x y = let span = Period_repr . to_seconds y in let t64 = Time . add x span in if x < Time . of_seconds 0L then ok t64 else if t64 < Time . of_seconds 0L then error Timestamp_add else ok t64 |
let ( -? ) x y = record_trace Timestamp_sub ( Period_repr . of_seconds ( Time . diff x y ) ) |
let ( - ) x y = Time . of_seconds Int64 . ( sub ( Time . to_seconds x ) ( Period_repr . to_seconds y ) ) |
let ( >>> ) = upon |
module T1 = struct include Synchronous_time_source0 . T1 let sexp_of_t _ { id = _ ; advance_errors = _ ; am_advancing = _ ; events ; fired_events = _ ; handle_fired = _ ; is_wall_clock ; most_recently_fired = _ ; scheduler = _ } = if is_wall_clock then [ % message " < wall_c... |
module Read_write = struct type t = read_write T1 . t [ @@ deriving sexp_of ] let invariant = invariant let invariant_with_jobs = invariant_with_jobs end |
type t = read T1 . t [ @@ deriving sexp_of ] |
let read_only ( t : [ > read ] T1 . t ) = ( t :> t ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.