summaryrefslogtreecommitdiff
path: root/btt/aqd.c
blob: 036a0d33786e5e71b9bbff2e3a6d975d46b27ac9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * blktrace output analysis: generate a timeline & gather statistics
 *
 * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "globals.h"

static struct file_info *aqd_files = NULL;

struct aqd_info {
	FILE *fp;
	int na;		/* # active */
};

void *aqd_init(char *str)
{
	char *oname;
	struct aqd_info *ap;

	if (aqd_name == NULL) return NULL;

	ap = malloc(sizeof(*ap));
	ap->na = 0;

	oname = malloc(strlen(aqd_name) + strlen(str) + 32);
	sprintf(oname, "%s_%s.dat", aqd_name, str);
	if ((ap->fp = fopen(oname, "w")) == NULL) {
		perror(oname);
		return NULL;
	}
	add_file(&aqd_files, ap->fp, oname);

	return ap;

}

void aqd_issue(void *info, double ts)
{
	struct aqd_info *ap = info;

	fprintf(ap->fp, "%lf %d\n%lf %d\n", ts, ap->na, ts, ap->na + 1);

	ap->na += 1;
}

void aqd_complete(void *info, double ts)
{
	struct aqd_info *ap = info;

	if (ap->na > 0) {
		fprintf(ap->fp, "%lf %d\n%lf %d\n", ts, ap->na, ts, ap->na - 1);
		ap->na -= 1;
	}
}