Thursday, December 13, 2018

CPU profiler


1. CPU profilter
1. 1 gprof, Valgrind and gperftools - an evaluation of some tools for application level CPU profiling on Linux

1.2 List of performance analysis tools

2. Valgrind
 - memory leak profiling: $ valgrind ./sample
 - cache profileing: $ valgrind --tool==cachegrind ./sample
 - function profiling: $ valgrind --tool==callgrind ./sample
 - kcachegrind (GUI tool)

3. gprof
 - WIKI
 - tutorial: https://www.thegeekstuff.com/2012/08/gprof-tutorial/
 - What is gprof?
 - How to install and use profiling tool Gprof on Linux
 - GPROF Tutorial
    To write the gmon.out file properly, your program must exit normally. _exit()
    Call graph: gprof2dot
 - gprof Quick-Start Guide


  • use the makefile (edit CFLAGS / FFLAGS first) or call compiler at the shell
  • required flags for profiling: -pg -g
  • try with and without inlining: -finline / -fno-inline


4. gprof2dot

Saturday, September 1, 2018

The history of "foo" & "bar"


http://programmers.stackexchange.com/questions/69788/using-foo-and-bar-in-examples

Start Python for C, C++ programmmer


Python Tutorial
http://docs.python.org/2/tutorial/index.html

Matplot Lib.
http://coreapython.hosting.paran.com/manual/Matplotlib%20-%20pylab%20-%20matlab%20style%20python%20plotting%20(plots,%20graphs,%20charts).htm (Korean Version)


Python: Tips 1

sprintf in Python
------------------------------

How to do a sprintf in Python
http://www.johnkerl.org/python/sprintf.html

[Tutor] sprintf-like functionality in Python
http://mail.python.org/pipermail/tutor/2003-August/024921.html

Python/파이썬] C언어의 sprintf 함수 구현 예제
http://mwultong.blogspot.com/2007/01/python-c-sprintf.html


gmtime conversion in Python
------------------------------

Python time gmtime() Method

http://www.tutorialspoint.com/python/time_gmtime.htm


import time
time.gmtime(xxxxxxxxx.xxx)


Python isNumber
------------------------------



http://mwultong.blogspot.com/2007/01/python-isnumber-isnum-isnumeric.html

def isNumber(s):
  try:
    float(s)
    return True
  except ValueError:
    return False

Case Ranges

in the Linux kernel, you can find below code

switch (val) { case 1 ... 10:         /* ... */         break; case 11 ... 20:         /* ... */         break; default:         /* ... */ }
It is a GCC extension.




CPU load & CPU stat

     user    nice   system  idle      iowait irq   softirq  steal  guest  guest_nice
cpu  74608   2520   24433   1117073   6176   4054  0        0      0      0

Algorithmically, we can calculate the CPU usage percentage like:
PrevIdle = previdle + previowait
Idle = idle + iowait

PrevNonIdle = prevuser + prevnice + prevsystem + previrq + prevsoftirq + prevsteal
NonIdle = user + nice + system + irq + softirq + steal

PrevTotal = PrevIdle + PrevNonIdle
Total = Idle + NonIdle

# differentiate: actual value minus the previous one
totald = Total - PrevTotal
idled = Idle - PrevIdle

CPU_Percentage = (totald - idled)/totald


cpu  114466 58760 208131 183612 1490 18 5178 0 0 0
cpu0 20966 6912 72976 161278 1200 3 3263 0 0 0
cpu1 18880 6959 39092 4213 20 5 112 0 0 0
cpu2 18665 6782 29917 4321 21 2 50 0 0 0
cpu3 18134 6434 27657 4442 21 2 62 0 0 0
cpu4 10008 8231 10491 2308 63 0 1003 0 0 0
cpu5 9338 8080 9868 2382 64 0 240 0 0 0
cpu6 9210 7570 9186 2392 40 2 226 0 0 0
cpu7 9265 7792 8944 2276 61 4 222 0 0 0



http://stackoverflow.com/questions/23367857/accurate-calculation-of-cpu-usage-given-in-percentage-in-linux