12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091(**************************************************************************)(* *)(* OCaml *)(* *)(* Mark Shinwell and Leo White, Jane Street Europe *)(* *)(* Copyright 2015--2016 Jane Street Group LLC *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)externalspacetime_enabled:unit->bool="caml_spacetime_enabled"[@@noalloc]letenabled=spacetime_enabled()letif_spacetime_enabledf=ifenabledthenf()else()moduleSeries=structtypet={channel:out_channel;mutableclosed:bool;}externalwrite_magic_number:out_channel->unit="caml_spacetime_only_works_for_native_code""caml_spacetime_write_magic_number"externalregister_channel_for_spacetime:out_channel->unit="caml_register_channel_for_spacetime"letcreate~path=ifspacetime_enabled()thenbeginletchannel=open_outpathinregister_channel_for_spacetimechannel;lett={channel=channel;closed=false;}inwrite_magic_numbert.channel;tendelsebegin{channel=stdout;(* arbitrary value *)closed=true;}endexternalsave_event:?time:float->out_channel->event_name:string->unit="caml_spacetime_only_works_for_native_code""caml_spacetime_save_event"letsave_event?timet~event_name=if_spacetime_enabled(fun()->save_event?timet.channel~event_name)externalsave_trie:?time:float->out_channel->unit="caml_spacetime_only_works_for_native_code""caml_spacetime_save_trie"letsave_and_close?timet=if_spacetime_enabled(fun()->ift.closedthenfailwith"Series is closed";save_trie?timet.channel;close_outt.channel;t.closed<-true)endmoduleSnapshot=structexternaltake:?time:float->out_channel->unit="caml_spacetime_only_works_for_native_code""caml_spacetime_take_snapshot"lettake?time{Series.closed;channel}=if_spacetime_enabled(fun()->ifclosedthenfailwith"Series is closed";Gc.minor();take?timechannel)endexternalsave_event_for_automatic_snapshots:event_name:string->unit="caml_spacetime_only_works_for_native_code""caml_spacetime_save_event_for_automatic_snapshots"letsave_event_for_automatic_snapshots~event_name=if_spacetime_enabled(fun()->save_event_for_automatic_snapshots~event_name)