diff options
author | Jens Axboe <axboe@suse.de> | 2006-05-26 01:16:17 +0200 |
---|---|---|
committer | Jens Axboe <axboe@suse.de> | 2006-05-26 01:16:17 +0200 |
commit | 63eba14776dbafe34ebc4aade8f66456825d7514 (patch) | |
tree | 3c2ed991f1912773a7b94f466a0c586dbf1a7084 /btt/devmap.c | |
parent | e94cf8d72bbc19141b644fc56d010c3b88f6f7da (diff) | |
download | blktrace-63eba14776dbafe34ebc4aade8f66456825d7514.tar.gz blktrace-63eba14776dbafe34ebc4aade8f66456825d7514.tar.bz2 |
[PATCH] Add Alan's btt tool
Diffstat (limited to 'btt/devmap.c')
-rw-r--r-- | btt/devmap.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/btt/devmap.c b/btt/devmap.c new file mode 100644 index 0000000..5de57e8 --- /dev/null +++ b/btt/devmap.c @@ -0,0 +1,69 @@ +/* + * 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 "globals.h" +struct devmap *all_devmaps = NULL; +void dev_map_add(struct devmap *dmp) +{ + struct devmap *this = zmalloc(sizeof(*this)); + + *this = *dmp; + this->next = all_devmaps; + all_devmaps = this; +} + +struct devmap *dev_map_find(__u32 device) +{ + char this[128]; + struct devmap *dmp; + + sprintf(this, "%u,%u", MAJOR(device), MINOR(device)); + for (dmp = all_devmaps; dmp != NULL; dmp = dmp->next) + if (!strcmp(this, dmp->devno)) + break; + + return dmp; +} + +int dev_map_read(char *fname) +{ + char line[256]; + struct devmap dm; + FILE *fp = fopen(fname, "r"); + + if (!fp) { + perror(fname); + return 1; + } + + while (fscanf(fp, "%255[a-zA-Z0-9 :.,/]\n", line) == 1) { + if (strstr(line, "Device") != NULL) continue; + if (sscanf(line, "%s %s %u %u %u %u %s %s %u %u %s", + &dm.device[0], &dm.model[0], &dm.host, &dm.bus, + &dm.target, &dm.lun, &dm.node[0], &dm.pci[0], + &dm.irq, &dm.cpu, &dm.devno[0]) != 11) + break; + dev_map_add(&dm); + } + + return 0; +} |