made benchmarking changes for concurency; made finish line before sampling
This commit is contained in:
@@ -29,5 +29,5 @@ Per-run outputs are stored under `runs/`:
|
|||||||
|
|
||||||
- `pi_digits.txt` — final concatenated digits
|
- `pi_digits.txt` — final concatenated digits
|
||||||
- `workers.csv` — per-worker durations and chunk metadata
|
- `workers.csv` — per-worker durations and chunk metadata
|
||||||
- `results.csv` — per-run summary metrics (includes aggregated RSS/VSZ and snapshot overhead)
|
- `results.csv` — per-run summary metrics (includes aggregated RSS/VSZ/PSS and snapshot overhead)
|
||||||
- `stdout.log` / `stderr.log` — benchmark logs
|
- `stdout.log` / `stderr.log` — benchmark logs
|
||||||
|
|||||||
Binary file not shown.
@@ -54,6 +54,7 @@ typedef struct {
|
|||||||
long max_vsz_kb;
|
long max_vsz_kb;
|
||||||
long agg_rss_kb;
|
long agg_rss_kb;
|
||||||
long agg_vsz_kb;
|
long agg_vsz_kb;
|
||||||
|
long agg_pss_kb;
|
||||||
double mem_snapshot_s;
|
double mem_snapshot_s;
|
||||||
size_t output_bytes;
|
size_t output_bytes;
|
||||||
int exit_code;
|
int exit_code;
|
||||||
@@ -348,17 +349,36 @@ static int read_self_status_kb(long *rss_kb, long *vsz_kb) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long read_self_pss_kb(void) {
|
||||||
|
FILE *f = fopen("/proc/self/smaps", "r");
|
||||||
|
if (!f) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
long total = 0;
|
||||||
|
char line[256];
|
||||||
|
while (fgets(line, sizeof(line), f)) {
|
||||||
|
long v = 0;
|
||||||
|
if (sscanf(line, "Pss: %ld", &v) == 1) {
|
||||||
|
total += v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
static int write_worker_stats(const char *path) {
|
static int write_worker_stats(const char *path) {
|
||||||
long rss_kb = 0;
|
long rss_kb = 0;
|
||||||
long vsz_kb = 0;
|
long vsz_kb = 0;
|
||||||
|
long pss_kb = 0;
|
||||||
if (read_self_status_kb(&rss_kb, &vsz_kb) != 0) {
|
if (read_self_status_kb(&rss_kb, &vsz_kb) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
pss_kb = read_self_pss_kb();
|
||||||
FILE *f = fopen(path, "w");
|
FILE *f = fopen(path, "w");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fprintf(f, "%ld,%ld\n", rss_kb, vsz_kb);
|
fprintf(f, "%ld,%ld,%ld\n", rss_kb, vsz_kb, pss_kb);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -573,31 +593,18 @@ static void collect_metrics(run_metrics_t *metrics, double start_wall, double en
|
|||||||
read_self_status_kb(&metrics->max_rss_kb, &metrics->max_vsz_kb);
|
read_self_status_kb(&metrics->max_rss_kb, &metrics->max_vsz_kb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_worker_stats(const char *path, long *rss_kb, long *vsz_kb) {
|
|
||||||
*rss_kb = 0;
|
|
||||||
*vsz_kb = 0;
|
|
||||||
FILE *f = fopen(path, "r");
|
|
||||||
if (!f) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (fscanf(f, "%ld,%ld", rss_kb, vsz_kb) != 2) {
|
|
||||||
fclose(f);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void aggregate_worker_memory(const bench_config_t *cfg, run_mode_t mode, const worker_info_t *workers, run_metrics_t *metrics) {
|
static void aggregate_worker_memory(const bench_config_t *cfg, run_mode_t mode, const worker_info_t *workers, run_metrics_t *metrics) {
|
||||||
double t0 = now_wall();
|
double t0 = now_wall();
|
||||||
long total_rss = 0;
|
long total_rss = 0;
|
||||||
long total_vsz = 0;
|
long total_vsz = 0;
|
||||||
|
long total_pss = 0;
|
||||||
|
|
||||||
long self_rss = 0;
|
long self_rss = 0;
|
||||||
long self_vsz = 0;
|
long self_vsz = 0;
|
||||||
read_self_status_kb(&self_rss, &self_vsz);
|
read_self_status_kb(&self_rss, &self_vsz);
|
||||||
total_rss += self_rss;
|
total_rss += self_rss;
|
||||||
total_vsz += self_vsz;
|
total_vsz += self_vsz;
|
||||||
|
total_pss += read_self_pss_kb();
|
||||||
|
|
||||||
if (mode == MODE_PROCESS) {
|
if (mode == MODE_PROCESS) {
|
||||||
for (long i = 0; i < cfg->process_count; ++i) {
|
for (long i = 0; i < cfg->process_count; ++i) {
|
||||||
@@ -606,15 +613,22 @@ static void aggregate_worker_memory(const bench_config_t *cfg, run_mode_t mode,
|
|||||||
}
|
}
|
||||||
long rss_kb = 0;
|
long rss_kb = 0;
|
||||||
long vsz_kb = 0;
|
long vsz_kb = 0;
|
||||||
if (read_worker_stats(workers[i].stats_path, &rss_kb, &vsz_kb) == 0) {
|
long pss_kb = 0;
|
||||||
|
FILE *f = fopen(workers[i].stats_path, "r");
|
||||||
|
if (f && fscanf(f, "%ld,%ld,%ld", &rss_kb, &vsz_kb, &pss_kb) == 3) {
|
||||||
|
fclose(f);
|
||||||
total_rss += rss_kb;
|
total_rss += rss_kb;
|
||||||
total_vsz += vsz_kb;
|
total_vsz += vsz_kb;
|
||||||
|
total_pss += pss_kb;
|
||||||
|
} else if (f) {
|
||||||
|
fclose(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metrics->agg_rss_kb = total_rss;
|
metrics->agg_rss_kb = total_rss;
|
||||||
metrics->agg_vsz_kb = total_vsz;
|
metrics->agg_vsz_kb = total_vsz;
|
||||||
|
metrics->agg_pss_kb = total_pss;
|
||||||
metrics->mem_snapshot_s = now_wall() - t0;
|
metrics->mem_snapshot_s = now_wall() - t0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,13 +649,13 @@ static void write_results_csv(const char *results_csv, const char *run_id, const
|
|||||||
kernel[sizeof(kernel) - 1] = '\0';
|
kernel[sizeof(kernel) - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(csv, "run_id,timestamp,host,kernel,mode,worker_count,pi_digits,chunk_size,exit_code,wall_s,cpu_user_s,cpu_sys_s,cpu_pct,max_rss_kb,max_vsz_kb,agg_rss_kb,agg_vsz_kb,mem_snapshot_s,final_output_bytes\n");
|
fprintf(csv, "run_id,timestamp,host,kernel,mode,worker_count,pi_digits,chunk_size,exit_code,wall_s,cpu_user_s,cpu_sys_s,cpu_pct,max_rss_kb,max_vsz_kb,agg_rss_kb,agg_vsz_kb,agg_pss_kb,mem_snapshot_s,final_output_bytes\n");
|
||||||
long workers = (strcmp(mode, "thread") == 0) ? cfg->thread_count : cfg->process_count;
|
long workers = (strcmp(mode, "thread") == 0) ? cfg->thread_count : cfg->process_count;
|
||||||
fprintf(csv, "%s,%s,%s,%s,%s,%ld,%ld,%ld,%d,%.6f,%.6f,%.6f,%.2f,%ld,%ld,%ld,%ld,%.6f,%zu\n",
|
fprintf(csv, "%s,%s,%s,%s,%s,%ld,%ld,%ld,%d,%.6f,%.6f,%.6f,%.2f,%ld,%ld,%ld,%ld,%ld,%.6f,%zu\n",
|
||||||
run_id, ts, host, kernel, mode, workers, cfg->pi_digits, cfg->chunk_size,
|
run_id, ts, host, kernel, mode, workers, cfg->pi_digits, cfg->chunk_size,
|
||||||
metrics->exit_code, metrics->wall_s, metrics->cpu_user_s, metrics->cpu_sys_s,
|
metrics->exit_code, metrics->wall_s, metrics->cpu_user_s, metrics->cpu_sys_s,
|
||||||
metrics->cpu_pct, metrics->max_rss_kb, metrics->max_vsz_kb,
|
metrics->cpu_pct, metrics->max_rss_kb, metrics->max_vsz_kb,
|
||||||
metrics->agg_rss_kb, metrics->agg_vsz_kb, metrics->mem_snapshot_s, metrics->output_bytes);
|
metrics->agg_rss_kb, metrics->agg_vsz_kb, metrics->agg_pss_kb, metrics->mem_snapshot_s, metrics->output_bytes);
|
||||||
fclose(csv);
|
fclose(csv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -741,18 +755,17 @@ int main(int argc, char **argv) {
|
|||||||
metrics.exit_code = 1;
|
metrics.exit_code = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double t_calc = now_wall();
|
||||||
|
collect_metrics(&metrics, t0, t_calc);
|
||||||
|
aggregate_worker_memory(&cfg, mode, workers, &metrics);
|
||||||
|
|
||||||
int agg_rc = concatenate_outputs(&cfg, tmp_dir, final_path, worker_count);
|
int agg_rc = concatenate_outputs(&cfg, tmp_dir, final_path, worker_count);
|
||||||
if (agg_rc != 0) {
|
if (agg_rc != 0) {
|
||||||
metrics.exit_code = 1;
|
metrics.exit_code = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
aggregate_worker_memory(&cfg, mode, workers, &metrics);
|
|
||||||
|
|
||||||
remove_dir_tree(tmp_dir);
|
remove_dir_tree(tmp_dir);
|
||||||
unlink(pid_file);
|
unlink(pid_file);
|
||||||
|
|
||||||
double t1 = now_wall();
|
|
||||||
collect_metrics(&metrics, t0, t1);
|
|
||||||
metrics.output_bytes = file_size(final_path);
|
metrics.output_bytes = file_size(final_path);
|
||||||
|
|
||||||
write_results_csv(results_csv, run_id, mode_name, &cfg, &metrics);
|
write_results_csv(results_csv, run_id, mode_name, &cfg, &metrics);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ RUN_ID=$(date +"%Y%m%d_%H%M%S")
|
|||||||
|
|
||||||
RESULTS_CSV="$DIR/results.csv"
|
RESULTS_CSV="$DIR/results.csv"
|
||||||
if [ ! -f "$RESULTS_CSV" ]; then
|
if [ ! -f "$RESULTS_CSV" ]; then
|
||||||
echo "run_id,timestamp,host,kernel,mode,worker_count,pi_digits,chunk_size,exit_code,wall_s,cpu_user_s,cpu_sys_s,cpu_pct,max_rss_kb,max_vsz_kb,agg_rss_kb,agg_vsz_kb,mem_snapshot_s,final_output_bytes" > "$RESULTS_CSV"
|
echo "run_id,timestamp,host,kernel,mode,worker_count,pi_digits,chunk_size,exit_code,wall_s,cpu_user_s,cpu_sys_s,cpu_pct,max_rss_kb,max_vsz_kb,agg_rss_kb,agg_vsz_kb,agg_pss_kb,mem_snapshot_s,final_output_bytes" > "$RESULTS_CSV"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
run_mode() {
|
run_mode() {
|
||||||
|
|||||||
Reference in New Issue
Block a user