2011
09.07

我可能很早之前就聽過 gcov[1] 這個工具,但是我沒有去了解或學習它能做些什麼。
今天從朋友的噗那裡又再看到這個工具,而且有了簡單的認識,發覺這真是個好東西,應該要來試試看,就拿現在正在寫的 Choqok Plurk plugin 來試試看吧。

要使用 gcov 其實很簡單,只要在編譯跟連結的時候加上
-fprofile-arcs -ftest-coverage
這兩個 flag 即可。
不過我們的 project 是使用 CMake 所以改法稍微有點不同,下面就是修改的 diff
ubuntu@ubuntu-Vostro-V131 ~/kde/src/choqok (git-svn)-[plurk] % git diff
diff --git a/microblogs/plurk/CMakeLists.txt b/microblogs/plurk/CMakeLists.txt
index 2950374..0fb6cfa 100644
--- a/microblogs/plurk/CMakeLists.txt
+++ b/microblogs/plurk/CMakeLists.txt
@@ -32,7 +32,8 @@ plurklistdialog_base.ui
kde4_add_plugin(choqok_plurk ${choqok_plurk_SRCS})
-target_link_libraries(choqok_plurk ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${QJSON_LIBRARY} ${QTOAUTH_LIBRARY} choqok plurkapihelper)
+add_definitions(-fprofile-arcs -ftest-coverage)
+target_link_libraries(choqok_plurk ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${QJSON_LIBRARY} ${QTOAUTH_LIBRARY} choqok plurkapihelper -fprofile-arcs)

# Install

改完之後重新編譯,我的環境是依照 KDE Build Environment[2] 建立的,所以我是這樣編譯並執行程式的
cs choqok && kdebuild && ~/kde/inst/master/bin/choqok
執行時記得每項功能都點一點,這樣才會產生較完整的資料。

最後,我改使用 lcov[3],而不是 gcov,來產生較漂亮的網頁報表。
ubuntu@ubuntu-Vostro-V131 ~/kde/src/choqok (git-svn)-[plurk] % lcov -d ../../build/choqok/microblogs/plurk/CMakeFiles/choqok_plurk.dir/ -capture -o choqok.info
Capturing coverage data from ../../build/choqok/microblogs/plurk/CMakeFiles/choqok_plurk.dir/
Found gcov version: 4.6.1
Scanning ../../build/choqok/microblogs/plurk/CMakeFiles/choqok_plurk.dir/ for .gcda files ...
Found 19 data files in ../../build/choqok/microblogs/plurk/CMakeFiles/choqok_plurk.dir/
Processing choqok_plurk.dir/plurkaccount.gcda
Processing choqok_plurk.dir/plurkapishowthread.gcda
... ...
Processing choqok_plurk.dir/plurkapisearchtimelinewidget.gcda
Processing choqok_plurk.dir/plurkapimicroblogwidget.gcda
Processing choqok_plurk.dir/choqok_plurk_automoc.gcda
Finished .info-file creation

ubuntu@ubuntu-Vostro-V131 ~/kde/src/choqok (git-svn)-[plurk] % genhtml -o results choqok.info
Reading data file choqok.info
Found 104 entries.
Found common filename prefix "/home/ubuntu/kde"
Writing .css and .png files.
Generating output.
Processing file build/choqok/libchoqok/choqokbehaviorsettings.h
Processing file build/choqok/libchoqok/choqokappearancesettings.h
... ...
Processing file /usr/include/qt4/QtGui/qcolor.h
Processing file /usr/include/qt4/QtXml/qdom.h
Writing directory view page.
Overall coverage rate:
lines......: 37.8% (1369 of 3619 lines)
functions..: 46.5% (546 of 1173 functions)
branches...: 27.7% (599 of 2164 branches)

ubuntu@ubuntu-Vostro-V131 ~/kde/src/choqok (git-svn)-[plurk] % konqueror results/index.html

最後附上其他有使用到的參考資料
http://www.yuanma.org/data/2006/0613/article_805.htm
http://xuwenzhang.org/blog/tag/gcov/

1. http://gcc.gnu.org/onlinedocs/gcc/Gcov.html
2. http://techbase.kde.org/Getting_Started/Build/Environment
3. http://ltp.sourceforge.net/coverage/lcov.php

2011
08.24

Plurk for Choqok

I’m starting a project to add plurk microblog into choqok[1], a KDE micro-blogging client.
The status right now is merely pass the OAuth of plurk and read posts, but not stable, crashes all the time.

Since it’s not stable yet, so I push the code on github[2] temporally, will trying to merge back to choqok once it’s done.
I’ll try to complete the code for plurk microblog, and I also look forward to anyone of you could send me patches to make it better.

BTW, according to the license of Choqok, the plurk microblog project will following the same license, it’s GNU GPLv3.

1. http://choqok.gnufolks.org/
2. https://github.com/acelan/choqok plurk branch

2011
03.01

I read some interesting articles about nested function by C[1][2] and thought this is easy to be implemented by C++, so I wrote one C++ version.

1. 在 C 语言中包装函数 — Closure 和 GCC nested function
2. GCC 的 nested function 與 trampoline

Read More >>

2010
09.03

I’m trying to log how I built an rtl8190 DKMS package, the info may not correct and only works for me.

tar xf rtl8190p_linux_2.6.0011.1029.2009.tar.gz
sudo mv rtl8190p_linux_2.6.0011.1029.2009 /usr/src/rtl8190p-0011.1029.2009/

Modified the Makefile and copy out the .ko file

@make -C $(KSRC) SUBDIRS=$(RTL819x_DIR)/HAL/$(HAL_SUB_DIR) modules
+ cp ./HAL/rtl8192/r8190_pci.ko .

Prepare files needed, “dkms.conf”, “install.sh”, “remove.sh”
% cat /usr/src/rtl8190p-0011.1029.2009/dkms.conf
PACKAGE_NAME="rtl8190p"
PACKAGE_VERSION="0011.1029.2009"
CLEAN="make clean"
BUILT_MODULE_NAME[0]="r8190"
DEST_MODULE_NAME[0]="r8190"
DEST_MODULE_LOCATION[0]="/updates"
POST_INSTALL="install.sh $dkms_tree/$PACKAGE_NAME/$PACKAGE_VERSION"
POST_REMOVE="remove.sh"
AUTOINSTALL="yes"

% cat /usr/src/rtl8190p-0011.1029.2009/install.sh
cp -a firmware/RTL8190P /lib/firmware/

% cat /usr/src/rtl8190p-0011.1029.2009/remove.sh
rm -rf /lib/firmware/RTL8190P

And remember to give them execution permission
sudo chmod a+x /usr/src/rtl8190p-0011.1029.2009/{install,remove}.sh

Add this driver into dkms system
% sudo dkms add -m rtl8190p -v 0011.1029.2009

Creating symlink /var/lib/dkms/rtl8190p/0011.1029.2009/source ->
/usr/src/rtl8190p-0011.1029.2009

DKMS: add Completed.

Try to build it
% sudo dkms build -m rtl8190p -v 0011.1029.2009

Kernel preparation unnecessary for this kernel. Skipping...

Building module:
cleaning build area....
make KERNELRELEASE=2.6.35-19-generic............
cleaning build area....

DKMS: build Completed.

No error, so try to install it and see if everything all correct.
% sudo dkms install -m rtl8190p -v 0011.1029.2009

r8190_pci.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/2.6.35-19-generic/updates/dkms/

Running post_install:

depmod....

DKMS: install Completed.

Now, try to load the module and test the driver
sudo modprobe r8190_pci
dmesg | tail

Pack the .deb package
% sudo dkms mkdsc -m rtl8190p -v 0011.1029.2009 --source-only
Using /etc/dkms/template-dkms-mkdsc
copying template...
modifying debian/changelog...
modifying debian/compat...
modifying debian/control...
modifying debian/copyright...
modifying debian/dirs...
modifying debian/postinst...
modifying debian/prerm...
modifying debian/README.Debian...
modifying debian/rules...
copying legacy postinstall template...
Copying source tree...
Building source package... dpkg-source --before-build rtl8190p-dkms-0011.1029.2009
debian/rules clean
dpkg-source -b rtl8190p-dkms-0011.1029.2009
dpkg-source: warning: no source format specified in debian/source/format, see dpkg-source(1)
dpkg-genchanges -S >../rtl8190p-dkms_0011.1029.2009_source.changes
dpkg-genchanges: including full source code in upload
dpkg-source --after-build rtl8190p-dkms-0011.1029.2009

DKMS: mkdsc Completed.
Moving built files to /var/lib/dkms/rtl8190p/0011.1029.2009/dsc...
Cleaning up temporary files...

You can find the .deb file here
% ls -l /var/lib/dkms/rtl8190p/0011.1029.2009/deb
total 2020
-rw-r--r-- 1 root root 2066436 Sep 3 20:21 rtl8190p-dkms_0011.1029.2009_all.deb

2010
09.01

First of all, check how many Cs state your system support.

acelan@acelan-nb ~ % cat /proc/acpi/processor/*/power
active state: C0
max_cstate: C8
maximum allowed latency: 749931 usec
states:
C1: type[C1] promotion[--] demotion[--] latency[001] usage[00034144] duration[00000000000000000000]
C2: type[C2] promotion[--] demotion[--] latency[001] usage[12402973] duration[00000000041800676364]
active state: C0
max_cstate: C8
maximum allowed latency: 749931 usec
states:
C1: type[C1] promotion[--] demotion[--] latency[001] usage[00017168] duration[00000000000000000000]
C2: type[C2] promotion[--] demotion[--] latency[001] usage[14252404] duration[00000000042491108472]

Then get fadt(Fixed ACPI Description table) and disassemble it
sudo cat /proc/acpi/fadt > /tmp/fadt.dat
acelan@acelan-nb ~ % iasl -d /tmp/fadt.dat

Intel ACPI Component Architecture
AML Disassembler version 20090521 [Jun 30 2009]
Copyright (C) 2000 - 2009 Intel Corporation
Supports ACPI Specification Revision 3.0a

Loading Acpi table from file /tmp/fadt.dat
Acpi Data Table [FACP] decoded, written to "/tmp/fadt.dsl"

Check those two values to see if C2 is smaller then 100(0×64) and C3 is smaller then 1000(0×3E8).
acelan@acelan-nb ~ % grep Latency /tmp/fadt.dsl
[060h 0096 2] C2 Latency : 0001
[062h 0098 2] C3 Latency : 03E9

If not, that means BIOS blocks the system switch to C2/C3 state.

In drivers/acpi/processor_idle.c:325 (linux 2.6.35)
/*
* FADT specified C2 latency must be less than or equal to
* 100 microseconds.
*/
if (acpi_gbl_FADT.C2latency > ACPI_PROCESSOR_MAX_C2_LATENCY) {
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
"C2 latency too large [%d]\n", acpi_gbl_FADT.C2latency));
/* invalidate C2 */
pr->power.states[ACPI_STATE_C2].address = 0;
}

/*
* FADT supplied C3 latency must be less than or equal to
* 1000 microseconds.
*/
if (acpi_gbl_FADT.C3latency > ACPI_PROCESSOR_MAX_C3_LATENCY) {
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
"C3 latency too large [%d]\n", acpi_gbl_FADT.C3latency));
/* invalidate C3 */
pr->power.states[ACPI_STATE_C3].address = 0;
}

2010
03.25

Just a simple note about what I have did for building my won Android ROM for my Nexus One

get repo utility from below link

http://source.android.com/download/using-repo

Then run
repo init -u git://github.com/cyanogen/android.git -b eclair
repo sync

Create a file buildspec.mk with those contents(for Nexus One)
TARGET_PRODUCT:=cyanogen_passion
TARGET_BUILD_VARIANT:=eng
TARGET_BUILD_TYPE:=release

Run the command to setup you environment
. build/envsetup.sh

To specifically configure the build system for CyanogenMod
lunch cyanogen_passion-eng

Connect you Nexus One with USB and open debug mode to retrieve proprietary library from cell phone
(cd vendor/google/passion;./extract-files.sh)

make -j4

2010
02.09

% cat /etc/apt/sources.list.d/handbrake.list
deb http://ppa.launchpad.net/handbrake-ubuntu/ppa/ubuntu karmic main
deb-src http://ppa.launchpad.net/handbrake-ubuntu/ppa/ubuntu karmic main

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 62D38753
sudo apt-get update
sudo aptitude install handbrake-cli

HandBrakeCLI -i ccc.avi -o ccc.mp4

2010
01.07

I’m trying to use eclipse to write a hello android program, but encountered a problem while installing ADT plugin for eclipse.

The following is the solution and from this bug report, the problem is fixed in eclipse (3.5.1+repack~3-0ubuntu1).

Read More >>

2009
11.06

Apply patch

PATCH=patch_filename ; git am $PATCH || (git apply --reject $PATCH ; find -name *.rej)

It’s done, if no .rej files be produced.

If git am failed, it’ll try to apply the other successful part and produce the .rej files to indicate the failed part.

Edit the failed files then, and using git status to make sure how many files infected and using git add files to add them or using git add -u to add all not updated files.

Finally, git am --resolved

Note for the zsh user. (2010/01/12)
I changed my default shell to zsh recently and found the apply patch command is broken. Although zsh claim that it’s compatible with bash, there are still some difference. But the good news is we can overcome this problem by adding one more line in the .zshrc
setopt GLOB_SUBST
More detail, please read this

2009
10.28

Android apps I installed

* Mobentoo(a.k.a. SlideME) – An Android market like program
* Color Dict Lite – A very good dictionary, the dictionary files are compatible with stardict, so you can download a lot of dictionary from Internet.
* RockOn –
* Ultra Notes – More useful note with category
* Opera Mini
* rTerm – bbs client
* aiCurrency
* AndAppStore
* Aldiko – online book
* Advance Task Manager – I paid for this program, 0.99USD