MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / expandFilePattern

Method expandFilePattern

src/arguments.cpp:462–512  ·  view source on GitHub ↗

Expands the following patterns: %p process id %t timestamp (yyyyMMdd-hhmmss) %n{MAX} sequence number %{ENV} environment variable

Source from the content-addressed store, hash-verified

460// %n{MAX} sequence number
461// %{ENV} environment variable
462const char* Arguments::expandFilePattern(const char* pattern) {
463 char* ptr = _buf;
464 char* end = _buf + EXTRA_BUF_SIZE - 1;
465
466 while (ptr < end && *pattern != 0) {
467 char c = *pattern++;
468 if (c == '%') {
469 c = *pattern++;
470 if (c == 0) {
471 break;
472 } else if (c == 'p') {
473 ptr += snprintf(ptr, end - ptr, "%d", getpid());
474 continue;
475 } else if (c == 't') {
476 time_t timestamp = time(NULL);
477 struct tm t;
478 localtime_r(&timestamp, &t);
479 ptr += snprintf(ptr, end - ptr, "%d%02d%02d-%02d%02d%02d",
480 t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
481 t.tm_hour, t.tm_min, t.tm_sec);
482 continue;
483 } else if (c == 'n') {
484 unsigned int max_files = 0;
485 const char* p;
486 if (*pattern == '{' && (p = strchr(pattern, '}')) != NULL) {
487 max_files = atoi(pattern + 1);
488 pattern = p + 1;
489 }
490 ptr += snprintf(ptr, end - ptr, "%u", max_files > 0 ? _file_num % max_files : _file_num);
491 continue;
492 } else if (c == '{') {
493 char env_key[128];
494 const char* p = strchr(pattern, '}');
495 if (p != NULL && p - pattern < sizeof(env_key)) {
496 memcpy(env_key, pattern, p - pattern);
497 env_key[p - pattern] = 0;
498 const char* env_value = getenv(env_key);
499 if (env_value != NULL) {
500 ptr += snprintf(ptr, end - ptr, "%s", env_value);
501 pattern = p + 1;
502 continue;
503 }
504 }
505 }
506 }
507 *ptr++ = c;
508 }
509
510 *(ptr < end ? ptr : end) = 0;
511 return _buf;
512}
513
514Output Arguments::detectOutputFormat(const char* file) {
515 const char* ext = strrchr(file, '.');

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected