San Mehat | e20e134 | 2009-06-03 15:36:35 -0700 | [diff] [blame] | 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 "globals.h" |
| 22 | |
| 23 | static inline void latency_out(FILE *ofp, __u64 tstamp, __u64 latency) |
| 24 | { |
| 25 | if (ofp) |
| 26 | fprintf(ofp, "%lf %lf\n", TO_SEC(tstamp), TO_SEC(latency)); |
| 27 | } |
| 28 | |
| 29 | FILE *latency_open(__u32 device, char *name, char *post) |
| 30 | { |
| 31 | FILE *fp = NULL; |
| 32 | |
| 33 | if (name) { |
| 34 | int mjr, mnr; |
| 35 | char oname[strlen(name) + 32]; |
| 36 | |
| 37 | mjr = device >> MINORBITS; |
| 38 | mnr = device & ((1 << MINORBITS) - 1); |
| 39 | |
| 40 | sprintf(oname, "%s_%03d,%03d_%s.dat", name, mjr, mnr, post); |
| 41 | if ((fp = my_fopen(oname, "w")) == NULL) |
| 42 | perror(oname); |
| 43 | else |
| 44 | add_file(fp, strdup(oname)); |
| 45 | } |
| 46 | |
| 47 | return fp; |
| 48 | } |
| 49 | |
| 50 | void latency_alloc(struct d_info *dip) |
| 51 | { |
| 52 | dip->q2d_ofp = latency_open(dip->device, q2d_name, "q2d"); |
| 53 | dip->d2c_ofp = latency_open(dip->device, d2c_name, "d2c"); |
| 54 | dip->q2c_ofp = latency_open(dip->device, q2c_name, "q2c"); |
| 55 | } |
| 56 | |
| 57 | void latency_q2d(struct d_info *dip, __u64 tstamp, __u64 latency) |
| 58 | { |
| 59 | plat_x2c(dip->q2d_plat_handle, tstamp, latency); |
| 60 | latency_out(dip->q2d_ofp, tstamp, latency); |
| 61 | } |
| 62 | |
| 63 | void latency_d2c(struct d_info *dip, __u64 tstamp, __u64 latency) |
| 64 | { |
| 65 | plat_x2c(dip->d2c_plat_handle, tstamp, latency); |
| 66 | latency_out(dip->d2c_ofp, tstamp, latency); |
| 67 | } |
| 68 | |
| 69 | void latency_q2c(struct d_info *dip, __u64 tstamp, __u64 latency) |
| 70 | { |
| 71 | plat_x2c(dip->q2c_plat_handle, tstamp, latency); |
| 72 | latency_out(dip->q2c_ofp, tstamp, latency); |
| 73 | } |