123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120includeTypesmoduleA=Atomic_moduleCollector=CollectormoduleMeta_map=Meta_maptypecollector=(moduleCollector.S)(** Global collector. *)letcollector:collectoroptionA.t=A.makeNonelet[@inline]enabled()=matchA.getcollectorwith|None->false|Some_->trueletwith_span_collector_(moduleC:Collector.S)?__FUNCTION__~__FILE__~__LINE__?(data=fun()->[])namef=letdata=data()inC.with_span~__FUNCTION__~__FILE__~__LINE__~datanameflet[@inline]with_span?__FUNCTION__~__FILE__~__LINE__?datanamef=matchA.getcollectorwith|None->(* fast path: no collector, no span *)fCollector.dummy_span|Somecollector->with_span_collector_collector?__FUNCTION__~__FILE__~__LINE__?datanamefletenter_explicit_span_collector_(moduleC:Collector.S)~parent~flavor?__FUNCTION__~__FILE__~__LINE__?(data=fun()->[])name:explicit_span=letdata=data()inC.enter_manual_span~parent~flavor~__FUNCTION__~__FILE__~__LINE__~datanamelet[@inline]enter_manual_sub_span~parent?flavor?__FUNCTION__~__FILE__~__LINE__?dataname:explicit_span=matchA.getcollectorwith|None->Collector.dummy_explicit_span|Somecoll->enter_explicit_span_collector_coll~parent:(Someparent)~flavor?__FUNCTION__~__FILE__~__LINE__?datanamelet[@inline]enter_manual_toplevel_span?flavor?__FUNCTION__~__FILE__~__LINE__?dataname:explicit_span=matchA.getcollectorwith|None->Collector.dummy_explicit_span|Somecoll->enter_explicit_span_collector_coll~parent:None~flavor?__FUNCTION__~__FILE__~__LINE__?datanamelet[@inline]exit_manual_spanespan:unit=matchA.getcollectorwith|None->()|Some(moduleC)->C.exit_manual_spanespanletmessage_collector_(moduleC:Collector.S)?span?(data=fun()->[])msg:unit=letdata=data()inC.message?span~datamsglet[@inline]message?span?datamsg:unit=matchA.getcollectorwith|None->()|Somecoll->message_collector_coll?span?datamsgletmessagef?span?datak=matchA.getcollectorwith|None->()|Some(moduleC)->k(funfmt->Format.kasprintf(funstr->letdata=matchdatawith|None->[]|Somef->f()inC.message?span~datastr)fmt)letcounter_intnamen:unit=matchA.getcollectorwith|None->()|Some(moduleC)->C.counter_intnamenletcounter_floatnamef:unit=matchA.getcollectorwith|None->()|Some(moduleC)->C.counter_floatnamefletset_thread_namename:unit=matchA.getcollectorwith|None->()|Some(moduleC)->C.name_threadnameletset_process_namename:unit=matchA.getcollectorwith|None->()|Some(moduleC)->C.name_processnameletsetup_collectorc:unit=whileletcur=A.getcollectorinmatchcurwith|Some_->invalid_arg"trace: collector already present"|None->not(A.compare_and_setcollectorcur(Somec))do()doneletshutdown()=matchA.exchangecollectorNonewith|None->()|Some(moduleC)->C.shutdown()moduleInternal_=structmoduleAtomic_=Atomic_end