From c52d7ab471d62b32836617fce06c0946d08ecb09 Mon Sep 17 00:00:00 2001 From: "Bjoern B. Brandenburg" Date: Wed, 24 Sep 2008 23:26:44 -0400 Subject: display information about struct timestamp --- src/ftdump.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ftdump.c b/src/ftdump.c index 849d6ee..2871537 100644 --- a/src/ftdump.c +++ b/src/ftdump.c @@ -12,7 +12,7 @@ static void dump(struct timestamp* ts, size_t count) struct timestamp *x; while (count--) { x = ts++; - printf("event:%d seq:%u cpu:%d type:%d\n", + printf("event:%d seq:%u cpu:%d type:%d\n", (int) x->event, x->seq_no, x->cpu, x->task_type); } } @@ -21,15 +21,31 @@ static void die(char* msg) { if (errno) perror("error: "); - fprintf(stderr, "%s\n", msg); + fprintf(stderr, "%s\n", msg); exit(1); } -int main(int argc, char** argv) +#define offset(type, member) ((unsigned int) &((type *) 0)->member) + +int main(int argc, char** argv) { void* mapped; size_t size, count; - struct timestamp* ts; + struct timestamp* ts; + + printf("struct timestamp:\n" + "\t size = %3lu\n" + "\t offset(timestamp) = %3u\n" + "\t offset(seq_no) = %3u\n" + "\t offset(cpu) = %3u\n" + "\t offset(event) = %3u\n" + "\t offset(task_type) = %3u\n", + sizeof(struct timestamp), + offset(struct timestamp, timestamp), + offset(struct timestamp, seq_no), + offset(struct timestamp, cpu), + offset(struct timestamp, event), + offset(struct timestamp, task_type)); if (argc != 2) die("Usage: ftdump "); @@ -37,7 +53,7 @@ int main(int argc, char** argv) die("could not map file"); ts = (struct timestamp*) mapped; - count = size / sizeof(struct timestamp); + count = size / sizeof(struct timestamp); dump(ts, count); return 0; -- cgit v1.2.2