0

My program is in C++ and I have one server listening to a number of clients. Clients send small packets to server. I'm running my code on Ubuntu.

I want to measure the CPU utilization and possibly total number of CPU cycles on both sides, ideally with a breakdown on cycles/utilization spent on networking (all the way from NIC to the user space and vice versa), kernel space, user space, context switches, etc.

I did some search, but I couldn't figure out whether it should be done inside my C++ code or an external profiler should be used, or perhaps some other way.

4
  • Have a look at SystemTap. sourceware.org/systemtap
    – kaylum
    Commented Mar 26, 2015 at 3:19
  • Please edit your question to motivate it. Why do you ask? Why common profiling & benchmarking techniques are not enough? What exactly did you try? Commented Mar 26, 2015 at 17:03
  • @BasileStarynkevitch I think I motivated it enough in my question (the second paragraph). If by common profiling you mean information retrievable from /proc, then it does not give detailed cost breakdown for networking/....
    – narengi
    Commented Mar 26, 2015 at 18:30
  • No, I was referring to oprofile Commented Mar 26, 2015 at 18:34

3 Answers 3

1

Your best friend/helper in this case is the /proc file system in Linux. In /proc you will find CPU usage, memory usage, power usage etc. Have a look at this link

http://www.linuxhowtos.org/System/procstat.htm

Even you can check each process cpu usage by looking at the files /proc/process_id/stat.

3
  • Also, a process can query its own status using /proc/self/stat Commented Mar 26, 2015 at 5:50
  • @BasileStarynkevitch Thank you both for the tip. However, as far as I know, /proc is considered course-grained profiling and does not give detailed information about cpu cycles and also how it's distributed among networking/user space/etc, right?
    – narengi
    Commented Mar 26, 2015 at 17:00
  • You could perhaps use oprofile; but please explain exactly why do you ask, etc... Commented Mar 26, 2015 at 17:03
0

Take a look at the RDTSCP instruction and some other ways to measure performacnce metrics. System simulators like SniperSim, Gem5 etc. can also give total cycle count of your running program ( however, they may not be very accurate - there are some conditions that need to be met (core frequencies are same etc.))

0

As I commented, you probably should consider using oprofile. I am not very familiar with it (and it may be complex to use, and require system-wide configuration)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.