1515using BuildXL . Ipc . ExternalApi ;
1616using BuildXL . Ipc . Interfaces ;
1717using BuildXL . Storage ;
18- using BuildXL . Utilities . Core ;
18+ using BuildXL . Tracing . CloudBuild ;
1919using BuildXL . Utilities . CLI ;
20+ using BuildXL . Utilities . Core ;
2021using BuildXL . Utilities . Core . Tasks ;
2122using Microsoft . VisualStudio . Services . Common ;
2223using Microsoft . VisualStudio . Services . Symbol . App . Core . Tracing ;
@@ -160,7 +161,7 @@ public sealed class SymbolDaemon : ServicePipDaemon.FinalizedByCreatorServicePip
160161 IsRequired = false ,
161162 DefaultValue = true ,
162163 } ) ;
163-
164+
164165 internal static readonly StrOption PersonalAccessTokenEnv = RegisterSymbolConfigOption ( new StrOption ( "PersonalAccessTokenEnv" )
165166 {
166167 ShortName = "patenv" ,
@@ -730,20 +731,11 @@ internal static void EnsureCommandsInitialized()
730731 /// </summary>
731732 protected override async Task < IIpcResult > DoCreateAsync ( string name = null )
732733 {
733- // TODO(olkonone): add logging
734- Request createRequestResult ;
735-
736- try
737- {
738- createRequestResult = await InternalCreateAsync ( ) ;
739- }
740- catch ( Exception e )
741- {
742- return new IpcResult ( IpcResultStatus . GenericError , e . DemystifyToString ( ) ) ;
743- }
734+ var dropCreationEvent = await HandleResultAndSendSymbolEtwEventAsync ( InternalCreateAsync ( ) ) ;
744735
745- // get and return RequestId ?
746- return IpcResult . Success ( I ( $ "Symbol request '{ RequestName } ' created (assigned request ID: '{ createRequestResult . Id } ').") ) ;
736+ return dropCreationEvent . Succeeded
737+ ? IpcResult . Success ( I ( $ "Symbol request '{ RequestName } ' created (url: '{ dropCreationEvent . DropUrl } ').") )
738+ : new IpcResult ( IpcResultStatus . GenericError , dropCreationEvent . ErrorMessage ) ;
747739 }
748740
749741 /// <summary>
@@ -777,19 +769,11 @@ private async Task<IIpcResult> AddSymbolFileAsync(SymbolFile file)
777769 /// </summary>
778770 protected override async Task < IIpcResult > DoFinalizeAsync ( )
779771 {
780- // TODO(olkonone): add logging
781- Request finalizeRequestResult ;
782-
783- try
784- {
785- finalizeRequestResult = await InternalFinalizeAsync ( ) ;
786- }
787- catch ( Exception e )
788- {
789- return new IpcResult ( IpcResultStatus . GenericError , e . DemystifyToString ( ) ) ;
790- }
772+ var dropFinalizationEvent = await HandleResultAndSendSymbolEtwEventAsync ( InternalFinalizeAsync ( ) ) ;
791773
792- return IpcResult . Success ( I ( $ "Symbol request '{ RequestName } ' finalized; the request expires on '{ finalizeRequestResult . ExpirationDate } '.") ) ;
774+ return dropFinalizationEvent . Succeeded
775+ ? IpcResult . Success ( I ( $ "Symbol request '{ RequestName } ' finalized.") )
776+ : new IpcResult ( IpcResultStatus . GenericError , dropFinalizationEvent . ErrorMessage ) ;
793777 }
794778
795779 /// <nodoc />
@@ -805,25 +789,42 @@ public override void Dispose()
805789 base . Dispose ( ) ;
806790 }
807791
808- private async Task < Request > InternalCreateAsync ( )
792+ private async Task < DropCreationEvent > InternalCreateAsync ( )
809793 {
810794 var symbolClient = await m_symbolServiceClientTask ;
811795 var result = await symbolClient . CreateAsync ( ) ;
812796
813797 Contract . Assert ( result . Status == RequestStatus . Created ) ;
814798
815- return result ;
799+ var serializedResult = SymbolRequesToString ( result ) ;
800+ m_logger . Info ( $ "CreateAsync completed:{ Environment . NewLine } { serializedResult } ") ;
801+
802+ return new DropCreationEvent ( )
803+ {
804+ Succeeded = true ,
805+ DropUrl = result . Url . ToString ( ) ,
806+ // For Symbols, expiration is set during finalization, so we are using a value we will be assigning later.
807+ DropExpirationInDays = ( int ) SymbolConfig . Retention . TotalDays ,
808+ AdditionalInformation = serializedResult
809+ } ;
816810 }
817811
818- private async Task < Request > InternalFinalizeAsync ( )
812+ private async Task < DropFinalizationEvent > InternalFinalizeAsync ( )
819813 {
820814 var symbolClient = await m_symbolServiceClientTask ;
821815 var result = await symbolClient . FinalizeAsync ( ) ;
822816
823817 Contract . Assert ( result . Status == RequestStatus . Sealed ) ;
824818 Contract . Assert ( result . ExpirationDate . HasValue ) ;
825819
826- return result ;
820+ var serializedResult = SymbolRequesToString ( result ) ;
821+ m_logger . Info ( $ "FinalizeAsync completed:{ Environment . NewLine } { serializedResult } ") ;
822+
823+ return new DropFinalizationEvent ( )
824+ {
825+ Succeeded = true ,
826+ DropUrl = result . Url . ToString ( ) ,
827+ } ;
827828 }
828829
829830 private async Task ReportStatisticsAsync ( )
@@ -870,5 +871,46 @@ private async Task ReportStatisticsAsync()
870871 m_logger . Warning ( "No stats recorded by symbol client of type " + symbolClient . GetType ( ) . Name ) ;
871872 }
872873 }
874+
875+ private async Task < T > HandleResultAndSendSymbolEtwEventAsync < T > ( Task < T > task ) where T : DropOperationBaseEvent
876+ {
877+ var sw = Stopwatch . StartNew ( ) ;
878+ T dropEvent ;
879+ try
880+ {
881+ dropEvent = await task ;
882+ }
883+ catch ( Exception e )
884+ {
885+ dropEvent = Activator . CreateInstance < T > ( ) ;
886+ dropEvent . Succeeded = false ;
887+ dropEvent . ErrorMessage = e . DemystifyToString ( ) ;
888+ // For symbols, url is something that is only defined for successful operations
889+ // (it's based on a requestId which is not available until successful execution of 'symbol create').
890+ dropEvent . DropUrl = null ;
891+ }
892+
893+ // common properties: execution time, drop type
894+ dropEvent . ElapsedTimeTicks = sw . ElapsedTicks ;
895+ dropEvent . DropType = "SymbolIndex" ;
896+
897+ // send event
898+ m_etwLogger . Log ( dropEvent ) ;
899+
900+ return dropEvent ;
901+ }
902+
903+ private static string SymbolRequesToString ( Request request )
904+ {
905+ try
906+ {
907+ return request . ToJson ( ) ;
908+ }
909+ catch ( Exception e )
910+ {
911+ // The value is only used for debugging, so it's not a big deal if we fail to create the string.
912+ return $ "Failed to serialized Request. Exception: { e } ";
913+ }
914+ }
873915 }
874916}
0 commit comments