Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8444783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:29:13+00:00 2026-06-10T09:29:13+00:00

Is there a way to read performance counters periodically in linux? Something like perf

  • 0

Is there a way to read performance counters periodically in linux?

Something like perf stat with the ability to sample every X cycles is what I’m looking for.

Basically I would like to be able to read the instruction counter (number of instructions executed) every X amount of cpu cycles for some program.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:29:14+00:00Added an answer on June 10, 2026 at 9:29 am

    It seems that the perf tool in Linux works by recording an event when the counters reach a specific value, rather than sampling at regular intervals.

    Command perf record -e cycles,instructions -c 10000 stores an event every 10000 cycles and every 10000 instructions. It can be run against a new command or an existing pid. It records to perf.data in current directory.

    Analyzing the data is another matter. Using perf script gets you quite close:

    ls 16040 2152149.005813: cycles:          c113a068  ([kernel.kallsyms])
    ls 16040 2152149.005820: cycles:          c1576af0  ([kernel.kallsyms])
    ls 16040 2152149.005827: cycles:          c10ed6aa  ([kernel.kallsyms])
    ls 16040 2152149.005831: instructions:          c1104b30  ([kernel.kallsyms])
    ls 16040 2152149.005835: cycles:          c11777c1  ([kernel.kallsyms])
    ls 16040 2152149.005842: cycles:          c10702a8  ([kernel.kallsyms])
    ...
    

    You need to write a script that takes a bunch of lines from that output and counts the number of ‘cycles’ and ‘instructions’ events in that set. You can adjust the resolution by changing the parameter -c 10000 in the recording command.

    I verified the analysis by running perf stat and perf record against ls /. Stat reported 2 634 205 cycles, 1 725 255 instructions, while script output had 410 cycles events and 189 instructions events. The smaller the -c value, the more overhead there seems to be in the cycles reading.

    There is also a -F option to perf record, which samples at regular intervals. However, I could not find a way to retrieve the counter values when using this option.

    Edit: perf stat apparently works on pids also, and captures data until ctrl-c is pressed. It should be quite easy to modify the source so that it always captures for N seconds and then run it in a loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to read a TIFF file using AIR ? Looks like
I am recording a performance counters frm linux using the command perf record. I
Is there any way to read whole lines from a socket in Erlang, or
Is there a way to read a ByteBuffer with a BufferedReader without having to
Is there a way to read off from an [external] xml (an xml file
Is there any way to read a file using sharpsvn................
Is there any way to read the asp.net Import directives at runtime? I have
Is there any way to read a file line by line in javascript, specifically
In C#/.NET (on Windows) is there a way to read a growing file using
In the Mercurial API, is there any way to read the configuration values associated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.