/* Ċ Ġ* ĠCopyright Ġ( c ) ĠFacebook , ĠInc . Ġand Ġits Ġaffiliates . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġcom . facebook . samples . l ith o . kotlin . logging Ċ Ċ import Ġandroid . util . Log Ċ import Ġcom . facebook . l ith o . Component Context Ċ import Ġcom . facebook . l ith o . Components Logger Ċ import Ġcom . facebook . l ith o . Framework Log Events Ċ import Ġcom . facebook . l ith o . Perf Event Ċ import Ġcom . facebook . l ith o . Tree Props Ċ import Ġjava . util . concurrent . atomic . Atomic Integer Ċ Ċ class ĠSample Components Logger Ġ: ĠComponents Logger Ġ{ ĊĠ Ġprivate Ġval Ġtag Ġ= Ġ" LIT HO SAMPLE " ĊĠ Ġprivate Ġval Ġinstance Counter : ĠAtomicInteger Ġ= ĠAtomicInteger ( 0 ) ĊĊĠ Ġoverride Ġfun Ġnew Performance Event ( c : ĠComponent Context , Ġevent Id : ĠInt ): ĠPer f Event Ġ{ ĊĠĠĠ Ġreturn ĠPer f Event Store . obtain ( eventId , Ġinstance Counter . increment AndGet ()) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġlog Perf Event ( event : ĠPer f Event ) Ġ{ ĊĠĠĠ Ġprint EventData ( event , ĠPer f Event Store . release ( event )) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġcancel Perf Event ( event : ĠPer f Event ) Ġ{ ĊĠĠĠ ĠPer f Event Store . release ( event ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġget Extra Annotations ( tree Props : ĠTree Props ): ĠMutable Map < String , ĠString > Ġ= ĊĠĠĠĠĠ Ġtree Props ?. get ( Log Context :: class . java )?. let Ġ{ Ġmutable Map Of (" log _ context " Ġto Ġ"$ it ") Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ?: Ġmutable Map Of () ĊĊĠ Ġoverride Ġfun Ġis Tracing ( log Event : ĠPer f Event ): ĠBoolean Ġ= Ġtrue ĊĊĠ Ġprivate Ġfun Ġprint EventData ( event : ĠPer f Event , Ġdata : ĠEvent Data ) Ġ{ ĊĠĠĠ Ġval Ġtotal Time Ms Ġ= Ġ( data . endTime Ns !! Ġ- Ġdata . startTime Ns ) Ġ/ Ġ( 1 0 0 0 Ġ* Ġ 1 0 0 0 f ) ĊĠĠĠ Ġvar Ġmsg Ġ= ĊĠĠĠĠĠĠĠ Ġ""" ĊĠĠĠĠĠĠĠ Ġ| --- Ġ< PER FE VENT > Ġ--- ĊĠĠĠĠĠĠĠ Ġ| type : Ġ${ getEvent Name ById ( event . marker Id )} ĊĠĠĠĠĠĠĠ Ġ| total Ġtime : Ġ${ total Time Ms . with Digits ( 2 )} ms ĊĠĠĠĠĠĠĠ Ġ""" ĊĊĠĠĠ Ġval Ġannotations Ġ= Ġformat Annotations ( data ) ĊĠĠĠ Ġif Ġ( annotations . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠ Ġmsg Ġ+= Ġ"| annotations : Ġ$ annotations \ n " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġmarkers Ġ= Ġformat Markers ( data ) ĊĠĠĠ Ġif Ġ( markers . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠ Ġmsg Ġ+= Ġ"| markers : Ġ$ markers \ n " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġmsg Ġ+= Ġ"| --- Ġ</ PER FE VENT > Ġ--- \ n " ĊĊĠĠĠ ĠLog . v ( tag , Ġmsg . trim Margin ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġformat Markers ( data : ĠEvent Data ): ĠString Ġ= ĊĠĠĠĠĠ Ġdata . get Markers (). join ToString Ġ{ ĊĠĠĠĠĠĠĠ Ġ"${ (( it . first Ġ- Ġdata . startTime Ns ) Ġ/ Ġ( 1 0 0 0 Ġ* Ġ 1 0 0 0 f )). with Digits ( 2 )} ms Ġ-> Ġ${ it . second }" ĊĠĠĠĠĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġformat Annotations ( data : ĠEvent Data ): ĠString Ġ= ĊĠĠĠĠĠ Ġdata . get Annotations (). map Ġ{ Ġ"${ it . key } =${ it . value }" Ġ}. join ToString () ĊĊĠ Ġprivate Ġfun Ġget Event Name ById (@ Framework Log Events . Log EventId Ġmarker Id : ĠInt ): ĠString Ġ= ĊĠĠĠĠĠ Ġwhen Ġ( marker Id ) Ġ{ ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ MOUNT Ġ-> Ġ" MOUNT " ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ PRE _ ALLOC ATE _ MOUNT _ CONTENT Ġ-> Ġ" PRE _ ALLOC ATE _ MOUNT _ CONTENT " ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ SECTION S _ CREATE _ NEW _ TREE Ġ-> Ġ" SECTION S _ CREATE _ NEW _ TREE " ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ SECTION S _ DATA _ DIFF _ CAL C UL ATE _ DIFF Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" SECTION S _ DATA _ DIFF _ CAL C UL ATE _ DIFF " ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ SECTION S _ GENER ATE _ CHANGE SET Ġ-> Ġ" SECTION S _ GENER ATE _ CHANGE SET " ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ SECTION S _ ON _ CREATE _ CHILD REN Ġ-> Ġ" SECTION S _ ON _ CREATE _ CHILD REN " ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ SECTION S _ SET _ ROOT Ġ-> Ġ" SECTION S _ SET _ ROOT " ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ CAL C UL ATE _ LAYOUT _ STATE Ġ-> Ġ" CAL C UL ATE _ LAYOUT _ STATE " ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ BENCH MARK _ RUN Ġ-> Ġ" EVENT _ BENCH MARK _ RUN " ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ RE SU ME _ CAL C UL ATE _ LAYOUT _ STATE Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" EVENT _ RE SU ME _ CAL C UL ATE _ LAYOUT _ STATE " ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ INIT _ RANGE Ġ-> Ġ" EVENT _ INIT _ RANGE " ĊĠĠĠĠĠĠĠ ĠFramework Log Events . EVENT _ LAYOUT _ STATE _ F UT URE _ GET _ WAIT Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" EVENT _ LAYOUT _ STATE _ F UT URE _ GET _ WAIT " ĊĠĠĠĠĠĠĠ Ġelse Ġ-> Ġ" UNKNOWN " ĊĠĠĠĠĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠFloat . with Digits ( digits : ĠInt ) Ġ= Ġ"% .${ digits } f ". format ( this ) Ċ } Ċ