-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathProcDumpConfiguration.c
More file actions
763 lines (666 loc) · 27.2 KB
/
ProcDumpConfiguration.c
File metadata and controls
763 lines (666 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License
//--------------------------------------------------------------------
//
// The global configuration structure and utilities header
//
//--------------------------------------------------------------------
#include "Includes.h"
extern pthread_mutex_t LoggerLock;
long HZ; // clock ticks per second
int MAXIMUM_CPU; // maximum cpu usage percentage (# cores * 100)
struct ProcDumpConfiguration g_config; // backbone of the program
struct ProcDumpConfiguration * target_config; // list of configs for target group processes or matching names
extern pthread_mutex_t queue_mutex;
sigset_t sig_set;
//--------------------------------------------------------------------
//
// ApplyDefaults - Apply default values to configuration
//
//--------------------------------------------------------------------
void ApplyDefaults(struct ProcDumpConfiguration *self)
{
if(self->NumberOfDumpsToCollect == -1)
{
self->NumberOfDumpsToCollect = DEFAULT_NUMBER_OF_DUMPS;
}
if(self->ThresholdSeconds == -1)
{
self->ThresholdSeconds = DEFAULT_DELTA_TIME;
}
if(self->PollingInterval == -1)
{
self->PollingInterval = MIN_POLLING_INTERVAL;
}
}
//--------------------------------------------------------------------
//
// InitProcDump - initalize procdump
//
//--------------------------------------------------------------------
void InitProcDump()
{
openlog("ProcDump", LOG_PID, LOG_USER);
if(CheckKernelVersion() == false)
{
Log(error, "Kernel version lower than 3.5+.");
exit(-1);
}
InitProcDumpConfiguration(&g_config);
pthread_mutex_init(&LoggerLock, NULL);
pthread_mutex_init(&queue_mutex, NULL);
sigemptyset (&sig_set);
sigaddset (&sig_set, SIGINT);
sigaddset (&sig_set, SIGTERM);
pthread_sigmask (SIG_BLOCK, &sig_set, NULL);
auto_free char* prefixTmpFolder = NULL;
// Create the directories where our sockets will be stored
// If $TMPDIR is set, use it as the path, otherwise we use /tmp
prefixTmpFolder = getenv("TMPDIR");
if(prefixTmpFolder==NULL)
{
createDir("/tmp/procdump", 0777);
}
else
{
int len = strlen(prefixTmpFolder) + strlen("/procdump") + 1;
char* t = malloc(len);
sprintf(t, "%s%s", prefixTmpFolder, "/procdump");
createDir(t, 0777);
free(t);
}
}
//--------------------------------------------------------------------
//
// ExitProcDump - cleanup during exit.
//
//--------------------------------------------------------------------
void ExitProcDump()
{
Trace("ExitProcDump: Enter");
pthread_mutex_destroy(&LoggerLock);
closelog();
// Try to delete the profiler lib in case it was left over...
unlink(PROCDUMP_DIR "/" PROFILER_FILE_NAME);
Trace("ExitProcDump: Exit");
}
//--------------------------------------------------------------------
//
// InitProcDumpConfiguration - initalize a config
//
//--------------------------------------------------------------------
void InitProcDumpConfiguration(struct ProcDumpConfiguration *self)
{
MAXIMUM_CPU = 100 * (int)sysconf(_SC_NPROCESSORS_ONLN);
HZ = sysconf(_SC_CLK_TCK);
sysinfo(&(self->SystemInfo));
pthread_mutex_init(&self->ptrace_mutex, NULL);
InitNamedEvent(&(self->evtCtrlHandlerCleanupComplete.event), true, false, "CtrlHandlerCleanupComplete");
self->evtCtrlHandlerCleanupComplete.type = EVENT;
InitNamedEvent(&(self->evtBannerPrinted.event), true, false, "BannerPrinted");
self->evtBannerPrinted.type = EVENT;
InitNamedEvent(&(self->evtConfigurationPrinted.event), true, false, "ConfigurationPrinted");
self->evtConfigurationPrinted.type = EVENT;
InitNamedEvent(&(self->evtDebugThreadInitialized.event), true, false, "DebugThreadInitialized");
self->evtDebugThreadInitialized.type = EVENT;
InitNamedEvent(&(self->evtQuit.event), true, false, "Quit");
self->evtQuit.type = EVENT;
InitNamedEvent(&(self->evtStartMonitoring.event), true, false, "StartMonitoring");
self->evtStartMonitoring.type = EVENT;
sem_init(&(self->semAvailableDumpSlots.semaphore), 0, 1);
self->semAvailableDumpSlots.type = SEMAPHORE;
// Additional initialization
self->ProcessId = NO_PID;
self->bProcessGroup = false;
self->ProcessGroup = NO_PID;
self->NumberOfDumpsCollected = 0;
self->NumberOfDumpsToCollect = -1;
self->CpuThreshold = -1;
self->bCpuTriggerBelowValue = false;
self->MemoryThreshold = -1;
self->ThreadThreshold = -1;
self->FileDescriptorThreshold = -1;
self->SignalNumber = -1;
self->ThresholdSeconds = -1;
self->bMemoryTriggerBelowValue = false;
self->bTimerThreshold = false;
self->WaitingForProcessName = false;
self->DiagnosticsLoggingEnabled = false;
self->gcorePid = NO_PID;
self->PollingInterval = -1;
self->CoreDumpPath = NULL;
self->CoreDumpName = NULL;
self->nQuit = 0;
self->bDumpOnException = false;
self->bDumpOnException = NULL;
self->socketPath = NULL;
self->statusSocket = -1;
}
//--------------------------------------------------------------------
//
// FreeProcDumpConfiguration - ensure destruction of config and contents
//
//--------------------------------------------------------------------
void FreeProcDumpConfiguration(struct ProcDumpConfiguration *self)
{
Trace("FreeProcDumpConfiguration: Enter");
DestroyEvent(&(self->evtCtrlHandlerCleanupComplete.event));
DestroyEvent(&(self->evtBannerPrinted.event));
DestroyEvent(&(self->evtConfigurationPrinted.event));
DestroyEvent(&(self->evtDebugThreadInitialized.event));
DestroyEvent(&(self->evtQuit.event));
DestroyEvent(&(self->evtStartMonitoring.event));
pthread_mutex_destroy(&self->ptrace_mutex);
sem_destroy(&(self->semAvailableDumpSlots.semaphore));
if(self->ProcessName)
{
free(self->ProcessName);
self->ProcessName = NULL;
}
if(self->statusSocket != -1)
{
close(self->statusSocket);
self->statusSocket = -1;
}
if(self->socketPath)
{
unlink(self->socketPath);
free(self->socketPath);
self->socketPath = NULL;
}
if(self->ExceptionFilter)
{
free(self->ExceptionFilter);
self->ExceptionFilter = NULL;
}
if(self->CoreDumpPath)
{
free(self->CoreDumpPath);
self->CoreDumpPath = NULL;
}
if(self->CoreDumpName)
{
free(self->CoreDumpName);
self->CoreDumpName = NULL;
}
Trace("FreeProcDumpConfiguration: Exit");
}
//--------------------------------------------------------------------
//
// CopyProcDumpConfiguration - deep copy of Procdump Config struct
//
//--------------------------------------------------------------------
struct ProcDumpConfiguration * CopyProcDumpConfiguration(struct ProcDumpConfiguration *self)
{
struct ProcDumpConfiguration * copy = (struct ProcDumpConfiguration*)malloc(sizeof(struct ProcDumpConfiguration));
if(copy != NULL) {
// Init new struct
InitProcDumpConfiguration(copy);
// copy target data we need from original config
copy->ProcessId = self->ProcessId;
copy->bProcessGroup = self->bProcessGroup;
copy->ProcessGroup = self->ProcessGroup;
copy->ProcessName = self->ProcessName == NULL ? NULL : strdup(self->ProcessName);
// copy runtime values from original config
copy->NumberOfDumpsCollecting = self->NumberOfDumpsCollecting;
copy->NumberOfDumpsCollected = self->NumberOfDumpsCollected;
copy->bTerminated = self->bTerminated;
// copy trigger behavior from original config
copy->bTriggerThenSnoozeCPU = self->bTriggerThenSnoozeCPU;
copy->bTriggerThenSnoozeMemory = self->bTriggerThenSnoozeMemory;
copy->bTriggerThenSnoozeTimer = self->bTriggerThenSnoozeTimer;
// copy options from original config
copy->CpuThreshold = self->CpuThreshold;
copy->bCpuTriggerBelowValue = self->bCpuTriggerBelowValue;
copy->MemoryThreshold = self->MemoryThreshold;
copy->bMemoryTriggerBelowValue = self->bMemoryTriggerBelowValue;
copy->ThresholdSeconds = self->ThresholdSeconds;
copy->bTimerThreshold = self->bTimerThreshold;
copy->NumberOfDumpsToCollect = self->NumberOfDumpsToCollect;
copy->WaitingForProcessName = self->WaitingForProcessName;
copy->DiagnosticsLoggingEnabled = self->DiagnosticsLoggingEnabled;
copy->ThreadThreshold = self->ThreadThreshold;
copy->FileDescriptorThreshold = self->FileDescriptorThreshold;
copy->SignalNumber = self->SignalNumber;
copy->PollingInterval = self->PollingInterval;
copy->CoreDumpPath = self->CoreDumpPath == NULL ? NULL : strdup(self->CoreDumpPath);
copy->CoreDumpName = self->CoreDumpName == NULL ? NULL : strdup(self->CoreDumpName);
copy->ExceptionFilter = self->ExceptionFilter == NULL ? NULL : strdup(self->ExceptionFilter);
copy->socketPath = self->socketPath == NULL ? NULL : strdup(self->socketPath);
copy->bDumpOnException = self->bDumpOnException;
copy->statusSocket = self->statusSocket;
return copy;
}
else {
Trace("Failed to alloc memory for Procdump config copy");
return NULL;
}
}
//--------------------------------------------------------------------
//
// GetOptions - Unpack command line inputs
//
//--------------------------------------------------------------------
int GetOptions(struct ProcDumpConfiguration *self, int argc, char *argv[])
{
bool bProcessSpecified = false;
if (argc < 2) {
Trace("GetOptions: Invalid number of command line arguments.");
return PrintUsage();
}
for( int i = 1; i < argc; i++ )
{
if (0 == strcasecmp( argv[i], "/?" ) || 0 == strcasecmp( argv[i], "-?" ))
{
return PrintUsage();
}
else if ( 0 == strcasecmp( argv[i], "/c" ) ||
0 == strcasecmp( argv[i], "-c" ) ||
0 == strcasecmp( argv[i], "/cl" ) ||
0 == strcasecmp( argv[i], "-cl" ))
{
if( i+1 >= argc || self->CpuThreshold != -1 ) return PrintUsage();
if(!ConvertToInt(argv[i+1], &self->CpuThreshold)) return PrintUsage();
if(self->CpuThreshold < 0)
{
Log(error, "Invalid CPU threshold count specified.");
return PrintUsage();
}
if( 0 == strcasecmp( argv[i], "/cl" ) || 0 == strcasecmp( argv[i], "-cl"))
{
self->bCpuTriggerBelowValue = true;
}
i++;
}
else if( 0 == strcasecmp( argv[i], "/m" ) ||
0 == strcasecmp( argv[i], "-m" ) ||
0 == strcasecmp( argv[i], "/ml" ) ||
0 == strcasecmp( argv[i], "-ml" ))
{
if( i+1 >= argc || self->MemoryThreshold != -1 ) return PrintUsage();
if(!ConvertToInt(argv[i+1], &self->MemoryThreshold)) return PrintUsage();
if(self->MemoryThreshold < 0)
{
Log(error, "Invalid memory threshold count specified.");
return PrintUsage();
}
if( 0 == strcasecmp( argv[i], "/ml" ) || 0 == strcasecmp( argv[i], "-ml" ))
{
self->bMemoryTriggerBelowValue = true;
}
i++;
}
else if( 0 == strcasecmp( argv[i], "/tc" ) ||
0 == strcasecmp( argv[i], "-tc" ))
{
if( i+1 >= argc || self->ThreadThreshold != -1 ) return PrintUsage();
if(!ConvertToInt(argv[i+1], &self->ThreadThreshold)) return PrintUsage();
if(self->ThreadThreshold < 0)
{
Log(error, "Invalid thread threshold count specified.");
return PrintUsage();
}
i++;
}
else if( 0 == strcasecmp( argv[i], "/fc" ) ||
0 == strcasecmp( argv[i], "-fc" ))
{
if( i+1 >= argc || self->FileDescriptorThreshold != -1 ) return PrintUsage();
if(!ConvertToInt(argv[i+1], &self->FileDescriptorThreshold)) return PrintUsage();
if(self->FileDescriptorThreshold < 0)
{
Log(error, "Invalid file descriptor threshold count specified.");
return PrintUsage();
}
i++;
}
else if( 0 == strcasecmp( argv[i], "/sig" ) ||
0 == strcasecmp( argv[i], "-sig" ))
{
if( i+1 >= argc || self->SignalNumber != -1 ) return PrintUsage();
if(!ConvertToInt(argv[i+1], &self->SignalNumber)) return PrintUsage();
if(self->SignalNumber < 0)
{
Log(error, "Invalid signal specified.");
return PrintUsage();
}
i++;
}
else if( 0 == strcasecmp( argv[i], "/pf" ) ||
0 == strcasecmp( argv[i], "-pf" ))
{
if( i+1 >= argc || self->PollingInterval != -1 ) return PrintUsage();
if(!ConvertToInt(argv[i+1], &self->PollingInterval)) return PrintUsage();
if(self->PollingInterval < 0)
{
Log(error, "Invalid polling inverval specified.");
return PrintUsage();
}
i++;
}
else if( 0 == strcasecmp( argv[i], "/n" ) ||
0 == strcasecmp( argv[i], "-n" ))
{
if( i+1 >= argc || self->NumberOfDumpsToCollect != -1 ) return PrintUsage();
if(!ConvertToInt(argv[i+1], &self->NumberOfDumpsToCollect)) return PrintUsage();
if(self->NumberOfDumpsToCollect < 0)
{
Log(error, "Invalid number of dumps specified.");
return PrintUsage();
}
if(self->NumberOfDumpsToCollect > MAX_DUMP_COUNT)
{
Log(error, "Max dump count must be less than %d.", MAX_DUMP_COUNT);
return PrintUsage();
}
i++;
}
else if( 0 == strcasecmp( argv[i], "/s" ) ||
0 == strcasecmp( argv[i], "-s" ))
{
if( i+1 >= argc || self->ThresholdSeconds != -1 ) return PrintUsage();
if(!ConvertToInt(argv[i+1], &self->ThresholdSeconds)) return PrintUsage();
if(self->ThresholdSeconds < 0)
{
Log(error, "Invalid seconds specified.");
return PrintUsage();
}
i++;
}
else if( 0 == strcasecmp( argv[i], "/log" ) ||
0 == strcasecmp( argv[i], "-log" ))
{
self->DiagnosticsLoggingEnabled = true;
}
else if( 0 == strcasecmp( argv[i], "/e" ) ||
0 == strcasecmp( argv[i], "-e" ))
{
self->bDumpOnException = true;
}
else if( 0 == strcasecmp( argv[i], "/f" ) ||
0 == strcasecmp( argv[i], "-f" ))
{
if( i+1 >= argc ) return PrintUsage();
self->ExceptionFilter = strdup(argv[i+1]);
if( tolower( self->ExceptionFilter[0] ) > 'z' || ( self->ExceptionFilter[0] != '*' && tolower( self->ExceptionFilter[0] ) < 'a' ) ) return PrintUsage();
i++;
}
else if( 0 == strcasecmp( argv[i], "/o" ) ||
0 == strcasecmp( argv[i], "-o" ))
{
self->bOverwriteExisting = true;
}
else if( 0 == strcasecmp( argv[i], "/w" ) ||
0 == strcasecmp( argv[i], "-w" ))
{
self->WaitingForProcessName = true;
}
else if( 0 == strcasecmp( argv[i], "/pgid" ) ||
0 == strcasecmp( argv[i], "-pgid" ))
{
self->bProcessGroup = true;
}
else
{
// Process targets
int j;
if( bProcessSpecified && self->CoreDumpPath )
{
return PrintUsage();
} else if(!bProcessSpecified)
{
bProcessSpecified = true;
bool isPid = true;
for( j = 0; j < (int) strlen( argv[i]); j++ )
{
if( !isdigit( argv[i][j]) )
{
isPid = false;
break;
}
}
if( !isPid )
{
self->ProcessName = strdup(argv[i]);
} else
{
if(self->bProcessGroup)
{
if( !sscanf( argv[i], "%d", &self->ProcessGroup ))
{
return PrintUsage();
}
}
else
{
if( !sscanf( argv[i], "%d", &self->ProcessId ))
{
return PrintUsage();
}
}
}
} else if(!self->CoreDumpPath)
{
char *tempOutputPath = NULL;
tempOutputPath = strdup(argv[i]);
struct stat statbuf;
// Check if the user provided an existing directory or a path
// ending in a '/'. In this case, use the default naming
// convention but place the files in the given directory.
if ((stat(tempOutputPath, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) ||
tempOutputPath[strlen(tempOutputPath)-1] == '/') {
self->CoreDumpPath = tempOutputPath;
self->CoreDumpName = NULL;
} else {
self->CoreDumpPath = strdup(dirname(tempOutputPath));
free(tempOutputPath);
tempOutputPath = strdup(argv[i]);
self->CoreDumpName = strdup(basename(tempOutputPath));
free(tempOutputPath);
}
// Check if the path portion of the output format is valid
if (stat(self->CoreDumpPath, &statbuf) < 0 || !S_ISDIR(statbuf.st_mode)) {
Log(error, "Invalid directory (\"%s\") provided for core dump output.",
self->CoreDumpPath);
return PrintUsage();
}
}
}
}
//
// Validate multi arguments
//
// If exception filter is provided with no -e switch exit
if((self->ExceptionFilter && self->bDumpOnException == false))
{
Log(error, "Please use the -e switch when specifying an exception filter (-f)");
return PrintUsage();
}
// If no path was provided, assume the current directory
if (self->CoreDumpPath == NULL) {
self->CoreDumpPath = strdup(".");
}
// Wait
if((self->WaitingForProcessName && self->ProcessId != NO_PID))
{
Log(error, "The wait option requires the process be specified by name.");
return PrintUsage();
}
// If number of dumps to collect is set, but there is no other criteria, enable Timer here...
if ((self->CpuThreshold == -1) &&
(self->MemoryThreshold == -1) &&
(self->ThreadThreshold == -1) &&
(self->FileDescriptorThreshold == -1))
{
self->bTimerThreshold = true;
}
// Signal trigger can only be specified alone
if(self->SignalNumber != -1 || self->bDumpOnException)
{
if(self->CpuThreshold != -1 || self->ThreadThreshold != -1 || self->FileDescriptorThreshold != -1 || self->MemoryThreshold != -1)
{
Log(error, "Signal/Exception trigger must be the only trigger specified.");
return PrintUsage();
}
if(self->PollingInterval != -1)
{
Log(error, "Polling interval has no meaning during Signal/Exception monitoring.");
return PrintUsage();
}
// Again, we cant have another trigger (in this case timer) kicking off another dump generation since we will already
// be attached via ptrace.
self->bTimerThreshold = false;
}
// If we are monitoring multiple process, setting dump name doesn't make sense (path is OK)
if ((self->bProcessGroup || self->WaitingForProcessName) && self->CoreDumpName)
{
Log(error, "Setting core dump name in multi process monitoring is invalid (path is ok).");
return PrintUsage();
}
// Apply default values for any config values that were not specified by user
ApplyDefaults(self);
Trace("GetOpts and initial Configuration finished");
return 0;
}
//--------------------------------------------------------------------
//
// PrintConfiguration - Prints the current configuration to the command line
//
//--------------------------------------------------------------------
bool PrintConfiguration(struct ProcDumpConfiguration *self)
{
if (WaitForSingleObject(&self->evtConfigurationPrinted,0) == WAIT_TIMEOUT) {
if(self->SignalNumber != -1) {
printf("** NOTE ** Signal triggers use PTRACE which will impact the performance of the target process\n\n");
}
if (self->bProcessGroup) {
printf("%-40s%d\n", "Process Group:", self->ProcessGroup);
}
else if (self->WaitingForProcessName) {
printf("%-40s%s\n", "Process Name:", self->ProcessName);
}
else {
printf("%-40s%s (%d)\n", "Process:", self->ProcessName, self->ProcessId);
}
// CPU
if (self->CpuThreshold != -1) {
if (self->bCpuTriggerBelowValue) {
printf("%-40s< %d%%\n", "CPU Threshold:", self->CpuThreshold);
} else {
printf("%-40s>= %d%%\n", "CPU Threshold:", self->CpuThreshold);
}
} else {
printf("%-40s%s\n", "CPU Threshold:", "n/a");
}
// Memory
if (self->MemoryThreshold != -1) {
if (self->bMemoryTriggerBelowValue) {
printf("%-40s<%d MB\n", "Commit Threshold:", self->MemoryThreshold);
} else {
printf("%-40s>=%d MB\n", "Commit Threshold:", self->MemoryThreshold);
}
} else {
printf("%-40s%s\n", "Commit Threshold:", "n/a");
}
// Thread
if (self->ThreadThreshold != -1) {
printf("%-40s%d\n", "Thread Threshold:", self->ThreadThreshold);
}
else {
printf("%-40s%s\n", "Thread Threshold:", "n/a");
}
// File descriptor
if (self->FileDescriptorThreshold != -1) {
printf("%-40s%d\n", "File Descriptor Threshold:", self->FileDescriptorThreshold);
}
else {
printf("%-40s%s\n", "File Descriptor Threshold:", "n/a");
}
// Signal
if (self->SignalNumber != -1) {
printf("%-40s%d\n", "Signal:", self->SignalNumber);
}
else {
printf("%-40s%s\n", "Signal:", "n/a");
}
// Signal
if (self->bDumpOnException) {
printf("%-40s%s\n", "Exception monitor", "On");
printf("%-40s%s\n", "Exception filter", self->ExceptionFilter);
}
else {
printf("%-40s%s\n", "Exception monitor", "Off");
}
// Polling inverval
printf("%-40s%d\n", "Polling Interval (ms):", self->PollingInterval);
// time
printf("%-40s%d\n", "Threshold (s):", self->ThresholdSeconds);
// number of dumps and others
printf("%-40s%d\n", "Number of Dumps:", self->NumberOfDumpsToCollect);
// Output directory and filename
printf("%-40s%s\n", "Output directory:", self->CoreDumpPath);
if (self->CoreDumpName != NULL) {
printf("%-40s%s_<counter>\n", "Custom name for core dumps:", self->CoreDumpName);
}
SetEvent(&self->evtConfigurationPrinted.event);
return true;
}
return false;
}
//--------------------------------------------------------------------
//
// PrintBanner - Not re-entrant safe banner printer. Function must be called before trigger threads start.
//
//--------------------------------------------------------------------
void PrintBanner()
{
printf("\nProcDump v1.4 - Sysinternals process dump utility\n");
printf("Copyright (C) 2022 Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n");
printf("Mark Russinovich, Mario Hewardt, John Salem, Javid Habibi\n");
printf("Sysinternals - www.sysinternals.com\n\n");
printf("Monitors one or more processes and writes a core dump file when the processes exceeds the\n");
printf("specified criteria.\n\n");
}
//--------------------------------------------------------------------
//
// PrintUsage - Print usage
//
//--------------------------------------------------------------------
int PrintUsage()
{
printf("\nCapture Usage: \n");
printf(" procdump [-n Count]\n");
printf(" [-s Seconds]\n");
printf(" [-c|-cl CPU_Usage]\n");
printf(" [-m|-ml Commit_Usage]\n");
printf(" [-tc Thread_Threshold]\n");
printf(" [-fc FileDescriptor_Threshold]\n");
printf(" [-sig Signal_Number]\n");
printf(" [-e]\n");
printf(" [-f Include_Filter,...]\n");
printf(" [-pf Polling_Frequency]\n");
printf(" [-o]\n");
printf(" [-log]\n");
printf(" {\n");
printf(" {{[-w] Process_Name | [-pgid] PID} [Dump_File | Dump_Folder]}\n");
printf(" }\n");
printf("\n");
printf("Options:\n");
printf(" -n Number of dumps to write before exiting.\n");
printf(" -s Consecutive seconds before dump is written (default is 10).\n");
printf(" -c CPU threshold above which to create a dump of the process.\n");
printf(" -cl CPU threshold below which to create a dump of the process.\n");
printf(" -m Memory commit threshold in MB at which to create a dump.\n");
printf(" -ml Trigger when memory commit drops below specified MB value.\n");
printf(" -tc Thread count threshold above which to create a dump of the process.\n");
printf(" -fc File descriptor count threshold above which to create a dump of the process.\n");
printf(" -sig Signal number to intercept to create a dump of the process.\n");
printf(" -e [.NET] Create dump when the process encounters an exception.\n");
printf(" -f [.NET] Filter (include) on the (comma separated) exception name(s).\n");
printf(" -pf Polling frequency.\n");
printf(" -o Overwrite existing dump file.\n");
printf(" -log Writes extended ProcDump tracing to syslog.\n");
printf(" -w Wait for the specified process to launch if it's not running.\n");
printf(" -pgid Process ID specified refers to a process group ID.\n");
return -1;
}