1/* 2 * blktrace output analysis: generate a timeline & gather statistics 3 * 4 * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com> 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 */ 21#include <stdio.h> 22#include <string.h> 23#include <unistd.h> 24#include <sys/time.h> 25#include <time.h> 26#include "globals.h" 27 28char bt_timeline_version[] = "2.08"; 29 30char *devices, *exes, *input_name, *output_name, *seek_name, *bno_dump_name; 31char *d2c_name, *q2c_name, *per_io_name, *unplug_hist_name; 32char *sps_name, *aqd_name, *q2d_name, *per_io_trees; 33FILE *rngs_ofp, *avgs_ofp, *xavgs_ofp, *per_io_ofp, *msgs_ofp; 34int verbose, done, time_bounded, output_all_data, seek_absolute; 35int easy_parse_avgs, ignore_remaps; 36double t_astart, t_aend; 37unsigned long n_traces; 38struct avgs_info all_avgs; 39unsigned int n_devs; 40time_t genesis, last_vtrace; 41LIST_HEAD(all_devs); 42LIST_HEAD(all_procs); 43LIST_HEAD(all_ios); 44LIST_HEAD(free_ios); 45LIST_HEAD(free_bilinks); 46__u64 q_histo[N_HIST_BKTS], d_histo[N_HIST_BKTS]; 47 48double plat_freq = 0.0; 49double range_delta = 0.1; 50__u64 last_q = (__u64)-1; 51 52struct region_info all_regions = { 53 .qranges = LIST_HEAD_INIT(all_regions.qranges), 54 .cranges = LIST_HEAD_INIT(all_regions.cranges), 55}; 56 57int process(void); 58 59int main(int argc, char *argv[]) 60{ 61 handle_args(argc, argv); 62 63 init_dev_heads(); 64 iostat_init(); 65 if (process() || output_avgs(avgs_ofp) || output_ranges(rngs_ofp)) 66 return 1; 67 68 if (iostat_ofp) { 69 fprintf(iostat_ofp, "\n"); 70 iostat_dump_stats(iostat_last_stamp, 1); 71 } 72 73 if (msgs_ofp != stdout) 74 fclose(msgs_ofp); 75 if (rngs_ofp != stdout) 76 fclose(rngs_ofp); 77 if (avgs_ofp != stdout) 78 fclose(avgs_ofp); 79 if (xavgs_ofp) 80 fclose(xavgs_ofp); 81 82 dip_cleanup(); 83 dev_map_exit(); 84 dip_exit(); 85 pip_exit(); 86 io_free_all(); 87 region_exit(&all_regions); 88 clean_allocs(); 89 90 return 0; 91} 92 93static inline double tv2dbl(struct timeval *tv) 94{ 95 return (double)tv->tv_sec + (((double)tv->tv_usec) / (1000.0 * 1000.0)); 96} 97 98int process(void) 99{ 100 int ret = 0; 101 struct io *iop = io_alloc(); 102 struct timeval tvs, tve; 103 104 genesis = last_vtrace = time(NULL); 105 gettimeofday(&tvs, NULL); 106 while (!done && next_trace(&iop->t, &iop->pdu)) { 107 add_trace(iop); 108 iop = io_alloc(); 109 } 110 111 io_release(iop); 112 gettimeofday(&tve, NULL); 113 114 if (verbose) { 115 double tps, dt_input = tv2dbl(&tve) - tv2dbl(&tvs); 116 117 tps = (double)n_traces / dt_input; 118 printf("\r " 119 " \r"); 120 printf("%10lu traces @ %.1lf Ktps in %.6lf seconds\n", 121 n_traces, tps/1000.0, 122 dt_input); 123 } 124 125 return ret; 126} 127