VCD/Gnuplot: Cosmetics, code simplifications.

This commit is contained in:
Uwe Hermann 2010-05-09 14:42:46 +02:00
parent a821069b34
commit 607b58de58
2 changed files with 15 additions and 17 deletions

View File

@ -140,7 +140,7 @@ static int data(struct output *o, char *data_in, uint64_t length_in,
char **data_out, uint64_t *length_out) char **data_out, uint64_t *length_out)
{ {
struct context *ctx; struct context *ctx;
unsigned int offset, outsize, p, curbit; unsigned int i, outsize, p, curbit;
uint64_t sample, count = 0; uint64_t sample, count = 0;
char *outbuf, *c; char *outbuf, *c;
@ -163,9 +163,8 @@ static int data(struct output *o, char *data_in, uint64_t length_in,
/* TODO: Are disabled probes handled correctly? */ /* TODO: Are disabled probes handled correctly? */
for (offset = 0; offset <= length_in - ctx->unitsize; for (i = 0; i <= length_in - ctx->unitsize; i += ctx->unitsize) {
offset += ctx->unitsize) { memcpy(&sample, data_in + i, ctx->unitsize);
memcpy(&sample, data_in + offset, ctx->unitsize);
/* The first column is a counter (needed for gnuplot). */ /* The first column is a counter (needed for gnuplot). */
c = outbuf + strlen(outbuf); c = outbuf + strlen(outbuf);

View File

@ -153,7 +153,7 @@ static int data(struct output *o, char *data_in, uint64_t length_in,
char **data_out, uint64_t *length_out) char **data_out, uint64_t *length_out)
{ {
struct context *ctx; struct context *ctx;
unsigned int offset, outsize; unsigned int i, outsize;
int p, curbit, prevbit; int p, curbit, prevbit;
uint64_t sample, prevsample; uint64_t sample, prevsample;
char *outbuf, *c; char *outbuf, *c;
@ -177,28 +177,27 @@ static int data(struct output *o, char *data_in, uint64_t length_in,
/* TODO: Are disabled probes handled correctly? */ /* TODO: Are disabled probes handled correctly? */
for (offset = 0; offset <= length_in - ctx->unitsize; for (i = 0; i <= length_in - ctx->unitsize; i += ctx->unitsize) {
offset += ctx->unitsize) { memcpy(&sample, data_in + i, ctx->unitsize);
memcpy(&sample, data_in + offset, ctx->unitsize);
for (p = 0; p < ctx->num_enabled_probes; p++) { for (p = 0; p < ctx->num_enabled_probes; p++) {
curbit = (sample & ((uint64_t) (1 << p))) != 0; curbit = (sample & ((uint64_t) (1 << p))) != 0;
if (offset == 0) { if (i == 0) {
prevbit = ~curbit; prevbit = ~curbit;
} else { } else {
memcpy(&prevsample, data_in + offset - 1, memcpy(&prevsample, data_in + i - 1,
ctx->unitsize); ctx->unitsize);
prevbit = prevbit =
(prevsample & ((uint64_t) (1 << p))) != 0; (prevsample & ((uint64_t) (1 << p))) != 0;
} }
if (prevbit != curbit) { /* VCD only contains deltas/changes. */
/* FIXME: Only once per sample? */ if (prevbit == curbit)
c = outbuf + strlen(outbuf); continue;
sprintf(c, "#%i\n", offset * 1 /* TODO */);
/* FIXME: Only once per sample? */
/* TODO: Is 'i' correct here? */
c = outbuf + strlen(outbuf); c = outbuf + strlen(outbuf);
sprintf(c, "%i%c\n", curbit, (char)('!' + p)); sprintf(c, "#%i\n%i%c\n", i, curbit, (char)('!' + p));
}
} }
/* TODO: Use realloc() if strlen(outbuf) is almost "full"... */ /* TODO: Use realloc() if strlen(outbuf) is almost "full"... */