// ĠCopyright Ġ 2 0 0 0 - 2 0 1 9 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġcom . intellij . stats Ċ Ċ import Ġjava . util . concurrent . Concurrent HashMap Ċ import Ġjava . util . concurrent . TimeUnit Ċ import Ġjava . util . concurrent . atomic . Long Ad der Ċ Ċ class ĠPerformance Tracker Ġ{ ĊĠ Ġprivate Ġvar Ġsorting Count Ġ= Ġ 0 ĊĊĠ Ġprivate Ġval Ġmeasures : ĠConcurrent HashMap < String , ĠLong Ad der > Ġ= ĠConcurrent HashMap () ĊĠ Ġprivate Ġval Ġelement Providers Meas urer : ĠConcurrent HashMap < String , ĠLong Ad der > Ġ= ĠConcurrent HashMap () ĊĊĠ Ġprivate Ġvar Ġtotal Ml Contribution : ĠLong Ġ= Ġ 0 L ĊĊĠ Ġfun Ġtotal ML Time Contribution (): ĠLong Ġ= Ġtotal Ml Contribution ĊĊĠ Ġfun Ġsorting Performed ( items Count : ĠInt , Ġtotal Time : ĠLong ) Ġ{ ĊĠĠĠ Ġadd ByKey (" sorting . items .$ sorting Count ", Ġitems Count . to Long ()) ĊĠĠĠ Ġadd ByKey (" sorting . time .$ sorting Count ", Ġtotal Time ) ĊĠĠĠ Ġtotal Ml Contribution Ġ+= Ġtotal Time ĊĠĠĠ Ġsorting Count Ġ+= Ġ 1 ĊĠ Ġ} ĊĊĠ Ġfun Ġevent Logged ( eventType : ĠString , Ġtime Sp ent : ĠLong ) Ġ{ ĊĠĠĠ Ġadd ByKey (" log .$ eventType ", Ġtime Sp ent ) ĊĠĠĠ Ġadd ByKey (" log . total ", Ġtime Sp ent ) ĊĠ Ġ} ĊĊĠ Ġfun Ġcontext Features Calculated ( provider Name : ĠString , Ġtime Sp ent : ĠLong ) Ġ{ ĊĠĠĠ Ġadd ByKey (" context . features .$ provider Name ", Ġtime Sp ent ) ĊĠ Ġ} ĊĊĠ Ġfun Ġitems S cored ( items Count : ĠInt , Ġtime Sp ent : ĠLong ) Ġ{ ĊĠĠĠ Ġadd ByKey (" model . items .$ sorting Count ", Ġitems Count . to Long ()) ĊĠĠĠ Ġadd ByKey (" model . time .$ sorting Count ", Ġtime Sp ent ) ĊĠ Ġ} ĊĊĠ Ġfun Ġreordered By ML () Ġ{ ĊĠĠĠ Ġadd ByKey (" reordered . by . ml ", Ġ 1 ) ĊĠ Ġ} ĊĊĠ Ġfun Ġmeasurements (): ĠMap < String , ĠLong > Ġ{ ĊĠĠĠ Ġflush Element Providers Contribution () ĊĠĠĠ Ġreturn Ġmeasures . map Values Ġ{ Ġit . value . to Long () Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġ< T > Ġtrack Element Features Calculation ( provider Name : ĠString , Ġcompute : Ġ() Ġ-> ĠT ): ĠT Ġ{ ĊĠĠĠ Ġval Ġstarted Ġ= ĠSystem . nano Time () ĊĠĠĠ Ġval Ġresult Ġ= Ġcompute () ĊĠĠĠ Ġelement Providers Meas urer . compute If Absent ( provider Name ) Ġ{ ĠLong Ad der () Ġ}. add ( System . nano Time () Ġ- Ġstarted ) ĊĠĠĠ Ġreturn Ġresult ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġflush Element Providers Contribution () Ġ{ ĊĠĠĠ Ġelement Providers Meas urer . forEach Ġ{ Ġadd ByKey (" element . features .${ it . key }", ĠTimeUnit . NAN O SECONDS . to Millis ( it . value . to Long ())) Ġ} ĊĠĠĠ Ġelement Providers Meas urer . clear () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġadd ByKey ( key : ĠString , Ġvalue : ĠLong ) Ġ{ ĊĠĠĠ Ġif Ġ( value Ġ!= Ġ 0 L ) Ġ{ ĊĠĠĠĠĠ Ġmeasures . compute If Absent ( key ) Ġ{ ĠLong Ad der () Ġ}. add ( value ) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ }