@@ -54,7 +54,7 @@ private static void ConsoleWriteLine(string str)
54
54
/// <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>
55
55
/// <param name="rundown">Collect rundown events.</param>
56
56
/// <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 )
58
58
{
59
59
bool collectionStopped = false ;
60
60
bool cancelOnEnter = true ;
@@ -111,34 +111,35 @@ private static async Task<int> Collect(CancellationToken ct, CommandLineConfigur
111
111
if ( profile . Length == 0 && providers . Length == 0 && clrevents . Length == 0 )
112
112
{
113
113
ConsoleWriteLine ( "No profile or providers specified, defaulting to trace profile 'dotnet-common'" ) ;
114
- profile = "dotnet-common" ;
114
+ profile = new [ ] { "dotnet-common" } ;
115
115
}
116
116
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 ;
126
118
RetryStrategy retryStrategy = RetryStrategy . NothingToRetry ;
127
119
128
120
if ( profile . Length != 0 )
129
121
{
130
- Profile selectedProfile = ListProfilesCommandHandler . DotNETRuntimeProfiles
131
- . FirstOrDefault ( p => p . Name . Equals ( profile , StringComparison . OrdinalIgnoreCase ) ) ;
132
- if ( selectedProfile == null )
122
+ foreach ( string prof in profile )
133
123
{
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
+ }
137
131
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
+ }
140
139
141
- ProviderUtils . MergeProfileAndProviders ( selectedProfile , providerCollection , enabledBy ) ;
140
+ if ( rundownKeyword == 0 )
141
+ {
142
+ rundownKeyword = EventPipeSession . DefaultRundownKeyword ;
142
143
}
143
144
144
145
if ( rundown . HasValue )
@@ -155,31 +156,13 @@ private static async Task<int> Collect(CancellationToken ct, CommandLineConfigur
155
156
}
156
157
}
157
158
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 ) ;
175
160
if ( providerCollection . Count <= 0 )
176
161
{
177
162
Console . Error . WriteLine ( "No providers were specified to start a trace." ) ;
178
163
return ( int ) ReturnCode . ArgumentError ;
179
164
}
180
165
181
- PrintProviders ( providerCollection , enabledBy ) ;
182
-
183
166
// Validate and parse stoppingEvent parameters: stoppingEventProviderName, stoppingEventEventName, stoppingEventPayloadFilter
184
167
185
168
bool hasStoppingEventProviderName = ! string . IsNullOrEmpty ( stoppingEventProviderName ) ;
@@ -524,20 +507,6 @@ private static async Task<int> Collect(CancellationToken ct, CommandLineConfigur
524
507
return ret ;
525
508
}
526
509
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
-
541
510
private static string GetSize ( long length )
542
511
{
543
512
if ( length > 1e9 )
@@ -585,14 +554,18 @@ public static Command CollectCommand()
585
554
collectCommand . TreatUnmatchedTokensAsErrors = false ; // see the logic in Program.Main that handles UnmatchedTokens
586
555
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." ;
587
556
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 (
589
562
ct ,
590
563
cliConfig : parseResult . Configuration ,
591
564
processId : parseResult . GetValue ( CommonOptions . ProcessIdOption ) ,
592
565
output : parseResult . GetValue ( CommonOptions . OutputPathOption ) ,
593
566
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 ) ,
596
569
format : parseResult . GetValue ( CommonOptions . FormatOption ) ,
597
570
duration : parseResult . GetValue ( CommonOptions . DurationOption ) ,
598
571
clrevents : parseResult . GetValue ( CommonOptions . CLREventsOption ) ?? string . Empty ,
@@ -605,7 +578,8 @@ public static Command CollectCommand()
605
578
stoppingEventEventName : parseResult . GetValue ( StoppingEventEventNameOption ) ,
606
579
stoppingEventPayloadFilter : parseResult . GetValue ( StoppingEventPayloadFilterOption ) ,
607
580
rundown : parseResult . GetValue ( RundownOption ) ,
608
- dsrouter : parseResult . GetValue ( DSRouterOption ) ) ) ;
581
+ dsrouter : parseResult . GetValue ( DSRouterOption ) ) ;
582
+ } ) ;
609
583
610
584
return collectCommand ;
611
585
}
0 commit comments