Is it possible to obtain the program counter (PC) register values of a running Java application, particularly one running in an Android emulator? gprof, for example, randoml
Many Java profilers like VisualVM can do sampling-based profiling, which probably works like you describe.
As for code memory usage, this is what the "permanent generation" (PermGen) of the garbage collector mainly contains; VisualVM can display that as well.