0

Suppose I'm reading large chunks of data into memory and processing them sequentially. Is there a way to pinpoint when a given segment/chunk of the memory was accessed, by using some kind of system tool that will log memory address accesses?

An approach I'm considering - which doesn't rely on measurement utilities - is logging what data is being processed at any point of time, and inferring the usage based on looking at the data itself. But that is not a generic solution.

pramodbiligiri
  • 355
  • 1
  • 10

1 Answers1

1

These are some of the ideas that have been brewing in my head to do what you want. Never had the time to explore these in more detail though.

Simplest method is to add a watchpoint for the address inside gdb, if you need a quick fix kind of solution.

Another way to do this is to mark the pages READONLY for chunks of data you want to check access for. On Linux this can be done using mprotect call. This assumes you are debugging this code, as the access to the page will cause a segfault. You could possibly install a signal handler.

Another way to do the same maybe to us ptrace system call, which maybe more trouble than it's worth.

If you just want to count accesses to a memory address you can use perf_event_open system call on newer linux kernels. See documentation for PERF_COUNT_HW_CACHE_OP_READ and PERF_COUNT_HW_CACHE_OP_WRITE. You are on your own with that one though. It maybe even less worthwhile to use this method. However, since the question is marked with the performance tag, this maybe what you are looking for.

If you just want a system tool, you might want to look at perf tool and dig into the manuals to see if it can do the same thing that I described with perf_event_open. This tool is a wrapper around that system call, so I am guessing that it should have support for the functionality I mentioned in the previous point.

Community
  • 1
  • 1
Sudhanshu
  • 2,691
  • 1
  • 18
  • 25
  • That looks like an interesting set of approaches. I'll check it out. By the way, I should have mentioned that the program I'm running is on the JVM. – pramodbiligiri Apr 08 '15 at 23:10