2016年12月12日 星期一

[linux] 量測特定 process CPU ussage





Preparation

To calculate CPU usage for a specific process you'll need the following:
  1. /proc/uptime
    • #1 uptime of the system (seconds)
  2. /proc/[PID]/stat
    • #14 utime - CPU time spent in user code, measured in clock ticks
    • #15 stime - CPU time spent in kernel code, measured in clock ticks
    • #16 cutime - Waited-for children's CPU time spent in user code (in clock ticks)
    • #17 cstime - Waited-for children's CPU time spent in kernel code (in clock ticks)
    • #22 starttime - Time when the process started, measured in clock ticks
  3. Hertz (number of clock ticks per second) of your system.




Calculation

First we determine the total time spent for the process:
total_time = utime + stime
We also have to decide whether we want to include the time from children processes. If we do, then we add those values to total_time:
total_time = total_time + cutime + cstime
Next we get the total elapsed time in seconds since the process started:
seconds = uptime - (starttime / Hertz)
Finally we calculate the CPU usage percentage:
cpu_usage = 100 * ((total_time / Hertz) / seconds)





此例來說 bash 的 CPU usage 為
1.160880760010654


2016年12月11日 星期日

[Android] 改設定以免 Android Studio 吃 C槽 系統硬碟空間


1.
C:\Program Files\Android Studio\bin\idea.propertis

idea.config.path
idea.system.path

2.
環境變數
Variable name: ANDROID_SDK_HOME
Variable value: D:\Android



3.


gradle-setting.jpg


參考這篇但改變順序
以免重工
http://www.littlecpu.com/android-studio-c-drive




2016年12月6日 星期二

[C]如何在 linux 和 Mac build C share library

以此例來說,quanto2 是我們要build 的目的檔案



gcc -fPIC -g -c quanto2.c -o libquanto2.o

Linux:
gcc -g -shared -Wl,-soname,libquanto2.so -o libquanto2.so libquanto2.o -lc
MacOS:
gcc -g -shared -Wl,-install_name,libquanto2.so -o libquanto2.so libquanto2.o -lc


gcc -g test.c -o test -L. -lquanto2

[Go] 如何和 C 語言做介接

以這個為例 ,quanto2 是我的自定義 C library
這樣就可以call 到 C 的 function



// #cgo LDFLAGS: -L ./ -lquanto2
// #include <stdio.h>
// #include <stdlib.h>
// #include "quanto2.h"
import "C"
import "fmt"

func main() {
    fmt.Println("ho ho")
    C.testGo()
}