// Ġ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 . internal . statistic Ċ Ċ import Ġcom . intellij . internal . statistic . event Log . Feature Usage Data Ċ import Ġcom . intellij . internal . statistic . event Log . f us . Feature Usage Logger Ċ import Ġcom . intellij . internal . statistic . service . f us . collect ors . FU Counter Usage Logger Ċ import Ġcom . intellij . openapi . application . Application Manager Ċ import Ġcom . intellij . openapi . application . constraints . is Disposed Ċ import Ġcom . intellij . openapi . diagnostic . Logger Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġcom . intellij . openapi . util . Dis poser Ċ import Ġcom . intellij . util . Alarm Ċ import Ġcom . intellij . util . Single Alarm Ċ import Ġjava . util . concurrent . atomic . Atomic Integer Ċ import Ġjava . util . function . Consumer Ċ Ċ private Ġval ĠLOG Ġ= ĠLogger . getInstance ("# com . intellij . internal . statistic . Ide Activity ") Ċ Ċ private Ġenum Ġclass ĠState Ġ{ ĠNOT _ STARTED , ĠSTART ED , ĠFIN ISHED Ġ} Ċ Ċ class ĠIde Activity Ġ@ Jvm Over loads Ġconstructor ( private Ġval Ġproject OrNull For Application : ĠProject ?, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġgroup : ĠString , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġactivity Name : ĠString ? Ġ= Ġnull ) Ġ{ ĊĠ Ġprivate Ġval Ġid Ġ= Ġcounter . increment AndGet () ĊĊĠ Ġprivate Ġvar Ġstate Ġ= ĠState . NOT _ STARTED ĊĊĠ Ġprivate Ġfun Ġcreate Data With Activity Id (): ĠFeature Usage Data Ġ{ ĊĠĠĠ Ġreturn ĠFeature Usage Data (). addData (" ide _ activity _ id ", Ġid ) ĊĠ Ġ} ĊĊĠ Ġfun Ġstarted (): ĠIde Activity Ġ{ ĊĠĠĠ Ġreturn Ġstarted WithData ( Consumer Ġ{ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġstarted WithData ( consumer : ĠConsumer < Feature Usage Data >): ĠIde Activity Ġ{ ĊĠĠĠ ĠLOG . assertTrue ( state Ġ== ĠState . NOT _ STARTED , Ġstate . name ) ĊĠĠĠ Ġstate Ġ= ĠState . STARTED ĊĊĠĠĠ Ġval Ġdata Ġ= Ġcreate Data With Activity Id (). add Project ( project OrNull For Application ) ĊĠĠĠ Ġconsumer . accept ( data ) ĊĊĠĠĠ ĠF U Counter Usage Logger . getInstance (). log Event ( group , Ġappend Activity Name (" started "), Ġdata ) ĊĠĠĠ Ġreturn Ġthis ĊĠ Ġ} ĊĊĠ Ġfun Ġstage Started ( stage Name : ĠString ): ĠIde Activity Ġ{ ĊĠĠĠ ĠLOG . assertTrue ( state Ġ== ĠState . STARTED , Ġstate . name ) ĊĠĠĠ ĠF U Counter Usage Logger . getInstance (). log Event ( group , Ġappend Activity Name ( stage Name ), Ġcreate Data With Activity Id ()) ĊĠĠĠ Ġreturn Ġthis ĊĠ Ġ} ĊĊĠ Ġfun Ġstage Started ( stage Class : ĠClass < *> ): ĠIde Activity Ġ{ ĊĠĠĠ ĠLOG . assertTrue ( state Ġ== ĠState . STARTED , Ġstate . name ) ĊĠĠĠ Ġval Ġdata Ġ= Ġcreate Data With Activity Id (). addData (" stage _ class ", Ġstage Class . name ) ĊĠĠĠ ĠF U Counter Usage Logger . getInstance (). log Event ( group , Ġappend Activity Name (" stage "), Ġdata ) ĊĠĠĠ Ġreturn Ġthis ĊĠ Ġ} ĊĊĠ Ġfun Ġfinished (): ĠIde Activity Ġ{ ĊĠĠĠ ĠLOG . assertTrue ( state Ġ== ĠState . STARTED , Ġstate . name ) ĊĠĠĠ Ġstate Ġ= ĠState . FINISHED ĊĠĠĠ ĠF U Counter Usage Logger . getInstance (). log Event ( group , Ġappend Activity Name (" finished "), Ġcreate Data With Activity Id ()) ĊĠĠĠ Ġreturn Ġthis ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġappend Activity Name ( state : ĠString ): ĠString Ġ{ ĊĠĠĠ Ġif Ġ( activity Name Ġ== Ġnull ) Ġreturn Ġstate ĊĠĠĠ Ġreturn Ġ"$ activity Name .$ state " ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġprivate Ġval Ġcounter Ġ= ĠAtomicInteger ( 0 ) ĊĊĠĠĠ Ġ@ Jvm Static ĊĠĠĠ Ġ@ Jvm Over loads ĊĠĠĠ Ġfun Ġstarted ( project OrNull For Application : ĠProject ?, Ġgroup : ĠString , Ġactivity Name : ĠString ? Ġ= Ġnull ): ĠIde Activity Ġ= ĊĠĠĠĠĠ ĠIde Activity ( project OrNull For Application , Ġgroup , Ġactivity Name ). started () ĊĠ Ġ} Ċ } Ċ Ċ class ĠDelay ed Ide Activity Ġ@ Jvm Over loads Ġconstructor ( val Ġgroup : ĠString , Ġval Ġactivity Name : ĠString ? Ġ= Ġnull ) Ġ{ ĊĠ Ġprivate Ġval Ġdis posable Ġ= ĠDis poser . new Disposable () ĊĠ Ġprivate Ġvar Ġactivity : ĠIde Activity ? Ġ= Ġnull ĊĊĠ Ġprivate Ġvar Ġstate Ġ= ĠState . NOT _ STARTED ; ĊĊĠ Ġfun Ġstarted () Ġ: ĠDelay ed Ide Activity Ġ{ ĊĠĠĠ Ġsynchronized ( this ) Ġ{ ĊĠĠĠĠĠ ĠLOG . assertTrue ( state Ġ== ĠState . NOT _ STARTED , Ġstate . name ) ĊĠĠĠĠĠ Ġstate Ġ= ĠState . STARTED ; ĊĊĠĠĠĠĠ Ġif Ġ( Feature Usage Logger . getConfig (). is Record Enabled ()) Ġ{ Ġ// Ġavoid Ġunnecessary Ġwork , Ġwhen Ġdisabled ĊĠĠĠĠĠĠĠ Ġval Ġdelay Ġ= Ġ 1 0 0 0 ĊĊĠĠĠĠĠĠĠ Ġval Ġapplication Ġ= ĠApplication Manager . getApplication () ĊĠĠĠĠĠĠĠ Ġapplication . run Read Action Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ( application . is Disposed ) Ġreturn @ run Read Action ĊĊĠĠĠĠĠĠĠĠĠ ĠDis poser . register ( application , Ġdis posable ) ĊĠĠĠĠĠĠĠĠĠ ĠSingle Alarm ( Runnable Ġ{ Ġdelayed Start ( delay ) Ġ}, Ġdelay , ĠAlarm . Thread ToUse . PO O LED _ THREAD , Ġdis posable ). request () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġthis ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġdelayed Start (@ Suppress (" Same Parameter Value ") Ġdelay : ĠInt ) Ġ{ ĊĠĠĠ Ġsynchronized ( this ) Ġ{ ĊĠĠĠĠĠ Ġif Ġ( dis posable . is Disposed ) Ġreturn ĊĠĠĠĠĠ Ġactivity Ġ= ĠIde Activity ( null , Ġgroup , Ġactivity Name ). started WithData ( Consumer Ġ{ Ġdata Ġ-> ĊĠĠĠĠĠĠĠ Ġdata . addData (" activity _ start _ delay ", Ġdelay ) ĊĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġfinished () Ġ: ĠDelay ed Ide Activity { ĊĠĠĠ Ġsynchronized ( this ) Ġ{ ĊĠĠĠĠĠ ĠLOG . assertTrue ( state Ġ== ĠState . STARTED , Ġstate . name ) ĊĠĠĠĠĠ Ġstate Ġ= ĠState . FINISHED ; ĊĊĠĠĠĠĠ ĠDis poser . dispose ( dis posable ) ĊĠĠĠĠĠ Ġactivity ?. finished () ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġthis ĊĠ Ġ} Ċ } Ċ