Skip to content

Commit 7612959

Browse files
author
VadimTk
committed
Calculate response time properly
1 parent cfabf7c commit 7612959

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/driver.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern int* retry2[];
3939
extern int* failure2[];
4040

4141
extern double max_rt[];
42+
extern double total_rt[];
4243

4344
extern long clk_tck;
4445

@@ -131,10 +132,10 @@ static int do_neword (int t_num)
131132
qty[i] = RandomNumber(1, 10);
132133
}
133134

134-
clk1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf1 );
135+
clk1 = clock_gettime(CLOCK_MONOTONIC, &tbuf1 );
135136
for (i = 0; i < MAX_RETRY; i++) {
136137
ret = neword(t_num, w_id, d_id, c_id, ol_cnt, all_local, itemid, supware, qty);
137-
clk2 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf2 );
138+
clk2 = clock_gettime(CLOCK_MONOTONIC, &tbuf2 );
138139

139140
if(ret){
140141

@@ -146,6 +147,7 @@ static int do_neword (int t_num)
146147

147148
if(rt > max_rt[0])
148149
max_rt[0]=rt;
150+
total_rt[0] += rt;
149151
hist_inc(0, rt);
150152
if(counting_on){
151153
if( rt < RTIME_NEWORD ){
@@ -229,16 +231,17 @@ static int do_payment (int t_num)
229231
c_d_id = RandomNumber(1, DIST_PER_WARE);
230232
}
231233

232-
clk1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf1 );
234+
clk1 = clock_gettime(CLOCK_MONOTONIC, &tbuf1 );
233235
for (i = 0; i < MAX_RETRY; i++) {
234236
ret = payment(t_num, w_id, d_id, byname, c_w_id, c_d_id, c_id, c_last, h_amount);
235-
clk2 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf2 );
237+
clk2 = clock_gettime(CLOCK_MONOTONIC, &tbuf2 );
236238

237239
if(ret){
238240

239241
rt = (double)(tbuf2.tv_sec * 1000.0 + tbuf2.tv_nsec/1000000.0-tbuf1.tv_sec * 1000.0 - tbuf1.tv_nsec/1000000.0);
240242
if(rt > max_rt[1])
241243
max_rt[1]=rt;
244+
total_rt[1] += rt;
242245
hist_inc(1, rt);
243246
if(counting_on){
244247
if( rt < RTIME_PAYMENT ){
@@ -301,16 +304,17 @@ static int do_ordstat (int t_num)
301304
byname = 0; /* select by customer id */
302305
}
303306

304-
clk1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf1 );
307+
clk1 = clock_gettime(CLOCK_MONOTONIC, &tbuf1 );
305308
for (i = 0; i < MAX_RETRY; i++) {
306309
ret = ordstat(t_num, w_id, d_id, byname, c_id, c_last);
307-
clk2 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf2 );
310+
clk2 = clock_gettime(CLOCK_MONOTONIC, &tbuf2 );
308311

309312
if(ret){
310313

311314
rt = (double)(tbuf2.tv_sec * 1000.0 + tbuf2.tv_nsec/1000000.0-tbuf1.tv_sec * 1000.0 - tbuf1.tv_nsec/1000000.0);
312315
if(rt > max_rt[2])
313316
max_rt[2]=rt;
317+
total_rt[2] += rt;
314318
hist_inc(2, rt);
315319
if(counting_on){
316320
if( rt < RTIME_ORDSTAT ){
@@ -366,16 +370,17 @@ static int do_delivery (int t_num)
366370
}
367371
o_carrier_id = RandomNumber(1, 10);
368372

369-
clk1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf1 );
373+
clk1 = clock_gettime(CLOCK_MONOTONIC, &tbuf1 );
370374
for (i = 0; i < MAX_RETRY; i++) {
371375
ret = delivery(t_num, w_id, o_carrier_id);
372-
clk2 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf2 );
376+
clk2 = clock_gettime(CLOCK_MONOTONIC, &tbuf2 );
373377

374378
if(ret){
375379

376380
rt = (double)(tbuf2.tv_sec * 1000.0 + tbuf2.tv_nsec/1000000.0-tbuf1.tv_sec * 1000.0 - tbuf1.tv_nsec/1000000.0);
377381
if(rt > max_rt[3])
378382
max_rt[3]=rt;
383+
total_rt[3] += rt;
379384
hist_inc(3, rt );
380385
if(counting_on){
381386
if( rt < RTIME_DELIVERY ){
@@ -432,16 +437,17 @@ static int do_slev (int t_num)
432437
d_id = RandomNumber(1, DIST_PER_WARE);
433438
level = RandomNumber(10, 20);
434439

435-
clk1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf1 );
440+
clk1 = clock_gettime(CLOCK_MONOTONIC, &tbuf1 );
436441
for (i = 0; i < MAX_RETRY; i++) {
437442
ret = slev(t_num, w_id, d_id, level);
438-
clk2 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf2 );
443+
clk2 = clock_gettime(CLOCK_MONOTONIC, &tbuf2 );
439444

440445
if(ret){
441446

442447
rt = (double)(tbuf2.tv_sec * 1000.0 + tbuf2.tv_nsec/1000000.0-tbuf1.tv_sec * 1000.0 - tbuf1.tv_nsec/1000000.0);
443448
if(rt > max_rt[4])
444449
max_rt[4]=rt;
450+
total_rt[4] += rt;
445451
hist_inc(4, rt );
446452
if(counting_on){
447453
if( rt < RTIME_SLEV ){

src/main.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ int prev_s[5];
7272
int prev_l[5];
7373

7474
double max_rt[5];
75+
double total_rt[5];
7576
double cur_max_rt[5];
7677

78+
double prev_total_rt[5];
79+
7780
int activate_transaction;
7881
int counting_on;
7982

@@ -124,8 +127,10 @@ int main( int argc, char *argv[] )
124127

125128
prev_s[i]=0;
126129
prev_l[i]=0;
127-
130+
131+
prev_total_rt[i] = 0.0;
128132
max_rt[i]=0.0;
133+
total_rt[i]=0.0;
129134
}
130135

131136
/* dummy initialize*/
@@ -592,15 +597,18 @@ void alarm_handler(int signum)
592597
int i;
593598
int s[5],l[5];
594599
double rt90[5];
600+
double trt[5];
595601

596602
for( i=0; i<5; i++ ){
597603
s[i] = success[i];
598604
l[i] = late[i];
605+
trt[i] = total_rt[i];
599606
rt90[i] = hist_ckp(i);
600607
}
601608

602609
time_count += PRINT_INTERVAL;
603-
printf("%4d, %d:%.3f|%.3f, %d:%.3f|%.3f, %d:%.3f|%.3f, %d:%.3f, %d:%.3f|%.3f\n",
610+
// printf("%4d, %d:%.3f|%.3f(%.3f), %d:%.3f|%.3f(%.3f), %d:%.3f|%.3f(%.3f), %d:%.3f|%.3f(%.3f), %d:%.3f|%.3f(%.3f)\n",
611+
printf("%4d, %d:%.3f|%.3f, %d:%.3f|%.3f, %d:%.3f|%.3f, %d:%.3f|%.3f, %d:%.3f|%.3f\n",
604612
time_count,
605613
( s[0] + l[0] - prev_s[0] - prev_l[0] ),
606614
rt90[0],(double)cur_max_rt[0],
@@ -618,6 +626,7 @@ void alarm_handler(int signum)
618626
for( i=0; i<5; i++ ){
619627
prev_s[i] = s[i];
620628
prev_l[i] = l[i];
629+
prev_total_rt[i] = trt[i];
621630
cur_max_rt[i]=0.0;
622631
}
623632
}

0 commit comments

Comments
 (0)