Parses agent arguments. The format of the string is: arg[,arg...]
| 39 | // Parses agent arguments. |
| 40 | // The format of the string is: arg[,arg...] |
| 41 | Error Arguments::parse(const char* args) { |
| 42 | if (args == NULL) { |
| 43 | return Error::OK; |
| 44 | } |
| 45 | |
| 46 | size_t len = strlen(args); |
| 47 | free(_buf); |
| 48 | _buf = (char*)malloc(len + EXTRA_BUF_SIZE + 1); |
| 49 | if (_buf == NULL) { |
| 50 | return Error("Not enough memory to parse arguments"); |
| 51 | } |
| 52 | char* args_copy = strcpy(_buf + EXTRA_BUF_SIZE, args); |
| 53 | |
| 54 | const char* msg = NULL; |
| 55 | |
| 56 | for (char* arg = strtok(args_copy, ","); arg != NULL; arg = strtok(NULL, ",")) { |
| 57 | char* value = strchr(arg, '='); |
| 58 | if (value != NULL) *value++ = 0; |
| 59 | |
| 60 | SWITCH (arg) { |
| 61 | // Actions |
| 62 | CASE("start") |
| 63 | _action = ACTION_START; |
| 64 | |
| 65 | CASE("resume") |
| 66 | _action = ACTION_RESUME; |
| 67 | |
| 68 | CASE("stop") |
| 69 | _action = ACTION_STOP; |
| 70 | |
| 71 | CASE("dump") |
| 72 | _action = ACTION_DUMP; |
| 73 | |
| 74 | CASE("status") |
| 75 | _action = ACTION_STATUS; |
| 76 | |
| 77 | CASE("metrics") |
| 78 | _action = ACTION_METRICS; |
| 79 | |
| 80 | CASE("list") |
| 81 | _action = ACTION_LIST; |
| 82 | |
| 83 | CASE("version") |
| 84 | _action = ACTION_VERSION; |
| 85 | |
| 86 | // Output formats |
| 87 | CASE("collapsed") |
| 88 | _output = OUTPUT_COLLAPSED; |
| 89 | |
| 90 | CASE("flamegraph") |
| 91 | _output = OUTPUT_FLAMEGRAPH; |
| 92 | |
| 93 | CASE("tree") |
| 94 | _output = OUTPUT_TREE; |
| 95 | |
| 96 | CASE("jfr") |
| 97 | _output = OUTPUT_JFR; |
| 98 |