Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file counter.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385(******************************************************************************)(* _ __ * The Kappa Language *)(* | |/ / * Copyright 2010-2020 CNRS - Harvard Medical School - INRIA - IRIF *)(* | ' / *********************************************************************)(* | . \ * This file is distributed under the terms of the *)(* |_|\_\ * GNU Lesser General Public License Version 3 *)(******************************************************************************)moduleEfficiency:sigtypet={consecutive:intarray;mutableconsecutive_blocked:int;mutableno_more_binary:int;mutableno_more_unary:int;mutableclashing_instance:int;mutabletime_correction:int;}valinit:int->tvalnb:t->intvalnb_consecutive:rule_id:int->t->intvalnb_consecutive_blocked:t->intvalprint_detail:current_event:int->Format.formatter->t->unitvalreset_consecutive:rule_id:int->t->tvalreset_consecutive_blocked:t->tvalincr_no_more_binary:rule_id:int->t->tvalincr_no_more_unary:rule_id:int->t->tvalincr_clashing_instance:rule_id:int->t->tvalincr_time_correction:t->tvalincr_consecutive_blocked:t->tvalwrite_t:Buffer.t->t->unitvalstring_of_t:?len:int->t->stringvalread_t:Yojson.Safe.lexer_state->Lexing.lexbuf->tvalt_of_string:string->tend=structtypet={consecutive:intarray;mutableconsecutive_blocked:int;mutableno_more_binary:int;mutableno_more_unary:int;mutableclashing_instance:int;mutabletime_correction:int;}letinitsize={consecutive=Array.makesize0;consecutive_blocked=0;no_more_binary=0;no_more_unary=0;clashing_instance=0;time_correction=0;}letnbt=t.no_more_binary+t.no_more_unary+t.clashing_instance+t.time_correctionletnb_consecutive~rule_idt=t.consecutive.(rule_id)letnb_consecutive_blockedt=t.consecutive_blockedletreset_consecutive~rule_idt=let()=t.consecutive.(rule_id)<-0intletreset_consecutive_blockedt=let()=t.consecutive_blocked<-0intletincr_consecutive_blockedt=let()=t.consecutive_blocked<-succt.consecutive_blockedintletincr_no_more_binary~rule_idt=let()=t.no_more_binary<-succt.no_more_binaryinlet()=t.consecutive.(rule_id)<-succt.consecutive.(rule_id)intletincr_no_more_unary~rule_idt=let()=t.no_more_unary<-succt.no_more_unaryinlet()=t.consecutive.(rule_id)<-succt.consecutive.(rule_id)intletincr_clashing_instance~rule_idt=let()=t.clashing_instance<-succt.clashing_instanceinlet()=t.consecutive.(rule_id)<-succt.consecutive.(rule_id)intletincr_time_correctiont=let()=t.time_correction<-succt.time_correctionintletprint_detail~current_eventft=letall=float_of_int(nbt)inletevents=float_of_intcurrent_eventinlet()=Format.pp_open_vboxf0inlet()=ifall>0.thenFormat.fprintff"@[%.2f%% of event loops were productive.@ Null event cause:@]@,"(100.*.events/.(all+.events))inlet()=ift.no_more_unary>0thenFormat.fprintff"\tValid embedding but no longer unary when required: %.2f%%@,"(100.*.float_of_intt.no_more_unary/.all)inlet()=ift.no_more_binary>0thenFormat.fprintff"\tValid embedding but not binary when required: %.2f%%@,"(100.*.float_of_intt.no_more_binary/.all)inlet()=ift.clashing_instance>0thenFormat.fprintff"\tClashing instance: %.2f%%@,"(100.*.float_of_intt.clashing_instance/.all)inlet()=ift.time_correction>0thenFormat.fprintff"\tPerturbation interrupting time advance: %.2f%%@,"(100.*.float_of_intt.time_correction/.all)inFormat.fprintff"@]"letto_yojsont=`Assoc["consecutive",JsonUtil.of_arrayJsonUtil.of_intt.consecutive;"consecutive_blocked",`Intt.consecutive_blocked;"no_more_binary",`Intt.no_more_binary;"no_more_unary",`Intt.no_more_unary;"clashing_instance",`Intt.clashing_instance;"time_correction",`Intt.time_correction;]letof_yojson=function|`AssoclasxwhenList.lengthl=6->{consecutive=(JsonUtil.to_arrayYojson.Basic.Util.to_int)(Yojson.Basic.Util.member"consecutive"x);consecutive_blocked=Yojson.Basic.Util.to_int(Yojson.Basic.Util.member"consecutive_blocked"x);no_more_binary=Yojson.Basic.Util.to_int(Yojson.Basic.Util.member"no_more_binary"x);no_more_unary=Yojson.Basic.Util.to_int(Yojson.Basic.Util.member"no_more_unary"x);clashing_instance=Yojson.Basic.Util.to_int(Yojson.Basic.Util.member"clashing_instance"x);time_correction=Yojson.Basic.Util.to_int(Yojson.Basic.Util.member"time_correction"x);}|x->raise(Yojson.Basic.Util.Type_error("Invalid simulation efficiency",x))letwrite_tobf=Yojson.Basic.to_bufferob(to_yojsonf)letstring_of_t?(len=1024)x=letob=Buffer.createleninwrite_tobx;Buffer.contentsobletread_tplb=of_yojson(Yojson.Basic.from_lexbuf~stream:trueplb)lett_of_strings=read_t(Yojson.Safe.init_lexer())(Lexing.from_strings)endtypet={mutabletime:float;mutableevents:int;mutablestories:int;mutablelast_point:int;mutablestat_null:Efficiency.t;init_time:float;init_event:int;mutableplot_period:Configuration.period;mutablemax_time:floatoption;mutablemax_event:intoption;}letcurrent_storyc=c.storiesletcurrent_timec=c.timeletcurrent_eventc=c.eventsletnb_null_eventc=Efficiency.nbc.stat_nullletconsecutive_null_event~rule_idc=Efficiency.nb_consecutive~rule_idc.stat_nullletconsecutive_blockedc=Efficiency.nb_consecutive_blockedc.stat_nullletinc_storiesc=c.stories<-c.stories+1letinc_eventsc=c.events<-c.events+1letcheck_timec=matchc.max_timewith|None->true|Somemax->c.time<=maxletcheck_output_timecot=matchc.max_timewith|None->true|Somemax->ot<=maxletcheck_eventsc=matchc.max_eventwith|None->true|Somemax->c.events<maxletone_time_advancecdt=let()=c.time<-c.time+.dtincheck_timecletone_constructive_event~rule_idc=let()=c.stat_null<-Efficiency.reset_consecutive~rule_idc.stat_nullinlet()=c.stat_null<-Efficiency.reset_consecutive_blockedc.stat_nullinlet()=inc_eventscincheck_timec&&check_eventscletone_no_more_binary_event~rule_idc=let()=c.stat_null<-Efficiency.incr_no_more_binary~rule_idc.stat_nullincheck_timec&&check_eventscletone_no_more_unary_event~rule_idc=let()=c.stat_null<-Efficiency.incr_no_more_unary~rule_idc.stat_nullincheck_timec&&check_eventscletone_clashing_instance_event~rule_idc=let()=c.stat_null<-Efficiency.incr_clashing_instance~rule_idc.stat_nullincheck_timec&&check_eventscletone_time_correction_event?tic=matchOption_util.bindNbr.to_floattiwith|None->false|Someti->let()=c.time<-tiinlet()=c.stat_null<-Efficiency.incr_time_correctionc.stat_nullincheck_timec&&check_eventscletone_blocked_eventc=let()=c.stat_null<-Efficiency.incr_consecutive_blockedc.stat_nullincheck_timec&&check_eventscletget_efficiencyc=c.stat_nullletprint_efficiencyfc=Efficiency.print_detail~current_event:(current_eventc)fc.stat_nullletinit_timec=c.init_timeletmax_timec=c.max_timeletmax_eventsc=c.max_eventletplot_periodc=c.plot_periodlettime_ratiot=matcht.max_timewith|None->None|Sometmax->iftmax>t.init_timethenSome((t.time-.t.init_time)/.(tmax-.t.init_time))elseNoneletevent_ratiot=matcht.max_eventwith|None->None|Someemax->ifemax=0thenNoneelseSome(float_of_int(t.events-t.init_event)/.float_of_int(emax-t.init_event))letset_max_timect=c.max_time<-tletset_max_eventsce=c.max_event<-elettracked_events(counter:t):intoption=ifcounter.stories>=0thenSomecounter.storieselseNoneletset_plot_period(t:t)plot_period:unit=t.plot_period<-plot_periodletcreate?(init_t=0.)?(init_e=0)?max_time?max_event~plot_period~nb_rules()={time=init_t;events=init_e;stories=-1;stat_null=Efficiency.initnb_rules;plot_period;init_time=init_t;init_event=init_e;max_time;max_event;last_point=0;}letreinitializecounter=counter.time<-counter.init_time;counter.events<-counter.init_event;counter.stories<--1;counter.last_point<-0;counter.stat_null<-Efficiency.init(Array.lengthcounter.stat_null.Efficiency.consecutive)letnext_step_simulation_infoc={Trace.Simulation_info.story_id=current_storyc;Trace.Simulation_info.story_time=current_timec;Trace.Simulation_info.story_event=current_eventc+1;Trace.Simulation_info.profiling_info=();}letcurrent_simulation_infoc={Trace.Simulation_info.story_id=current_storyc;Trace.Simulation_info.story_time=current_timec;Trace.Simulation_info.story_event=current_eventc;Trace.Simulation_info.profiling_info=();}letnext_storyc=let()=inc_storiescinnext_step_simulation_infocletpositive_plot_periodcounter=matchplot_periodcounterwith|Configuration.DEe->e>0|Configuration.DTt->t>0.letnext_pointcounterdt=matchcounter.plot_periodwith|Configuration.DTdT->ifdT<=0.then0elseint_of_float((min(Option_util.unsomeinfinity(max_timecounter))(dt+.current_timecounter)-.counter.init_time)/.dT)|Configuration.DEdE->ifdE<=0then0else(current_eventcounter-counter.init_event)/dEletto_plot_pointscounterdt=letnext=next_pointcounterdtinletlast=counter.last_pointinlet()=counter.last_point<-nextinletn=next-lastinmatchcounter.plot_periodwith|Configuration.DTdT->(snd(Tools.recti(fun(time,acc)_->(time-.dT,ifcheck_output_timecountertimethentime::accelseacc))(counter.init_time+.(float_of_intnext*.dT),[])n),counter)|Configuration.DE_->ifn=1then[counter.time],counterelseifn=0then[],counterelseinvalid_arg("Counter.to_plot_points: invalid increment "^string_of_intn)letfill~outputscounter~dt=letpoints,counter'=to_plot_pointscounterdtinList.iter(funtime->outputscounter'time)pointsletfake_timettime={twithtime}