memzap

replay memory writes
git clone git://git.2f30.org/memzap.git
Log | Files | Refs | README | LICENSE

commit e13f55bfbdf51e7981d053ebbbcec3f738b6110f
parent b364eca05f579f09d7d8364acad2dd3fd340169d
Author: sin <sin@2f30.org>
Date:   Mon Mar  4 16:31:56 +0000

mdiff: Add `cycle' field

We keep track of the cycle count so we can visualize things
properly.  We might have more than a single diff for each cycle
so we should apply all of them before we move on to the next
cycle.

Diffstat:
mdiff.c | 4+++-
mdiffdump.c | 2++
memzap.c | 5++++-
proto.h | 5++++-
4 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/mdiff.c b/mdiff.c @@ -138,7 +138,8 @@ mdiff_read_diff(int fd, struct mdiff_hdr *hdr, uint32_t region) } int -mdiff_append_rdiff(int fd, struct mem_region_diff *rdiff) +mdiff_append_rdiff(int fd, struct mem_region_diff *rdiff, + uint64_t cycle) { struct mem_diff *md; struct mdiff_region mdiff; @@ -156,6 +157,7 @@ mdiff_append_rdiff(int fd, struct mem_region_diff *rdiff) md = &rdiff->mrdiffs[i]; mdiff.offset = md->offset; mdiff.len = md->len; + mdiff.cycle = cycle; /* TODO: Handle endianness issues here */ ret = write(fd, &mdiff, sizeof(mdiff)); if (ret != sizeof(mdiff)) diff --git a/mdiffdump.c b/mdiffdump.c @@ -32,6 +32,8 @@ main(int argc, char *argv[]) printf("\nDiff sections:\n"); for (i = 0; i < hdr->nregions; i++) { mdiff = mdiff_read_diff(fd, hdr, i); + printf(" [%lu]: cycle: %llu\n", (unsigned long)i, + (unsigned long long)mdiff->cycle); printf(" [%lu]: offset: %lu\n", (unsigned long)i, (unsigned long)mdiff->offset); printf(" [%lu]: len: %lu\n", (unsigned long)i, diff --git a/memzap.c b/memzap.c @@ -54,6 +54,7 @@ main(int argc, char *argv[]) char *prog = *argv; char mdiff_path[PATH_MAX - 1]; bool once = false; + uint64_t cycle = 0; while ((c = getopt(argc, argv, "hs:l:r:vV")) != -1) { switch (c) { @@ -124,6 +125,7 @@ main(int argc, char *argv[]) wait(&stat); if (!WIFSTOPPED(stat)) goto out_mmap; + cycle++; /* Create .mdiff file and initialize the header */ snprintf(mdiff_path, sizeof(mdiff_path), @@ -165,6 +167,7 @@ main(int argc, char *argv[]) free_mem_tree(mt_old); break; } + cycle++; /* Read in the (N + 1)th generation of the traced * region */ @@ -181,7 +184,7 @@ main(int argc, char *argv[]) /* If we've found differences, then apply them on * the Nth generation */ apply_diff(mr_old, rdiff); - hdr.nregions += mdiff_append_rdiff(fd, rdiff); + hdr.nregions += mdiff_append_rdiff(fd, rdiff, cycle); } /* Free these and go up for another run */ diff --git a/proto.h b/proto.h @@ -119,6 +119,8 @@ struct mdiff_hdr { }; struct mdiff_region { + /* Cycle count */ + uint64_t cycle; /* Offset into memory where this region should * be written to */ uint32_t offset; @@ -175,7 +177,8 @@ int mdiff_insert_hdr(int fd, struct mdiff_hdr *hdr); int mdiff_start_diff(int fd); struct mdiff_region *mdiff_read_diff(int fd, struct mdiff_hdr *hdr, uint32_t region); -int mdiff_append_rdiff(int fd, struct mem_region_diff *rdiff); +int mdiff_append_rdiff(int fd, struct mem_region_diff *rdiff, + uint64_t cycle); void free_mdiff_region(struct mdiff_region *mdiff); #endif