| 2514 | #endif |
| 2515 | |
| 2516 | bool |
| 2517 | prof_log_start(tsdn_t *tsdn, const char *filename) { |
| 2518 | if (!opt_prof || !prof_booted) { |
| 2519 | return true; |
| 2520 | } |
| 2521 | |
| 2522 | bool ret = false; |
| 2523 | size_t buf_size = PATH_MAX + 1; |
| 2524 | |
| 2525 | malloc_mutex_lock(tsdn, &log_mtx); |
| 2526 | |
| 2527 | if (prof_logging_state != prof_logging_state_stopped) { |
| 2528 | ret = true; |
| 2529 | } else if (filename == NULL) { |
| 2530 | /* Make default name. */ |
| 2531 | malloc_snprintf(log_filename, buf_size, "%s.%d.%"FMTu64".json", |
| 2532 | opt_prof_prefix, prof_getpid(), log_seq); |
| 2533 | log_seq++; |
| 2534 | prof_logging_state = prof_logging_state_started; |
| 2535 | } else if (strlen(filename) >= buf_size) { |
| 2536 | ret = true; |
| 2537 | } else { |
| 2538 | strcpy(log_filename, filename); |
| 2539 | prof_logging_state = prof_logging_state_started; |
| 2540 | } |
| 2541 | |
| 2542 | if (!ret) { |
| 2543 | nstime_update(&log_start_timestamp); |
| 2544 | } |
| 2545 | |
| 2546 | malloc_mutex_unlock(tsdn, &log_mtx); |
| 2547 | |
| 2548 | return ret; |
| 2549 | } |
| 2550 | |
| 2551 | /* Used as an atexit function to stop logging on exit. */ |
| 2552 | static void |
no test coverage detected