summaryrefslogtreecommitdiff
path: root/btt/seek.c
diff options
context:
space:
mode:
authorAlan D. Brunelle <Alan.Brunelle@hp.com>2007-04-14 08:05:06 +0200
committerJens Axboe <jens.axboe@oracle.com>2007-04-14 08:05:06 +0200
commit6904079488cd3063d171021c8954f955f4236849 (patch)
tree161035c6d78fba22a6acc21cb59d5d019022d5ae /btt/seek.c
parentc8b0b334cc1028ad8aa5407667233747af96a942 (diff)
downloadblktrace-6904079488cd3063d171021c8954f955f4236849.tar.gz
blktrace-6904079488cd3063d171021c8954f955f4236849.tar.bz2
Combine all outstanding patches into one /big patch/
o Added seek absolute option -- allows one to specify whether they want seek distances to be calculated based upon nearness to previous IO or from start to start. o Added block number dumping o Updated btt documentation for above. o Significant clean up of memory used and files opened. All allocated memory and opened files are cleaned up prior to normal program exit. o Fixed problem where Q & M traces were not being freed properly. o Fixed problem where bilink structures were not being freed properly. o Fixed omission -- output combined seeks in addition to read and write seeks. Signed-off-by: Alan D. Brunelle <Alan.Brunelle@hp.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'btt/seek.c')
-rw-r--r--btt/seek.c50
1 files changed, 41 insertions, 9 deletions
diff --git a/btt/seek.c b/btt/seek.c
index f5f3851..8738698 100644
--- a/btt/seek.c
+++ b/btt/seek.c
@@ -29,7 +29,7 @@ struct seek_bkt {
};
struct seeki {
- FILE *rfp, *wfp;
+ FILE *rfp, *wfp, *cfp;
struct rb_root root;
long long tot_seeks;
double total_sectors;
@@ -84,6 +84,17 @@ static void __insert(struct rb_root *root, long long sectors)
rb_insert_color(&sbp->rb_node, root);
}
+static void __destroy(struct rb_node *n)
+{
+ if (n) {
+ struct seek_bkt *sbp = rb_entry(n, struct seek_bkt, rb_node);
+
+ __destroy(n->rb_left);
+ __destroy(n->rb_right);
+ free(sbp);
+ }
+}
+
void seek_clean(void)
{
clean_files(&seek_files);
@@ -94,14 +105,19 @@ long long seek_dist(struct seeki *sip, struct io *iop)
long long dist;
long long start = BIT_START(iop), end = BIT_END(iop);
- /* Some overlap means no seek */
- if (((sip->last_start <= start) && (start <= sip->last_end)) ||
- ((sip->last_start <= end) && (end <= sip->last_end)))
- dist = 0;
- else if (start > sip->last_end)
+ if (seek_absolute)
dist = start - sip->last_end;
- else
- dist = start - sip->last_start;
+ else {
+ /* Some overlap means no seek */
+ if (((sip->last_start <= start) && (start <= sip->last_end)) ||
+ ((sip->last_start <= end) && (end <= sip->last_end)))
+ dist = 0;
+ else if (start > sip->last_end)
+ dist = start - sip->last_end;
+ else
+ dist = start - sip->last_start;
+
+ }
sip->last_start = start;
sip->last_end = end;
@@ -114,6 +130,7 @@ void *seeki_init(__u32 device)
sip->rfp = seek_open(device, 'r');
sip->wfp = seek_open(device, 'w');
+ sip->cfp = seek_open(device, 'c');
sip->tot_seeks = 0;
sip->total_sectors = 0.0;
sip->last_start = sip->last_end = 0;
@@ -122,14 +139,29 @@ void *seeki_init(__u32 device)
return sip;
}
+void seeki_exit(void *param)
+{
+ struct seeki *sip = param;
+
+ /*
+ * Associated files are cleaned up by seek_clean
+ */
+ __destroy(sip->root.rb_node);
+ free(sip);
+}
+
void seeki_add(void *handle, struct io *iop)
{
struct seeki *sip = handle;
+ char rw = IOP_READ(iop) ? 'r' : 'w';
long long dist = seek_dist(sip, iop);
+ double tstamp = BIT_TIME(iop->t.time);
FILE *fp = IOP_READ(iop) ? sip->rfp : sip->wfp;
if (fp)
- fprintf(fp, "%15.9lf %13lld\n", BIT_TIME(iop->t.time), dist);
+ fprintf(fp, "%15.9lf %13lld %c\n", tstamp, dist, rw);
+ if (sip->cfp)
+ fprintf(sip->cfp, "%15.9lf %13lld %c\n", tstamp, dist, rw);
dist = llabs(dist);
sip->tot_seeks++;