2 * blktrace output analysis: generate a timeline & gather statistics
4 * (C) Copyright 2008 Hewlett-Packard Development Company, L.P.
5 * Alan D. Brunelle <alan.brunelle@hp.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 double first_ts, last_ts, tl;
30 void *plat_alloc(struct d_info *dip, char *post)
35 if (plat_freq <= 0.0) return NULL;
37 pp = malloc(sizeof(*pp));
39 pp->first_ts = pp->last_ts = pp->tl = -1.0;
41 oname = malloc(strlen(dip->dip_name) + strlen(post) + 32);
42 sprintf(oname, "%s%s_plat.dat", dip->dip_name, post);
43 if ((pp->fp = my_fopen(oname, "w")) == NULL) {
49 add_file(pp->fp, oname);
54 void plat_free(void *info)
56 struct plat_info *pp = info;
58 if (pp == NULL) return;
60 if (pp->first_ts != -1.0) {
61 double delta = pp->last_ts - pp->first_ts;
63 fprintf(pp->fp, "%lf %lf\n",
64 pp->first_ts + (delta / 2), pp->tl / pp->nl);
69 void plat_x2c(void *info, __u64 ts, __u64 latency)
71 double now = TO_SEC(ts);
72 double lat = TO_SEC(latency);
73 struct plat_info *pp = info;
75 if (pp == NULL) return;
77 if (pp->first_ts == -1.0) {
78 pp->first_ts = pp->last_ts = now;
81 } else if ((now - pp->first_ts) >= plat_freq) {
82 double delta = pp->last_ts - pp->first_ts;
84 fprintf(pp->fp, "%lf %lf\n",
85 pp->first_ts + (delta / 2), pp->tl / pp->nl);
87 pp->first_ts = pp->last_ts = now;