@@ -54,7 +54,7 @@ private static void ConsoleWriteLine(string str)
5454        /// <param name="stoppingEventPayloadFilter">A string, parsed as [payload_field_name]:[payload_field_value] pairs separated by commas, that will stop the trace upon hitting an event with a matching payload. Requires `--stopping-event-provider-name` and `--stopping-event-event-name` to be set.</param> 
5555        /// <param name="rundown">Collect rundown events.</param> 
5656        /// <returns></returns> 
57-         private  static async  Task < int >  Collect ( CancellationToken  ct ,  CommandLineConfiguration  cliConfig ,  int  processId ,  FileInfo  output ,  uint  buffersize ,  string  providers ,  string  profile ,  TraceFileFormat  format ,  TimeSpan  duration ,  string  clrevents ,  string  clreventlevel ,  string  name ,  string  diagnosticPort ,  bool  showchildio ,  bool  resumeRuntime ,  string  stoppingEventProviderName ,  string  stoppingEventEventName ,  string  stoppingEventPayloadFilter ,  bool ?  rundown ,  string  dsrouter ) 
57+         private  static async  Task < int >  Collect ( CancellationToken  ct ,  CommandLineConfiguration  cliConfig ,  int  processId ,  FileInfo  output ,  uint  buffersize ,  string [ ]  providers ,  string [ ]  profile ,  TraceFileFormat  format ,  TimeSpan  duration ,  string  clrevents ,  string  clreventlevel ,  string  name ,  string  diagnosticPort ,  bool  showchildio ,  bool  resumeRuntime ,  string  stoppingEventProviderName ,  string  stoppingEventEventName ,  string  stoppingEventPayloadFilter ,  bool ?  rundown ,  string  dsrouter ) 
5858        { 
5959            bool  collectionStopped  =  false ; 
6060            bool  cancelOnEnter  =  true ; 
@@ -111,34 +111,35 @@ private static async Task<int> Collect(CancellationToken ct, CommandLineConfigur
111111                if  ( profile . Length  ==  0  &&  providers . Length  ==  0  &&  clrevents . Length  ==  0 ) 
112112                { 
113113                    ConsoleWriteLine ( "No profile or providers specified, defaulting to trace profile 'dotnet-common'" ) ; 
114-                     profile  =  "dotnet-common" ; 
114+                     profile  =  new [ ]   {   "dotnet-common"   } ; 
115115                } 
116116
117-                 Dictionary < string ,  string >  enabledBy  =  new ( ) ; 
118- 
119-                 List < EventPipeProvider >  providerCollection  =  ProviderUtils . ToProviders ( providers ) ; 
120-                 foreach  ( EventPipeProvider  providerCollectionProvider  in  providerCollection ) 
121-                 { 
122-                     enabledBy [ providerCollectionProvider . Name ]  =  "--providers " ; 
123-                 } 
124- 
125-                 long  rundownKeyword  =  EventPipeSession . DefaultRundownKeyword ; 
117+                 long  rundownKeyword  =  0 ; 
126118                RetryStrategy  retryStrategy  =  RetryStrategy . NothingToRetry ; 
127119
128120                if  ( profile . Length  !=  0 ) 
129121                { 
130-                     Profile  selectedProfile  =  ListProfilesCommandHandler . DotNETRuntimeProfiles 
131-                         . FirstOrDefault ( p =>  p . Name . Equals ( profile ,  StringComparison . OrdinalIgnoreCase ) ) ; 
132-                     if  ( selectedProfile  ==  null ) 
122+                     foreach  ( string  prof  in  profile ) 
133123                    { 
134-                         Console . Error . WriteLine ( $ "Invalid profile name: { profile } ") ; 
135-                         return  ( int ) ReturnCode . ArgumentError ; 
136-                     } 
124+                         Profile  selectedProfile  =  ListProfilesCommandHandler . DotNETRuntimeProfiles 
125+                             . FirstOrDefault ( p =>  p . Name . Equals ( prof ,  StringComparison . OrdinalIgnoreCase ) ) ; 
126+                         if  ( selectedProfile  ==  null ) 
127+                         { 
128+                             Console . Error . WriteLine ( $ "Invalid profile name: { prof } ") ; 
129+                             return  ( int ) ReturnCode . ArgumentError ; 
130+                         } 
137131
138-                     rundownKeyword  =  selectedProfile . RundownKeyword ; 
139-                     retryStrategy  =  selectedProfile . RetryStrategy ; 
132+                         rundownKeyword  |=  selectedProfile . RundownKeyword ; 
133+                         if  ( selectedProfile . RetryStrategy  >  retryStrategy ) 
134+                         { 
135+                             retryStrategy  =  selectedProfile . RetryStrategy ; 
136+                         } 
137+                     } 
138+                 } 
140139
141-                     ProviderUtils . MergeProfileAndProviders ( selectedProfile ,  providerCollection ,  enabledBy ) ; 
140+                 if  ( rundownKeyword  ==  0 ) 
141+                 { 
142+                     rundownKeyword  =  EventPipeSession . DefaultRundownKeyword ; 
142143                } 
143144
144145                if  ( rundown . HasValue ) 
@@ -155,31 +156,13 @@ private static async Task<int> Collect(CancellationToken ct, CommandLineConfigur
155156                    } 
156157                } 
157158
158-                 // Parse --clrevents parameter 
159-                 if  ( clrevents . Length  !=  0 ) 
160-                 { 
161-                     // Ignore --clrevents if CLR event provider was already specified via --profile or --providers command. 
162-                     if  ( enabledBy . ContainsKey ( ProviderUtils . CLREventProviderName ) ) 
163-                     { 
164-                         ConsoleWriteLine ( $ "The argument --clrevents { clrevents }  will be ignored because the CLR provider was configured via either --profile or --providers command.") ; 
165-                     } 
166-                     else 
167-                     { 
168-                         EventPipeProvider  clrProvider  =  ProviderUtils . ToCLREventPipeProvider ( clrevents ,  clreventlevel ) ; 
169-                         providerCollection . Add ( clrProvider ) ; 
170-                         enabledBy [ ProviderUtils . CLREventProviderName ]  =  "--clrevents" ; 
171-                     } 
172-                 } 
173- 
174- 
159+                 List < EventPipeProvider >  providerCollection  =  ProviderUtils . ToProviders ( providers ,  clrevents ,  clreventlevel ,  profile ,  ! IsQuiet ) ; 
175160                if  ( providerCollection . Count  <=  0 ) 
176161                { 
177162                    Console . Error . WriteLine ( "No providers were specified to start a trace." ) ; 
178163                    return  ( int ) ReturnCode . ArgumentError ; 
179164                } 
180165
181-                 PrintProviders ( providerCollection ,  enabledBy ) ; 
182- 
183166                // Validate and parse stoppingEvent parameters: stoppingEventProviderName, stoppingEventEventName, stoppingEventPayloadFilter 
184167
185168                bool  hasStoppingEventProviderName  =  ! string . IsNullOrEmpty ( stoppingEventProviderName ) ; 
@@ -524,20 +507,6 @@ private static async Task<int> Collect(CancellationToken ct, CommandLineConfigur
524507            return  ret ; 
525508        } 
526509
527-         private  static void  PrintProviders ( IReadOnlyList < EventPipeProvider >  providers ,  Dictionary < string ,  string >  enabledBy ) 
528-         { 
529-             ConsoleWriteLine ( "" ) ; 
530-             ConsoleWriteLine ( string . Format ( "{0, -40}" ,  "Provider Name" )  +  string . Format ( "{0, -20}" ,  "Keywords" )  + 
531-                 string . Format ( "{0, -20}" ,  "Level" )  +  "Enabled By" ) ;   // +4 is for the tab 
532-             foreach  ( EventPipeProvider  provider  in  providers ) 
533-             { 
534-                 ConsoleWriteLine ( string . Format ( "{0, -80}" ,  $ "{ GetProviderDisplayString ( provider ) } ")  +  $ "{ enabledBy [ provider . Name ] } ") ; 
535-             } 
536-             ConsoleWriteLine ( "" ) ; 
537-         } 
538-         private  static string  GetProviderDisplayString ( EventPipeProvider  provider )  => 
539-             string . Format ( "{0, -40}" ,  provider . Name )  +  string . Format ( "0x{0, -18}" ,  $ "{ provider . Keywords : X16} ")  +  string . Format ( "{0, -8}" ,  provider . EventLevel . ToString ( )  +  $ "({ ( int ) provider . EventLevel } )") ; 
540- 
541510        private  static string  GetSize ( long  length ) 
542511        { 
543512            if  ( length  >  1e9 ) 
@@ -585,14 +554,18 @@ public static Command CollectCommand()
585554            collectCommand . TreatUnmatchedTokensAsErrors  =  false ;  // see the logic in Program.Main that handles UnmatchedTokens 
586555            collectCommand . Description  =  "Collects a diagnostic trace from a currently running process or launch a child process and trace it. Append -- to the collect command to instruct the tool to run a command and trace it immediately. When tracing a child process, the exit code of dotnet-trace shall be that of the traced process unless the trace process encounters an error." ; 
587556
588-             collectCommand . SetAction ( ( parseResult ,  ct )  =>  Collect ( 
557+             collectCommand . SetAction ( ( parseResult ,  ct )  =>  { 
558+                 string  providersValue  =  parseResult . GetValue ( CommonOptions . ProvidersOption )  ??  string . Empty ; 
559+                 string  profileValue  =  parseResult . GetValue ( CommonOptions . ProfileOption )  ??  string . Empty ; 
560+ 
561+                 return  Collect ( 
589562                ct , 
590563                cliConfig :  parseResult . Configuration , 
591564                processId :  parseResult . GetValue ( CommonOptions . ProcessIdOption ) , 
592565                output :  parseResult . GetValue ( CommonOptions . OutputPathOption ) , 
593566                buffersize :  parseResult . GetValue ( CircularBufferOption ) , 
594-                 providers :  parseResult . GetValue ( CommonOptions . ProvidersOption )   ??   string . Empty , 
595-                 profile :  parseResult . GetValue ( CommonOptions . ProfileOption )   ??   string . Empty , 
567+                 providers :  providersValue . Split ( ',' ,   StringSplitOptions . RemoveEmptyEntries   |   StringSplitOptions . TrimEntries ) , 
568+                 profile :  profileValue . Split ( ',' ,   StringSplitOptions . RemoveEmptyEntries   |   StringSplitOptions . TrimEntries ) , 
596569                format :  parseResult . GetValue ( CommonOptions . FormatOption ) , 
597570                duration :  parseResult . GetValue ( CommonOptions . DurationOption ) , 
598571                clrevents :  parseResult . GetValue ( CommonOptions . CLREventsOption )  ??  string . Empty , 
@@ -605,7 +578,8 @@ public static Command CollectCommand()
605578                stoppingEventEventName :  parseResult . GetValue ( StoppingEventEventNameOption ) , 
606579                stoppingEventPayloadFilter :  parseResult . GetValue ( StoppingEventPayloadFilterOption ) , 
607580                rundown :  parseResult . GetValue ( RundownOption ) , 
608-                 dsrouter :  parseResult . GetValue ( DSRouterOption ) ) ) ; 
581+                 dsrouter :  parseResult . GetValue ( DSRouterOption ) ) ; 
582+             } ) ; 
609583
610584            return  collectCommand ; 
611585        } 
0 commit comments