12345678910111213141516171819202122232425262728293031typecategory=Timing|Width_check|Width_recordletcategories=["timing";"width-check";"width-record"]letparse=function|"timing"->OkTiming|"width-check"->OkWidth_check|"width-record"->OkWidth_record|s->Error(Printf.sprintf"Unknown debug category: %s (expected one of: %s)"s(String.concat", "categories))(* The set of active categories, set once at startup. Mirrors the one-shot
global config used elsewhere (e.g. [Validation.validate_refs]). *)letenabled:categorylistref=ref[]letenablecategories=enabled:=categoriesletis_enabledcategory=List.memcategory!enabledlettimed_ifcondlabelf=ifnot(cond&&is_enabledTiming)thenf()elsebeginletstart=Unix.gettimeofday()inletfinally()=letelapsed=(Unix.gettimeofday()-.start)*.1000.inPrintf.eprintf"%s: %.1f ms\n%!"labelelapsedinFun.protect~finallyfendlettimedlabelf=timed_iftruelabelf