1 /* 2 * Disktest 3 * Copyright (c) International Business Machines Corp., 2001 4 * 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 * 20 * Please send e-mail to yardleyb (at) us.ibm.com if you have 21 * questions or comments. 22 * 23 * Project Website: TBD 24 * 25 * $Id: stats.c,v 1.2 2008/02/14 08:22:24 subrata_modak Exp $ 26 * 27 */ 28 #include <stdio.h> 29 #ifdef WINDOWS 30 #include <windows.h> 31 #include <winioctl.h> 32 #include <io.h> 33 #include <process.h> 34 #include <sys/stat.h> 35 #include "getopt.h" 36 #else 37 #include <sys/types.h> 38 #include <unistd.h> 39 #endif 40 #include <stdlib.h> 41 #include <stdarg.h> 42 #include <signal.h> 43 #include <time.h> 44 #include <errno.h> 45 #include <fcntl.h> 46 #include <string.h> 47 #include <ctype.h> 48 49 #include "defs.h" 50 #include "globals.h" 51 #include "sfunc.h" 52 #include "threading.h" 53 #include "stats.h" 54 55 void print_stats(child_args_t * args, test_env_t * env, statop_t operation) 56 { 57 extern time_t global_start_time; /* global pointer to overall start */ 58 extern unsigned long glb_flags; /* global flags GLB_FLG_xxx */ 59 60 time_t curr_time = 0, hwrite_time = 0, hread_time = 0, write_time = 61 0, read_time = 0, gw_time = 0, gr_time = 0; 62 fmt_time_t time_struct; 63 64 curr_time = time(NULL); 65 66 if ((curr_time - env->start_time) == 0) 67 curr_time++; 68 69 if ((args->flags & CLD_FLG_LINEAR) && !(args->flags & CLD_FLG_NTRLVD)) { 70 hread_time = env->hbeat_stats.rtime; 71 hwrite_time = env->hbeat_stats.wtime; 72 read_time = env->cycle_stats.rtime; 73 write_time = env->cycle_stats.wtime; 74 gr_time = env->global_stats.rtime; 75 gw_time = env->global_stats.wtime; 76 } else { 77 hread_time = ((env->hbeat_stats.rtime * args->rperc) / 100); 78 hwrite_time = ((env->hbeat_stats.wtime * args->wperc) / 100); 79 read_time = ((env->cycle_stats.rtime * args->rperc) / 100); 80 write_time = ((env->cycle_stats.wtime * args->wperc) / 100); 81 gr_time = 82 (time_t) ((env->global_stats.rtime * args->rperc) / 100); 83 gw_time = 84 (time_t) ((env->global_stats.wtime * args->wperc) / 100); 85 } 86 87 /* if one second really has not passed, then make it at least one second */ 88 if (hread_time == 0) 89 hread_time++; 90 if (hwrite_time == 0) 91 hwrite_time++; 92 if (read_time == 0) 93 read_time++; 94 if (write_time == 0) 95 write_time++; 96 if (gr_time == 0) 97 gr_time++; 98 if (gw_time == 0) 99 gw_time++; 100 101 if (glb_flags & GLB_FLG_PERFP) { 102 if (args->flags & CLD_FLG_PRFTYPS) { 103 printf("%s;", args->device); 104 } 105 switch (operation) { 106 case HBEAT: /* only display current HBEAT stats */ 107 if ((args->flags & CLD_FLG_XFERS)) { 108 printf(CTRSTR, (env->hbeat_stats.rbytes), 109 (env->hbeat_stats.rcount)); 110 printf(CTWSTR, (env->hbeat_stats.wbytes), 111 (env->hbeat_stats.wcount)); 112 } 113 if ((args->flags & CLD_FLG_TPUTS)) { 114 printf(CTRRSTR, 115 ((double)(env->hbeat_stats.rbytes) / 116 (double)(hread_time)), 117 ((double)(env->hbeat_stats.rcount) / 118 (double)(hread_time))); 119 printf(CTRWSTR, 120 ((double)(env->hbeat_stats.wbytes) / 121 (double)(hwrite_time)), 122 ((double)(env->hbeat_stats.wcount) / 123 (double)(hwrite_time))); 124 } 125 if ((args->flags & CLD_FLG_RUNT)) { 126 printf("%lu;Rsecs;%lu;Wsecs;", hread_time, 127 hwrite_time); 128 } 129 break; 130 case CYCLE: /* only display current CYCLE stats */ 131 if ((args->flags & CLD_FLG_XFERS)) { 132 printf(CTRSTR, (env->cycle_stats.rbytes), 133 (env->cycle_stats.rcount)); 134 printf(CTWSTR, (env->cycle_stats.wbytes), 135 (env->cycle_stats.wcount)); 136 } 137 if ((args->flags & CLD_FLG_TPUTS)) { 138 printf(CTRRSTR, 139 ((double)(env->cycle_stats.rbytes) / 140 (double)(read_time)), 141 ((double)(env->cycle_stats.rcount) / 142 (double)(read_time))); 143 printf(CTRWSTR, 144 ((double)(env->cycle_stats.wbytes) / 145 (double)(write_time)), 146 ((double)(env->cycle_stats.wcount) / 147 (double)(write_time))); 148 } 149 if ((args->flags & CLD_FLG_RUNT)) { 150 printf("%lu;Rsecs;%lu;Wsecs;", read_time, 151 write_time); 152 } 153 break; 154 case TOTAL: /* display total read and write stats */ 155 if ((args->flags & CLD_FLG_XFERS)) { 156 printf(TCTRSTR, (env->global_stats.rbytes), 157 (env->global_stats.rcount)); 158 printf(TCTWSTR, (env->global_stats.wbytes), 159 (env->global_stats.wcount)); 160 } 161 if ((args->flags & CLD_FLG_TPUTS)) { 162 printf(TCTRRSTR, 163 ((double)(env->global_stats.rbytes) / 164 (double)(gr_time)), 165 ((double)(env->global_stats.rcount) / 166 (double)(gr_time))); 167 printf(TCTRWSTR, 168 ((double)(env->global_stats.wbytes) / 169 (double)(gw_time)), 170 ((double)(env->global_stats.wcount) / 171 (double)(gw_time))); 172 } 173 if ((args->flags & CLD_FLG_RUNT)) { 174 printf("%lu;secs;", 175 (curr_time - env->start_time)); 176 } 177 break; 178 default: 179 pMsg(ERR, args, "Unknown stats display type.\n"); 180 } 181 182 if (args->flags & CLD_FLG_PRFTYPS) { 183 printf("\n"); 184 } 185 } else { 186 if ((args->flags & CLD_FLG_XFERS)) { 187 switch (operation) { 188 case HBEAT: /* only display current HBEAT stats */ 189 if (args->flags & CLD_FLG_R) { 190 pMsg(STAT, args, HRTSTR, 191 (env->hbeat_stats.rbytes), 192 (env->hbeat_stats.rcount)); 193 } 194 if (args->flags & CLD_FLG_W) { 195 pMsg(STAT, args, HWTSTR, 196 (env->hbeat_stats.wbytes), 197 (env->hbeat_stats.wcount)); 198 } 199 break; 200 case CYCLE: /* only display current CYCLE stats */ 201 if (args->flags & CLD_FLG_R) { 202 pMsg(STAT, args, CRTSTR, 203 (env->cycle_stats.rbytes), 204 (env->cycle_stats.rcount)); 205 } 206 if (args->flags & CLD_FLG_W) { 207 pMsg(STAT, args, CWTSTR, 208 (env->cycle_stats.wbytes), 209 (env->cycle_stats.wcount)); 210 } 211 break; 212 case TOTAL: /* display total read and write stats */ 213 if (args->flags & CLD_FLG_R) { 214 pMsg(STAT, args, TRTSTR, 215 (env->global_stats.rcount), 216 (env->global_stats.rbytes)); 217 } 218 if (args->flags & CLD_FLG_W) { 219 pMsg(STAT, args, TWTSTR, 220 (env->global_stats.wcount), 221 (env->global_stats.wbytes)); 222 } 223 break; 224 default: 225 pMsg(ERR, args, 226 "Unknown stats display type.\n"); 227 } 228 } 229 230 if ((args->flags & CLD_FLG_TPUTS)) { 231 switch (operation) { 232 case HBEAT: /* only display current read stats */ 233 if (args->flags & CLD_FLG_R) { 234 pMsg(STAT, args, HRTHSTR, 235 ((double)env->hbeat_stats.rbytes / 236 (double)(hread_time)), 237 (((double)env->hbeat_stats.rbytes / 238 (double)hread_time) / 239 (double)1048576.), 240 ((double)env->hbeat_stats.rcount / 241 (double)(hread_time))); 242 } 243 if (args->flags & CLD_FLG_W) { 244 pMsg(STAT, args, HWTHSTR, 245 ((double)env->hbeat_stats.wbytes / 246 (double)hwrite_time), 247 (((double)env->hbeat_stats.wbytes / 248 (double)hwrite_time) / 249 (double)1048576.), 250 ((double)env->hbeat_stats.wcount / 251 (double)hwrite_time)); 252 } 253 break; 254 case CYCLE: /* only display current read stats */ 255 if (args->flags & CLD_FLG_R) { 256 pMsg(STAT, args, CRTHSTR, 257 ((double)env->cycle_stats.rbytes / 258 (double)(read_time)), 259 (((double)env->cycle_stats.rbytes / 260 (double)read_time) / 261 (double)1048576.), 262 ((double)env->cycle_stats.rcount / 263 (double)(read_time))); 264 } 265 if (args->flags & CLD_FLG_W) { 266 pMsg(STAT, args, CWTHSTR, 267 ((double)env->cycle_stats.wbytes / 268 (double)write_time), 269 (((double)env->cycle_stats.wbytes / 270 (double)write_time) / 271 (double)1048576.), 272 ((double)env->cycle_stats.wcount / 273 (double)write_time)); 274 } 275 break; 276 case TOTAL: /* display total read and write stats */ 277 if (args->flags & CLD_FLG_R) { 278 pMsg(STAT, args, TRTHSTR, 279 ((double)env->global_stats.rbytes / 280 (double)gr_time), 281 (((double)env->global_stats. 282 rbytes / (double)gr_time) / 283 (double)1048576.), 284 ((double)env->global_stats.rcount / 285 (double)gr_time)); 286 } 287 if (args->flags & CLD_FLG_W) { 288 pMsg(STAT, args, TWTHSTR, 289 ((double)env->global_stats.wbytes / 290 (double)gw_time), 291 (((double)env->global_stats. 292 wbytes / (double)gw_time) / 293 (double)1048576.), 294 ((double)env->global_stats.wcount / 295 (double)gw_time)); 296 } 297 break; 298 default: 299 pMsg(ERR, args, 300 "Unknown stats display type.\n"); 301 } 302 } 303 if (args->flags & CLD_FLG_RUNT) { 304 switch (operation) { 305 case HBEAT: /* only display current cycle stats */ 306 if (args->flags & CLD_FLG_R) { 307 time_struct = format_time(hread_time); 308 pMsg(STAT, args, 309 "Heartbeat Read Time: %u seconds (%luh%lum%lus)\n", 310 hread_time, time_struct.hours, 311 time_struct.minutes, 312 time_struct.seconds); 313 } 314 if (args->flags & CLD_FLG_W) { 315 time_struct = format_time(hwrite_time); 316 pMsg(STAT, args, 317 "Heartbeat Write Time: %u seconds (%luh%lum%lus)\n", 318 hwrite_time, time_struct.hours, 319 time_struct.minutes, 320 time_struct.seconds); 321 } 322 break; 323 case CYCLE: /* only display current cycle stats */ 324 if (args->flags & CLD_FLG_R) { 325 time_struct = format_time(read_time); 326 pMsg(STAT, args, 327 "Cycle Read Time: %u seconds (%luh%lum%lus)\n", 328 read_time, time_struct.hours, 329 time_struct.minutes, 330 time_struct.seconds); 331 } 332 if (args->flags & CLD_FLG_W) { 333 time_struct = format_time(write_time); 334 pMsg(STAT, args, 335 "Cycle Write Time: %u seconds (%luh%lum%lus)\n", 336 write_time, time_struct.hours, 337 time_struct.minutes, 338 time_struct.seconds); 339 } 340 break; 341 case TOTAL: 342 if (args->flags & CLD_FLG_R) { 343 time_struct = format_time(gr_time); 344 pMsg(STAT, args, 345 "Total Read Time: %u seconds (%lud%luh%lum%lus)\n", 346 gr_time, time_struct.days, 347 time_struct.hours, 348 time_struct.minutes, 349 time_struct.seconds); 350 } 351 if (args->flags & CLD_FLG_W) { 352 time_struct = format_time(gw_time); 353 pMsg(STAT, args, 354 "Total Write Time: %u seconds (%lud%luh%lum%lus)\n", 355 gw_time, time_struct.days, 356 time_struct.hours, 357 time_struct.minutes, 358 time_struct.seconds); 359 } 360 time_struct = 361 format_time((curr_time - 362 global_start_time)); 363 pMsg(STAT, args, 364 "Total overall runtime: %u seconds (%lud%luh%lum%lus)\n", 365 (curr_time - global_start_time), 366 time_struct.days, time_struct.hours, 367 time_struct.minutes, time_struct.seconds); 368 break; 369 default: 370 pMsg(ERR, args, 371 "Unknown stats display type.\n"); 372 } 373 } 374 } 375 } 376 377 void update_gbl_stats(test_env_t * env) 378 { 379 env->global_stats.wcount += env->cycle_stats.wcount; 380 env->global_stats.rcount += env->cycle_stats.rcount; 381 env->global_stats.wbytes += env->cycle_stats.wbytes; 382 env->global_stats.rbytes += env->cycle_stats.rbytes; 383 env->global_stats.wtime += env->cycle_stats.wtime; 384 env->global_stats.rtime += env->cycle_stats.rtime; 385 386 env->cycle_stats.wcount = 0; 387 env->cycle_stats.rcount = 0; 388 env->cycle_stats.wbytes = 0; 389 env->cycle_stats.rbytes = 0; 390 env->cycle_stats.wtime = 0; 391 env->cycle_stats.rtime = 0; 392 } 393 394 void update_cyc_stats(test_env_t * env) 395 { 396 env->cycle_stats.wcount += env->hbeat_stats.wcount; 397 env->cycle_stats.rcount += env->hbeat_stats.rcount; 398 env->cycle_stats.wbytes += env->hbeat_stats.wbytes; 399 env->cycle_stats.rbytes += env->hbeat_stats.rbytes; 400 env->cycle_stats.wtime += env->hbeat_stats.wtime; 401 env->cycle_stats.rtime += env->hbeat_stats.rtime; 402 403 env->hbeat_stats.wcount = 0; 404 env->hbeat_stats.rcount = 0; 405 env->hbeat_stats.wbytes = 0; 406 env->hbeat_stats.rbytes = 0; 407 env->hbeat_stats.wtime = 0; 408 env->hbeat_stats.rtime = 0; 409 } 410