Skip to content

Commit f13c9b2

Browse files
committed
libflow: add parameter measurement_boundary to end_measurement()
Introduce parameter measurement_boundary to end_measurement(), pass true in f3write.c and f3read.c since they make measurements on files (i.e., a file is a measurement boundary), and pass false for everyone else. Reaching a boundary forces any leftover processed_blocks and acc_delay_ns to be committed to the global statistics. This prevents measurement data from bleeding across boundaries.
1 parent 5f91ed7 commit f13c9b2

6 files changed

Lines changed: 17 additions & 11 deletions

File tree

src/f3brew.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static void write_blocks(struct device *dev, struct flow *fw,
296296
measure(fw, blocks_to_write, NULL);
297297
first_pos = next_pos;
298298
}
299-
end_measurement(fw);
299+
end_measurement(fw, false);
300300
dbuf_free(&dbuf);
301301
}
302302

@@ -452,7 +452,7 @@ static void read_blocks(struct device *dev, struct flow *fw,
452452
measure(fw, blocks_to_read, NULL);
453453
first_pos = next_pos;
454454
}
455-
end_measurement(fw);
455+
end_measurement(fw, false);
456456
dbuf_free(&dbuf);
457457

458458
if (range.state != bs_unknown)

src/f3read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static void validate_file(struct flow *fw, struct dynamic_buffer *dbuf,
291291
break;
292292
}
293293
}
294-
end_measurement(fw);
294+
end_measurement(fw, true);
295295
assert(!clock_gettime(CLOCK_MONOTONIC, &file_t2));
296296

297297
print_status(stats);

src/f3write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static int create_and_fill_file(struct flow *fw, struct dynamic_buffer *dbuf,
259259
if (saved_errno != 0)
260260
break;
261261
}
262-
end_measurement(fw);
262+
end_measurement(fw, true);
263263
assert(!clock_gettime(CLOCK_MONOTONIC, &file_t2));
264264
close(fd);
265265
free(full_fn);

src/libflow.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,19 @@ void measure(struct flow *fw, uint64_t processed_blocks,
457457
__start_measurement(fw);
458458
}
459459

460-
void end_measurement(struct flow *fw)
460+
void end_measurement(struct flow *fw, bool measurement_boundary)
461461
{
462462
if (fw->processed_blocks > 0) {
463-
/* Track progress in between files. */
463+
/* Track progress in between measurement boundaries. */
464464
struct timespec t2;
465465
assert(!clock_gettime(CLOCK_MONOTONIC, &t2));
466466
fw->acc_delay_ns += diff_timespec_ns(&fw->t1, &t2);
467+
if (measurement_boundary) {
468+
fw->measured_blocks += fw->processed_blocks;
469+
fw->measured_time_ns += fw->acc_delay_ns;
470+
fw->processed_blocks = 0;
471+
fw->acc_delay_ns = 0;
472+
}
467473
}
468474
clear_progress(fw); /* Erase progress information. */
469475
}

src/libflow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void start_measurement(struct flow *fw);
120120
void measure(struct flow *fw, uint64_t processed_blocks,
121121
struct fw_measurement *m);
122122
void clear_progress(struct flow *fw);
123-
void end_measurement(struct flow *fw);
123+
void end_measurement(struct flow *fw, bool measurement_boundary);
124124

125125
void print_avg_seq_speed(const struct flow *fw, const char *speed_type,
126126
bool use_sectors);

src/libprobe.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static int write_random_blocks(struct device *dev, const uint64_t pos[],
7979
return true;
8080
measure(&rwi->randw_fw, 1, NULL);
8181
}
82-
end_measurement(&rwi->randw_fw);
82+
end_measurement(&rwi->randw_fw, false);
8383
return false;
8484
}
8585

@@ -128,7 +128,7 @@ static int write_blocks(struct device *dev,
128128
measure(&rwi->seqw_fw, blocks_to_write, NULL);
129129
first_pos = next_pos;
130130
}
131-
end_measurement(&rwi->seqw_fw);
131+
end_measurement(&rwi->seqw_fw, false);
132132
return false;
133133
}
134134

@@ -231,11 +231,11 @@ static int find_first_x_block(struct device *dev,
231231
/* Found the first x_block. */
232232
*pfirst_x_block_idx = i;
233233
*pstate = bs;
234-
end_measurement(&rwi->randr_fw);
234+
end_measurement(&rwi->randr_fw, false);
235235
return false;
236236
}
237237
}
238-
end_measurement(&rwi->randr_fw);
238+
end_measurement(&rwi->randr_fw, false);
239239

240240
not_found:
241241
*pfirst_x_block_idx = n_blocks;

0 commit comments

Comments
 (0)