Commit | Line | Data |
---|---|---|
2baef508 AB |
1 | /* |
2 | * blktrace output analysis: generate a timeline & gather statistics | |
3 | * | |
4 | * (C) Copyright 2008 Hewlett-Packard Development Company, L.P. | |
5 | * Alan D. Brunelle <alan.brunelle@hp.com> | |
6 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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 | |
20 | * | |
21 | */ | |
22 | #include "globals.h" | |
23 | ||
24 | struct plat_info { | |
25 | long nl; | |
26 | FILE *fp; | |
27 | double first_ts, last_ts, tl; | |
28 | }; | |
29 | ||
a155ab98 | 30 | void *plat_alloc(struct d_info *dip, char *post) |
2baef508 AB |
31 | { |
32 | char *oname; | |
33 | struct plat_info *pp; | |
34 | ||
35 | if (plat_freq <= 0.0) return NULL; | |
36 | ||
37 | pp = malloc(sizeof(*pp)); | |
38 | pp->nl = 0; | |
39 | pp->first_ts = pp->last_ts = pp->tl = -1.0; | |
40 | ||
a155ab98 AB |
41 | oname = malloc(strlen(dip->dip_name) + strlen(post) + 32); |
42 | sprintf(oname, "%s%s_plat.dat", dip->dip_name, post); | |
99bb5ebc | 43 | if ((pp->fp = my_fopen(oname, "w")) == NULL) { |
2baef508 | 44 | perror(oname); |
84b321fa ES |
45 | free(oname); |
46 | free(pp); | |
2baef508 AB |
47 | return NULL; |
48 | } | |
c053af42 | 49 | add_file(pp->fp, oname); |
2baef508 AB |
50 | |
51 | return pp; | |
52 | } | |
53 | ||
c053af42 | 54 | void plat_free(void *info) |
2baef508 AB |
55 | { |
56 | struct plat_info *pp = info; | |
57 | ||
58 | if (pp == NULL) return; | |
59 | ||
60 | if (pp->first_ts != -1.0) { | |
61 | double delta = pp->last_ts - pp->first_ts; | |
62 | ||
63 | fprintf(pp->fp, "%lf %lf\n", | |
64 | pp->first_ts + (delta / 2), pp->tl / pp->nl); | |
65 | } | |
66 | free(info); | |
67 | } | |
68 | ||
2baef508 AB |
69 | void plat_x2c(void *info, __u64 ts, __u64 latency) |
70 | { | |
71 | double now = TO_SEC(ts); | |
72 | double lat = TO_SEC(latency); | |
73 | struct plat_info *pp = info; | |
74 | ||
75 | if (pp == NULL) return; | |
76 | ||
77 | if (pp->first_ts == -1.0) { | |
78 | pp->first_ts = pp->last_ts = now; | |
79 | pp->nl = 1; | |
80 | pp->tl = lat; | |
c053af42 | 81 | } else if ((now - pp->first_ts) >= plat_freq) { |
2baef508 AB |
82 | double delta = pp->last_ts - pp->first_ts; |
83 | ||
84 | fprintf(pp->fp, "%lf %lf\n", | |
85 | pp->first_ts + (delta / 2), pp->tl / pp->nl); | |
86 | ||
87 | pp->first_ts = pp->last_ts = now; | |
88 | pp->nl = 1; | |
89 | pp->tl = lat; | |
c053af42 | 90 | } else { |
2baef508 AB |
91 | pp->last_ts = now; |
92 | pp->nl += 1; | |
93 | pp->tl += lat; | |
94 | } | |
95 | } |