Skip to content

Commit 7652659

Browse files
committed
stat: Fix to show latency stats changed depth levels
1 parent 0f9d541 commit 7652659

File tree

1 file changed

+55
-50
lines changed

1 file changed

+55
-50
lines changed

stat.c

+55-50
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#define STAT_LAT_NR_DEF 10
2323
#define STAT_LAT_RANGE_MAX 1000
24+
#define STAT_NAME_LEN 20
2425

2526
struct fio_sem *stat_sem;
2627

@@ -804,11 +805,25 @@ static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
804805
}
805806
}
806807

807-
static bool show_lat(double *io_u_lat, int nr, const char **ranges,
808-
const char *msg, struct buf_output *out)
808+
static int stat_get_range(int i)
809+
{
810+
int range = STAT_LAT_RANGE_MAX;
811+
812+
if (i + 1 >= stat_lat_nr)
813+
range *= i + 2 - stat_lat_nr;
814+
else
815+
range = stat_lat_ranges[i + 1];
816+
817+
return range;
818+
}
819+
820+
static bool show_lat(double *io_u_lat, int nr, const char *msg,
821+
struct buf_output *out)
809822
{
810823
bool new_line = true, shown = false;
811824
int i, line = 0;
825+
int range;
826+
int range_max = STAT_LAT_RANGE_MAX * 2;
812827

813828
for (i = 0; i < nr; i++) {
814829
if (io_u_lat[i] <= 0.0)
@@ -823,7 +838,9 @@ static bool show_lat(double *io_u_lat, int nr, const char **ranges,
823838
}
824839
if (line)
825840
log_buf(out, ", ");
826-
log_buf(out, "%s%3.2f%%", ranges[i], io_u_lat[i]);
841+
range = stat_get_range(i);
842+
log_buf(out, "%s%d=%3.2f%%", range > range_max ? ">=" : "",
843+
range > range_max ? range_max : range, io_u_lat[i]);
827844
line++;
828845
if (line == 5)
829846
new_line = true;
@@ -837,27 +854,17 @@ static bool show_lat(double *io_u_lat, int nr, const char **ranges,
837854

838855
static void show_lat_n(double *io_u_lat_n, struct buf_output *out)
839856
{
840-
const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
841-
"250=", "500=", "750=", "1000=", };
842-
843-
show_lat(io_u_lat_n, FIO_IO_U_LAT_N_NR, ranges, "nsec", out);
857+
show_lat(io_u_lat_n, FIO_IO_U_LAT_N_NR, "nsec", out);
844858
}
845859

846860
static void show_lat_u(double *io_u_lat_u, struct buf_output *out)
847861
{
848-
const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
849-
"250=", "500=", "750=", "1000=", };
850-
851-
show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec", out);
862+
show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, "usec", out);
852863
}
853864

854865
static void show_lat_m(double *io_u_lat_m, struct buf_output *out)
855866
{
856-
const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
857-
"250=", "500=", "750=", "1000=", "2000=",
858-
">=2000=", };
859-
860-
show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec", out);
867+
show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, "msec", out);
861868
}
862869

863870
static void show_latencies(struct thread_stat *ts, struct buf_output *out)
@@ -1811,6 +1818,9 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
18111818
double usr_cpu, sys_cpu;
18121819
int i;
18131820
size_t size;
1821+
char name[STAT_NAME_LEN];
1822+
int range;
1823+
int range_max = STAT_LAT_RANGE_MAX * 2;
18141824

18151825
root = json_create_object();
18161826
json_object_add_value_string(root, "jobname", ts->name);
@@ -1858,11 +1868,10 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
18581868
json_object_add_value_object(root, "iodepth_level", tmp);
18591869
/* Only show fixed 7 I/O depth levels*/
18601870
for (i = 0; i < 7; i++) {
1861-
char name[20];
18621871
if (i < 6)
1863-
snprintf(name, 20, "%d", 1 << i);
1872+
snprintf(name, STAT_NAME_LEN, "%d", 1 << i);
18641873
else
1865-
snprintf(name, 20, ">=%d", 1 << i);
1874+
snprintf(name, STAT_NAME_LEN, ">=%d", 1 << i);
18661875
json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]);
18671876
}
18681877

@@ -1872,13 +1881,12 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
18721881
json_object_add_value_object(root, "iodepth_submit", tmp);
18731882
/* Only show fixed 7 I/O depth levels*/
18741883
for (i = 0; i < 7; i++) {
1875-
char name[20];
18761884
if (i == 0)
1877-
snprintf(name, 20, "0");
1885+
snprintf(name, STAT_NAME_LEN, "0");
18781886
else if (i < 6)
1879-
snprintf(name, 20, "%d", 1 << (i+1));
1887+
snprintf(name, STAT_NAME_LEN, "%d", 1 << (i+1));
18801888
else
1881-
snprintf(name, 20, ">=%d", 1 << i);
1889+
snprintf(name, STAT_NAME_LEN, ">=%d", 1 << i);
18821890
json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]);
18831891
}
18841892

@@ -1888,13 +1896,12 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
18881896
json_object_add_value_object(root, "iodepth_complete", tmp);
18891897
/* Only show fixed 7 I/O depth levels*/
18901898
for (i = 0; i < 7; i++) {
1891-
char name[20];
18921899
if (i == 0)
1893-
snprintf(name, 20, "0");
1900+
snprintf(name, STAT_NAME_LEN, "0");
18941901
else if (i < 6)
1895-
snprintf(name, 20, "%d", 1 << (i+1));
1902+
snprintf(name, STAT_NAME_LEN, "%d", 1 << (i+1));
18961903
else
1897-
snprintf(name, 20, ">=%d", 1 << i);
1904+
snprintf(name, STAT_NAME_LEN, ">=%d", 1 << i);
18981905
json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]);
18991906
}
19001907

@@ -1908,26 +1915,25 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
19081915
tmp = json_create_object();
19091916
json_object_add_value_object(root, "latency_ns", tmp);
19101917
for (i = 0; i < FIO_IO_U_LAT_N_NR; i++) {
1911-
const char *ranges[] = { "2", "4", "10", "20", "50", "100",
1912-
"250", "500", "750", "1000", };
1913-
json_object_add_value_float(tmp, ranges[i], io_u_lat_n[i]);
1918+
snprintf(name, STAT_NAME_LEN, "%d", stat_get_range(i));
1919+
json_object_add_value_float(tmp, name, io_u_lat_n[i]);
19141920
}
19151921
/* Microsecond latency */
19161922
tmp = json_create_object();
19171923
json_object_add_value_object(root, "latency_us", tmp);
19181924
for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
1919-
const char *ranges[] = { "2", "4", "10", "20", "50", "100",
1920-
"250", "500", "750", "1000", };
1921-
json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]);
1925+
snprintf(name, STAT_NAME_LEN, "%d", stat_get_range(i));
1926+
json_object_add_value_float(tmp, name, io_u_lat_u[i]);
19221927
}
19231928
/* Millisecond latency */
19241929
tmp = json_create_object();
19251930
json_object_add_value_object(root, "latency_ms", tmp);
19261931
for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) {
1927-
const char *ranges[] = { "2", "4", "10", "20", "50", "100",
1928-
"250", "500", "750", "1000", "2000",
1929-
">=2000", };
1930-
json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]);
1932+
range = stat_get_range(i);
1933+
snprintf(name, STAT_NAME_LEN, "%s%d",
1934+
range > range_max ? ">=" : "",
1935+
range > range_max ? range_max : range);
1936+
json_object_add_value_float(tmp, name, io_u_lat_m[i]);
19311937
}
19321938

19331939
/* Additional output if continue_on_error set - default off*/
@@ -3480,16 +3486,13 @@ void stat_alloc_lat_ranges(void)
34803486
int width_nr = sizeof(widths) / sizeof(widths[0]);
34813487
int idx = width_nr - 1;
34823488

3483-
if (stat_lat_ranges)
3484-
return;
3485-
34863489
for (i = 0; i < width_nr; i++) {
34873490
widths[i] = widths[i] * STAT_LAT_NR_DEF / stat_lat_nr;
34883491
if (!widths[i])
34893492
widths[i]++;
34903493
}
34913494

3492-
stat_lat_ranges = calloc(stat_lat_nr, sizeof(int));
3495+
stat_lat_ranges = scalloc(stat_lat_nr, sizeof(int));
34933496

34943497
for (i = stat_lat_nr; i; i--) {
34953498
if (range > widths[idx])
@@ -3508,23 +3511,25 @@ void stat_alloc_lat_ranges(void)
35083511
}
35093512

35103513
for (i = 0; i < stat_lat_nr; i++)
3511-
dprint(FD_STAT, "range[%d]: %d\n", i, stat_lat_ranges[i]);
3514+
dprint(FD_STAT, "lat_range[%d]: %d\n", i, stat_lat_ranges[i]);
35123515
}
35133516

35143517
void stat_alloc_lat(struct thread_stat *ts)
35153518
{
3516-
ts->io_u_lat_n = calloc(FIO_IO_U_LAT_N_NR, sizeof(uint64_t));
3517-
ts->io_u_lat_u = calloc(FIO_IO_U_LAT_U_NR, sizeof(uint64_t));
3518-
ts->io_u_lat_m = calloc(FIO_IO_U_LAT_M_NR, sizeof(uint64_t));
3519-
stat_alloc_lat_ranges();
3519+
ts->io_u_lat_n = scalloc(FIO_IO_U_LAT_N_NR, sizeof(uint64_t));
3520+
ts->io_u_lat_u = scalloc(FIO_IO_U_LAT_U_NR, sizeof(uint64_t));
3521+
ts->io_u_lat_m = scalloc(FIO_IO_U_LAT_M_NR, sizeof(uint64_t));
3522+
3523+
if (!stat_lat_ranges)
3524+
stat_alloc_lat_ranges();
35203525
}
35213526

35223527
void stat_free_lat(struct thread_stat *ts)
35233528
{
3524-
free(ts->io_u_lat_n);
3525-
free(ts->io_u_lat_u);
3526-
free(ts->io_u_lat_m);
3527-
free(stat_lat_ranges);
3529+
sfree(ts->io_u_lat_n);
3530+
sfree(ts->io_u_lat_u);
3531+
sfree(ts->io_u_lat_m);
3532+
sfree(stat_lat_ranges);
35283533
stat_lat_ranges = NULL;
35293534
}
35303535

0 commit comments

Comments
 (0)