Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Using linux performance counters from within application

    I'm interested in using the new performance counter functionality from kernel 2.6.32. I've built the perf tool, and it seems like exactly what I want, but I'm wondering if there is a good way of embedding this functionality in an application.

    Specifically, my goal is to profile only a portion of code, and trigger the beginning and end of the measurement from calls within the code. It seems that the perf tool is really just a wrapper for calling the sys_perf_event_open system call, so I assume that I probably want to call this directly from my code, but I haven't been able to find any decent documentation on that particular system call.

    Does anyone know where I can find some documentation? Or is there perhaps a better way to go about this? The particular event counters I want (to start with at least) are the instruction count, cache miss counts, tlb misses, branch mispredictions, and malloc calls.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    There is a gcc flag which will cause the compiler to emit pre-processed code when it compiles, which should have the profiler calls embedded. You should be able to use that to figure out how to manually embed them in your code. The flag is -E. From the gcc man page:
           -E  Stop after the preprocessing stage; do not run the compiler proper.  The
               output is in the form of preprocessed source code, which is sent to the
               standard output.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts