|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2005 - 2007 IBM Corporation, Intel Corporation. |
2 |
* Copyright (c) 2005 - 2008 IBM Corporation, Intel Corporation. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 57-63
Link Here
|
| 57 |
{ |
57 |
{ |
| 58 |
1 /* Provide timestamps by default */ |
58 |
1 /* Provide timestamps by default */ |
| 59 |
,0 /* Standalone mode */ |
59 |
,0 /* Standalone mode */ |
| 60 |
// ,0 /* Application mode */ |
60 |
,0 /* Application mode */ |
| 61 |
,1 /* Enabled mode */ |
61 |
,1 /* Enabled mode */ |
| 62 |
,1 /* Filters */ |
62 |
,1 /* Filters */ |
| 63 |
,1 /* Options */ |
63 |
,1 /* Options */ |
|
Lines 115-140
Link Here
|
| 115 |
strcpy(m_jvmtiAgent_Options.workDir, DEFAULT_WORK_DIR); |
115 |
strcpy(m_jvmtiAgent_Options.workDir, DEFAULT_WORK_DIR); |
| 116 |
} |
116 |
} |
| 117 |
|
117 |
|
| 118 |
int |
|
|
| 119 |
COptions::getToken(const char **src, char *buf, int buflen, char sep) |
| 120 |
{ |
| 121 |
int i; |
| 122 |
const char *p = *src; |
| 123 |
for (i = 0; i < buflen; i++) { |
| 124 |
if (p[i] == 0 || p[i] == sep) { |
| 125 |
buf[i] = 0; |
| 126 |
if (p[i] == sep) { |
| 127 |
i++; |
| 128 |
} |
| 129 |
*src += i; |
| 130 |
return i; |
| 131 |
} |
| 132 |
buf[i] = p[i]; |
| 133 |
} |
| 134 |
/* overflow */ |
| 135 |
return 0; |
| 136 |
} |
| 137 |
|
| 138 |
/** PRINT_USAGE ********************************************************************** |
118 |
/** PRINT_USAGE ********************************************************************** |
| 139 |
* Print the command line useage of the program. |
119 |
* Print the command line useage of the program. |
| 140 |
*/ |
120 |
*/ |
|
Lines 155-160
Link Here
|
| 155 |
"\n" |
135 |
"\n" |
| 156 |
"Supported option names and values:\n" |
136 |
"Supported option names and values:\n" |
| 157 |
" server=standalone|enabled|controlled\n" |
137 |
" server=standalone|enabled|controlled\n" |
|
|
138 |
" api=true|false\tProfiler API (default is false)\n" |
| 158 |
" file=<file>\t\tOutput file (default is %s)\n" |
139 |
" file=<file>\t\tOutput file (default is %s)\n" |
| 159 |
" \t\t\tOnly applicable when server=standalone\n" |
140 |
" \t\t\tOnly applicable when server=standalone\n" |
| 160 |
" filters=<file>\tFilter definition file (default is %s)\n" |
141 |
" filters=<file>\tFilter definition file (default is %s)\n" |
|
Lines 434-563
Link Here
|
| 434 |
return rc; |
415 |
return rc; |
| 435 |
} |
416 |
} |
| 436 |
|
417 |
|
| 437 |
/** PROCESS_INVOCATION_OPTIONS ******************************************* |
418 |
int COptions::parseOptions(char* buf) { |
| 438 |
* Takes the command line parameters and populates the m_jvmtiAgent_Options |
419 |
int outputSpecified = 0; |
| 439 |
* with the correct values based upon the options specified. |
|
|
| 440 |
* @param optionString - the command line args |
| 441 |
* @returns |
| 442 |
*/ |
| 443 |
|
| 444 |
int |
| 445 |
COptions::ProcessInvocationOptions(const char *str) |
| 446 |
{ |
| 447 |
char *buf = 0; |
| 448 |
int buflen; |
| 449 |
int outputSpecified = 0; |
| 450 |
if (str == 0) str = ""; |
| 451 |
|
420 |
|
| 452 |
/* if "help" is specified print out the useage */ |
421 |
char* pnext = buf; |
| 453 |
if ((STRICOLL(str, "help")) == 0) { |
422 |
while (pnext) { |
| 454 |
return -1; |
423 |
char* pname = pnext; // current tag |
| 455 |
} |
424 |
|
| 456 |
|
425 |
pnext = strchr(pnext, ','); |
| 457 |
while (*str) { |
426 |
if (pnext != NULL) { |
| 458 |
buflen= strlen(str)+1; |
427 |
*pnext++ = '\0'; // next tag |
| 459 |
buf = (char *)malloc(buflen); |
428 |
} |
| 460 |
if (!buf) { |
429 |
|
| 461 |
goto mem_error; |
430 |
char* pvalue = strchr(pname, '='); |
| 462 |
} |
431 |
if (pvalue != NULL) { |
|
|
432 |
*pvalue++ = '\0'; |
| 433 |
} |
| 463 |
|
434 |
|
| 464 |
/* All options contain an "=" */ |
|
|
| 465 |
if (!getToken(&str, buf, buflen, '=')) { |
| 466 |
goto bad_option; |
| 467 |
} |
| 468 |
/* Specied output file */ |
435 |
/* Specied output file */ |
| 469 |
if (STRICOLL(buf, "file") == 0) { |
436 |
if (STRICOLL(pname, "file") == 0) { |
| 470 |
if (outputSpecified || !getToken(&str, buf, buflen, ',')) { |
437 |
if (outputSpecified || pvalue == NULL) return -1; |
| 471 |
goto bad_option; |
438 |
|
| 472 |
} |
439 |
strcpyrealloc(&m_jvmtiAgent_Options.outputFileName, pvalue); |
| 473 |
strcpyrealloc(&m_jvmtiAgent_Options.outputFileName, buf); |
|
|
| 474 |
outputSpecified = 1; |
440 |
outputSpecified = 1; |
| 475 |
} else if (STRICOLL(buf, "filters") == 0) { |
441 |
} else if (STRICOLL(pname, "filters") == 0) { |
| 476 |
if (!getToken(&str, buf, buflen, ',')) { |
442 |
if (pvalue == NULL) return -1; |
| 477 |
goto bad_option; |
443 |
|
| 478 |
} |
444 |
strcpyrealloc(&m_jvmtiAgent_Options.filterFileName, pvalue); |
| 479 |
strcpyrealloc(&m_jvmtiAgent_Options.filterFileName,buf); |
|
|
| 480 |
// } else if (STRICOLL(buf, "debug") == 0) { |
| 481 |
// if (!getToken(&str, buf, buflen, ',')) { |
| 482 |
// goto bad_option; |
| 483 |
// } else { |
| 484 |
// goto bad_option; |
| 485 |
// } |
| 486 |
} |
445 |
} |
| 487 |
/* Mode of operation */ |
446 |
/* Mode of operation */ |
| 488 |
else if (STRICOLL(buf, "server") == 0) { |
447 |
else if (STRICOLL(pname, "server") == 0) { |
| 489 |
if (!getToken(&str, buf, buflen, ',')) { |
448 |
if (pvalue == NULL) return -1; |
| 490 |
goto bad_option; |
449 |
|
| 491 |
} |
|
|
| 492 |
/* If standalone */ |
450 |
/* If standalone */ |
| 493 |
if (STRICOLL(buf,"standalone") == 0) { |
451 |
if (STRICOLL(pvalue,"standalone") == 0) { |
| 494 |
m_jvmtiAgent_Options.standalone = 1; |
452 |
m_jvmtiAgent_Options.standalone = 1; |
| 495 |
m_jvmtiAgent_Options.enabled = 0; |
453 |
m_jvmtiAgent_Options.enabled = 0; |
| 496 |
} |
454 |
} |
| 497 |
/* If enabled */ |
455 |
/* If enabled */ |
| 498 |
else if (STRICOLL(buf, "enabled") == 0) { |
456 |
else if (STRICOLL(pvalue, "enabled") == 0) { |
| 499 |
m_jvmtiAgent_Options.standalone = 0; |
457 |
m_jvmtiAgent_Options.standalone = 0; |
| 500 |
m_jvmtiAgent_Options.enabled = 1; |
458 |
m_jvmtiAgent_Options.enabled = 1; |
| 501 |
} |
459 |
} |
| 502 |
/* If controlled */ |
460 |
/* If controlled */ |
| 503 |
else if (STRICOLL(buf, "controlled") == 0) { |
461 |
else if (STRICOLL(pvalue, "controlled") == 0) { |
| 504 |
m_jvmtiAgent_Options.standalone = 0; |
462 |
m_jvmtiAgent_Options.standalone = 0; |
| 505 |
m_jvmtiAgent_Options.enabled = 0; |
463 |
m_jvmtiAgent_Options.enabled = 0; |
| 506 |
} else { |
464 |
} else { |
| 507 |
goto bad_option; |
465 |
return -1; |
| 508 |
} |
466 |
} |
| 509 |
} else if (STRICOLL(buf, "workDir") == 0) { |
467 |
} else if (STRICOLL(pname, "api") == 0) { |
| 510 |
if (!getToken(&str, buf, buflen, ',')) { |
468 |
if (pvalue == NULL) return -1; |
| 511 |
goto bad_option; |
469 |
|
|
|
470 |
if (STRICOLL(pvalue, "true") == 0) { |
| 471 |
m_jvmtiAgent_Options.application = 1; |
| 512 |
} |
472 |
} |
| 513 |
strcpyrealloc(&m_jvmtiAgent_Options.workDir, buf); |
473 |
} else if (STRICOLL(pname, "workDir") == 0) { |
|
|
474 |
if (pvalue == NULL) return -1; |
| 475 |
|
| 476 |
strcpyrealloc(&m_jvmtiAgent_Options.workDir, pvalue); |
| 514 |
|
477 |
|
| 515 |
/* create the directory */ |
478 |
/* create the directory */ |
| 516 |
if (MKDIR(m_jvmtiAgent_Options.workDir) != 0 && errno != EEXIST) { |
479 |
if (MKDIR(m_jvmtiAgent_Options.workDir) != 0 && errno != EEXIST) { |
| 517 |
/* couldn't create the dir and it doesn't exists either */ |
480 |
/* couldn't create the dir and it doesn't exists either */ |
| 518 |
perror(m_jvmtiAgent_Options.workDir); |
481 |
perror(m_jvmtiAgent_Options.workDir); |
| 519 |
goto bad_option; |
482 |
return -1; |
| 520 |
} |
483 |
} |
| 521 |
|
484 |
|
| 522 |
/* end of workDir */ |
485 |
/* end of workDir */ |
| 523 |
} else if (STRICOLL(buf, "profile") == 0) { |
486 |
} else if (STRICOLL(pname, "profile") == 0) { |
| 524 |
m_jvmtiAgent_Options.profileFile; |
487 |
m_jvmtiAgent_Options.profileFile; |
| 525 |
if (!getToken(&str, buf, buflen, ',')) { |
488 |
if (pvalue == NULL) return -1; |
| 526 |
goto bad_option; |
489 |
|
| 527 |
} |
490 |
strcpyrealloc(&m_jvmtiAgent_Options.profileFile, pvalue); |
| 528 |
strcpyrealloc(&m_jvmtiAgent_Options.profileFile, buf); |
|
|
| 529 |
} else { |
491 |
} else { |
| 530 |
char *buf2 = (char *)malloc(buflen); |
492 |
if (pvalue == NULL) return -1; |
| 531 |
if (!getToken(&str, buf2, buflen, ',')) { |
493 |
SetProfileOption(pname, pvalue); |
| 532 |
free(buf2); |
|
|
| 533 |
return -1; |
| 534 |
} |
| 535 |
SetProfileOption(buf, buf2); |
| 536 |
free(buf2); |
| 537 |
} |
494 |
} |
| 538 |
// } else { |
495 |
} |
| 539 |
// /* unknown option */ |
496 |
|
| 540 |
// fprintf(stderr, "Unknown option \"%s\"\n", buf); |
497 |
return 0; |
| 541 |
// fflush(stderr); |
498 |
} |
| 542 |
// goto bad_option; |
499 |
|
| 543 |
// } |
500 |
/** PROCESS_INVOCATION_OPTIONS ******************************************* |
| 544 |
} |
501 |
* Takes the command line parameters and populates the m_jvmtiAgent_Options |
| 545 |
if (buf) { |
502 |
* with the correct values based upon the options specified. |
| 546 |
free (buf); |
503 |
* @param optionString - the command line args |
|
|
504 |
* @returns |
| 505 |
*/ |
| 506 |
|
| 507 |
int COptions::ProcessInvocationOptions(const char *str) { |
| 508 |
char* buf; |
| 509 |
|
| 510 |
if (str == NULL) return 0; |
| 511 |
|
| 512 |
/* if "help" is specified print out the useage */ |
| 513 |
if ((STRICOLL(str, "help")) == 0) { |
| 514 |
return -1; |
| 547 |
} |
515 |
} |
| 548 |
return 0; |
|
|
| 549 |
|
516 |
|
| 550 |
bad_option: |
517 |
buf = (char*) malloc(strlen(str) + 1); |
| 551 |
if (buf) { |
518 |
if (buf == NULL) { |
| 552 |
free(buf); |
519 |
fprintf(stderr, "Memory allocation error\n"); |
|
|
520 |
fflush(stderr); |
| 521 |
return -1; |
| 522 |
} |
| 523 |
|
| 524 |
strcpy(buf, str); |
| 525 |
|
| 526 |
int r = parseOptions(buf); |
| 527 |
free(buf); |
| 528 |
|
| 529 |
if (r < 0) { |
| 530 |
fprintf(stderr, "Illegal TIAgent option\n"); |
| 531 |
fflush(stderr); |
| 553 |
} |
532 |
} |
| 554 |
fprintf(stderr, "Bad TIAgent option\n"); |
533 |
|
| 555 |
fflush(stderr); |
534 |
return r; |
| 556 |
return -1; |
|
|
| 557 |
mem_error: |
| 558 |
fprintf(stderr, "Memory allocation error\n"); |
| 559 |
fflush(stderr); |
| 560 |
return -1; |
| 561 |
} |
535 |
} |
| 562 |
|
536 |
|
| 563 |
/** CHECK_OPTIONS_CONSISTENCY ******************************************** |
537 |
/** CHECK_OPTIONS_CONSISTENCY ******************************************** |