Home | History | Annotate | Download | only in btt
      1 /*
      2  * blktrace output analysis: generate a timeline & gather statistics
      3  *
      4  * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle (at) 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(struct d_info *dip, char *name, char *post)
     30 {
     31 	FILE *fp = NULL;
     32 
     33 	if (name) {
     34 		size_t tlen = strlen(name) + strlen(dip->dip_name)
     35 					   + strlen(post) + 32;
     36 		char oname[tlen];
     37 
     38 		sprintf(oname, "%s_%s_%s.dat", name, dip->dip_name, post);
     39 		if ((fp = my_fopen(oname, "w")) == NULL)
     40 			perror(oname);
     41 		else
     42 			add_file(fp, strdup(oname));
     43 	}
     44 
     45 	return fp;
     46 }
     47 
     48 void latency_alloc(struct d_info *dip)
     49 {
     50 	dip->q2d_ofp = latency_open(dip, q2d_name, "q2d");
     51 	dip->d2c_ofp = latency_open(dip, d2c_name, "d2c");
     52 	dip->q2c_ofp = latency_open(dip, q2c_name, "q2c");
     53 }
     54 
     55 void latency_q2d(struct d_info *dip, __u64 tstamp, __u64 latency)
     56 {
     57 	plat_x2c(dip->q2d_plat_handle, tstamp, latency);
     58 	latency_out(dip->q2d_ofp, tstamp, latency);
     59 }
     60 
     61 void latency_d2c(struct d_info *dip, __u64 tstamp, __u64 latency)
     62 {
     63 	plat_x2c(dip->d2c_plat_handle, tstamp, latency);
     64 	latency_out(dip->d2c_ofp, tstamp, latency);
     65 }
     66 
     67 void latency_q2c(struct d_info *dip, __u64 tstamp, __u64 latency)
     68 {
     69 	plat_x2c(dip->q2c_plat_handle, tstamp, latency);
     70 	latency_out(dip->q2c_ofp, tstamp, latency);
     71 }
     72