kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp

部分GCC选项

-Werror 和 -I 很有用
命令描述
-l library-llibrary 进行链接时搜索名为library的库。例子: $ gcc test.c -lm -o test
-Idir dir加入到搜索头文件的路径列表中。例子: $ gcc test.c -I../inc -o test
-Ldir dir加入到搜索库文件的路径列表中。例子: $ gcc -I/home/foo -L/home/foo -ltest test.c -o test
-Dname 预定义一个名为name的宏,值为1。例子: $ gcc -DTEST_CONFIG test.c -o test
-Dname=definition 预定义名为name,值为definition的宏。
-ggdb -ggdblevel 为调试器 gdb 生成调试信息。level可以为1,2,3,默认值为2。
-g -glevel 生成操作系统本地格式的调试信息。-g 和 -ggdb 并不太相同, -g 会生成 gdb 之外的信息。level取值同上。
-s 去除可执行文件中的符号表和重定位信息。用于减小可执行文件的大小。
-M 告诉预处理器输出一个适合make的规则,用于描述各目标文件的依赖关系。对于每个 源文件,预处理器输出 一个make规则,该规则的目标项(target)是源文件对应的目标文件名,依赖项(dependency)是源文件中 #include引用的所有文件。生成的规则可 以是单行,但如果太长,就用`/'-换行符续成多行。规则 显示在标准输出,不产生预处理过的C程序。
-C 告诉预处理器不要丢弃注释。配合`-E'选项使用。
-P 告诉预处理器不要产生`#line'命令。配合`-E'选项使用。
-static 在支持动态链接的系统上,阻止连接共享库。该选项在其它系统上 无效。
-nostdlib 不连接系统标准启动文件和标准库文件,只把指定的文件传递给连接器。
Warnings
-Wall 会打开一些很有用的警告选项,建议编译时加此选项。
-W -Wextra 打印一些额外的警告信息。
-w 禁止显示所有警告信息。
-Wshadow 当一个局部变量遮盖住了另一个局部变量,或者全局变量时,给出警告。很有用的选项,建议打开。 -Wall 并不会打开此项。
-Wpointer-arith 对函数指针或者void *类型的指针进行算术操作时给出警告。也很有用。 -Wall 并不会打开此项。
-Wcast-qual 当强制转化丢掉了类型修饰符时给出警告。 -Wall 并不会打开此项。
-Waggregate-return 如果定义或调用了返回结构体或联合体的函数,编译器就发出警告。
-Winline 无论是声明为 inline 或者是指定了-finline-functions 选项,如果某函数不能内联,编译器都将发出警告。如果你的代码含有很多 inline 函数的话,这是很有用的选项。
-Werror 把警告当作错误。出现任何警告就放弃编译。
-Wunreachable-code 如果编译器探测到永远不会执行到的代码,就给出警告。也是比较有用的选项。
-Wcast-align 一旦某个指针类型强制转换导致目标所需的地址对齐增加时,编译器就发出警告。
-Wundef 当一个没有定义的符号出现在 #if 中时,给出警告。
-Wredundant-decls 如果在同一个可见域内某定义多次声明,编译器就发出警告,即使这些重复声明有效并且毫无差别。

编译Android的perf

1 编译elfutils

elfutils源码

1
cp -r /home/kk/andr-perf/android-ndk-r10c/platforms/android-21/arch-arm arch-arm-21-ok
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
cd elfutils
./configure --host=arm-none-linux-gnueabi

sed -i -e 's/^CC = gcc/CC = $(CROSS_COMPILE)gcc/g' *Makefile
sed -i -e 's/^CC = gcc/CC = $(CROSS_COMPILE)gcc/g' */Makefile
sed -i -e 's/^AR = ar/AR = $(CROSS_COMPILE)ar/g' */Makefile

Makefile
-SUBDIRS = config m4 lib libelf libebl libdwfl libdw libcpu libasm backends \
+SUBDIRS = config libelf
+#SUBDIRS = config m4 lib libelf libebl libdwfl libdw libcpu libasm backends \

libelf/Makefile
-AM_CFLAGS = $(am__append_1) -Wall -Wshadow -Werror \
+AM_CFLAGS = $(am__append_1) -Wall -Wshadow \

-               -Wl,--soname,$@.$(VERSION),-z,-defs,-z,relro $(libelf_so_LDLIBS)
+               -Wl,--soname,$@.$(VERSION),-defs,-z,relro $(libelf_so_LDLIBS)

bionic-fixup/AndroidFixup.h
-static inline char *stpcpy(char *dst, const char *src)
+static inline char *stpcpy_noneed(char *dst, const char *src)

host-darwin-fixup/AndroidFixup.h
-static inline size_t strnlen (const char *__string, size_t __maxlen)
+static inline size_t strnlen_noneed (const char *__string, size_t __maxlen)

libelf/elf32_updatefile.c
libelf/elf_begin.c
libelf/elf_getarsym.c
#include "bionic-fixup/AndroidFixup.h"
#include "host-darwin-fixup/AndroidFixup.h"

libelf/elf_error.c
#include "host-darwin-fixup/AndroidFixup.h"

export NDK_SYSROOT=/home/kk/andr-perf/arch-arm-21-ok
export NDK_TOOLCHAIN=/home/kk/andr-perf/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
make ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} CFLAGS="--sysroot=${NDK_SYSROOT} -I`pwd`/bionic-fixup"

2 编译内核

1
2
3
4
5
6
7
make goldfish_defconfig

Makefile:
 195 ARCH            ?= arm
 196 CROSS_COMPILE   ?= /home/kk/android/gcc-arm-none-eabi-4_8-2014q3/bin/arm-none-eabi-

make

3 编译perf,perf要放在goldfish-android-goldfish-3.4/tools/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
cp /home/kk/android/android-ndk-r10c/platforms/android-19/arch-arm/usr/include/asm/page.h /home/kk/andr-perf/arch-arm-21-ok/usr/include/asm

pwd
/home/kk/andr-perf/elfutils-android-4.4.4_r2.0.1/libelf
cp elf.h gelf.h libelf.h /home/kk/andr-perf/arch-arm-21-ok/usr/include/
cp libelf.a libelf.so /home/kk/andr-perf/arch-arm-21-ok/usr/lib/

pwd
/home/kk/andr-perf/goldfish-android-goldfish-3.4/tools/linux-tools-perf-android-4.4.4_r2.0.1
cp /home/kk/andr-perf/goldfish-android-goldfish-3.4/lib/rbtree.o util/
```

Makefile
-EXTLIBS = -lpthread -lrt -lelf -lm
+EXTLIBS = -lelf -lm

-               msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
+#              msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);


-$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
+#$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
+#      $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<


perf.h
+#define __used__
+#define __force


util/util.h
+#include <linux/types_ws.h>  // 他会找到util/include/linux/types.h,导致没有include<linux/types.h>,会报没有__be32等错误


pwd
/home/kk/andr-perf/arch-arm-21-ok
cp ./usr/include/linux/types.h ./usr/include/linux/types_ws.h

/home/kk/andr-perf/arch-arm-21-ok/usr/include/linux/tcp.h 删掉下面这部分
 enum {
  TCP_FLAG_CWR = __constant_cpu_to_be32(0x00800000),
  TCP_FLAG_ECE = __constant_cpu_to_be32(0x00400000),
  TCP_FLAG_URG = __constant_cpu_to_be32(0x00200000),
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCP_FLAG_ACK = __constant_cpu_to_be32(0x00100000),
  TCP_FLAG_PSH = __constant_cpu_to_be32(0x00080000),
  TCP_FLAG_RST = __constant_cpu_to_be32(0x00040000),
  TCP_FLAG_SYN = __constant_cpu_to_be32(0x00020000),
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  TCP_FLAG_FIN = __constant_cpu_to_be32(0x00010000),
  TCP_RESERVED_BITS = __constant_cpu_to_be32(0x0F000000),
  TCP_DATA_OFFSET = __constant_cpu_to_be32(0xF0000000)
 };


export NDK_SYSROOT=/home/kk/andr-perf/arch-arm-21-ok
export NDK_TOOLCHAIN=/home/kk/andr-perf/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-

// 
make ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} CFLAGS="--sysroot=${NDK_SYSROOT} -I`pwd`" LDFLAGS+=-static

正则表达式常用字符

字符 描述
\ 将下一个字符标记为一个特殊字符、或一个原义字符、或一个 后向引用、或一个八进制转义符。例如,'n' 匹配字符 "n"。'\n' 匹配一个换行符。序列 '\\' 匹配 "\" 而 "\(" 则匹配 "("。
^ 匹配输入字符串的开始位置。如果设置了 RegExp 对象的 Multiline 属性,^ 也匹配 '\n' 或 '\r' 之后的位置。
$ 匹配输入字符串的结束位置。如果设置了RegExp 对象的 Multiline 属性,$ 也匹配 '\n' 或 '\r' 之前的位置。
\A 指定匹配必须出现在字符串的开头(忽略   Multiline   选项)。
\Z 指定匹配必须出现在字符串的结尾或字符串结尾的     之前(忽略   Multiline   选项)。
\z 指定匹配必须出现在字符串的结尾(忽略   Multiline   选项)。
* 匹配前面的子表达式零次或多次。例如,zo* 能匹配 "z" 以及 "zoo"。 * 等价于{0,}。
+ 匹配前面的子表达式一次或多次。例如,'zo+' 能匹配 "zo" 以及 "zoo",但不能匹配 "z"。+ 等价于 {1,}。
? 匹配前面的子表达式零次或一次。例如,"do(es)?" 可以匹配 "do" 或 "does" 中的"do" 。? 等价于 {0,1}。
{n} n 是一个非负整数。匹配确定的 n 次。例如,'o{2}' 不能匹配 "Bob" 中的 'o',但是能匹配 "food" 中的两个 o。
{n,} n 是一个非负整数。至少匹配n 次。例如,'o{2,}' 不能匹配 "Bob" 中的 'o',但能匹配 "foooood" 中的所有 o。'o{1,}' 等价于 'o+'。'o{0,}' 则等价于 'o*'。
{n,m} m 和 n 均为非负整数,其中n <= m。最少匹配 n 次且最多匹配 m 次。刘, "o{1,3}" 将匹配 "fooooood" 中的前三个 o。'o{0,1}' 等价于 'o?'。请注意在逗号和两个数之间不能有空格。
? 当该字符紧跟在任何一个其他限制符 (*, +, ?, {n}, {n,}, {n,m}) 后面时,匹配模式是非贪婪的。非贪婪模式尽可能少的匹配所搜索的字符串,而默认的贪婪模式则尽可能多的匹配所搜索的字符串。例如,对于字符串 "oooo",'o+?' 将匹配单个 "o",而 'o+' 将匹配所有 'o'。
. 匹配除 "\n" 之外的任何单个字符。要匹配包括 '\n' 在内的任何字符,请使用象 '[.\n]' 的模式。
(pattern) 匹配pattern 并获取这一匹配。所获取的匹配可以从产生的 Matches 集合得到,在VBScript 中使用 SubMatches 集合,在Visual Basic Scripting Edition 中则使用 $0$9 属性。要匹配圆括号字符,请使用 '\(' 或 '\)'。
(?:pattern) 匹配 pattern 但不获取匹配结果,也就是说这是一个非获取匹配,不进行存储供以后使用。这在使用 "或" 字符 (|) 来组合一个模式的各个部分是很有用。例如, 'industr(?:y|ies) 就是一个比 'industry|industries' 更简略的表达式。
(?=pattern) 正向预查,在任何匹配 pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。例如, 'Windows (?=95|98|NT|2000)' 能匹配 "Windows 2000" 中的 "Windows" ,但不能匹配 "Windows 3.1" 中的 "Windows"。预查不消耗字符,也就是说,在一个匹配发生后,在最后一次匹配之后立即开始下一次匹配的搜索,而不是从包含预查的字符之后开始。
(?!pattern) 负向预查,在任何不匹配Negative lookahead matches the search string at any point where a string not matching pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。例如'Windows (?!95|98|NT|2000)' 能匹配 "Windows 3.1" 中的 "Windows",但不能匹配 "Windows 2000" 中的 "Windows"。预查不消耗字符,也就是说,在一个匹配发生后,在最后一次匹配之后立即开始下一次匹配的搜索,而不是从包含预查的字符之后开始
x|y 匹配 x 或 y。例如,'z|food' 能匹配 "z" 或 "food"。'(z|f)ood' 则匹配 "zood" 或 "food"。
[xyz] 字符集合。匹配所包含的任意一个字符。例如, '[abc]' 可以匹配 "plain" 中的 'a'。
[^xyz] 负值字符集合。匹配未包含的任意字符。例如, '[^abc]' 可以匹配 "plain" 中的'p'。
[a-z] 字符范围。匹配指定范围内的任意字符。例如,'[a-z]' 可以匹配 'a' 到 'z' 范围内的任意小写字母字符。
[^a-z] 负值字符范围。匹配任何不在指定范围内的任意字符。例如,'[^a-z]' 可以匹配任何不在 'a' 到 'z' 范围内的任意字符。
\b 匹配一个单词边界,也就是指单词和空格间的位置。例如, 'er\b' 可以匹配"never" 中的 'er',但不能匹配 "verb" 中的 'er'。
\B 匹配非单词边界。'er\B' 能匹配 "verb" 中的 'er',但不能匹配 "never" 中的 'er'。
\cx 匹配由x指明的控制字符。例如, \cM 匹配一个 Control-M 或回车符。 x 的值必须为 A-Z 或 a-z 之一。否则,将 c 视为一个原义的 'c' 字符。
\d 匹配一个数字字符。等价于 [0-9]。
\D 匹配一个非数字字符。等价于 [^0-9]。
\f 匹配一个换页符。等价于 \x0c 和 \cL。
\n 匹配一个换行符。等价于 \x0a 和 \cJ。
\r 匹配一个回车符。等价于 \x0d 和 \cM。
\s 匹配任何空白字符,包括空格、制表符、换页符等等。等价于 [ \f\n\r\t\v]。
\S 匹配任何非空白字符。等价于 [^ \f\n\r\t\v]。
\t 匹配一个制表符。等价于 \x09 和 \cI。
\v 匹配一个垂直制表符。等价于 \x0b 和 \cK。
\w 匹配包括下划线的任何单词字符。等价于'[A-Za-z0-9_]'。
\W 匹配任何非单词字符。等价于 '[^A-Za-z0-9_]'。
\xn 匹配 n,其中 n 为十六进制转义值。十六进制转义值必须为确定的两个数字长。例如, '\x41' 匹配 "A"。'\x041' 则等价于 '\x04' & "1"。正则表达式中可以使用 ASCII 编码。.
\num 匹配 num,其中 num 是一个正整数。对所获取的匹配的引用。例如,'(.)\1' 匹配两个连续的相同字符。
\n 标识一个八进制转义值或一个后向引用。如果 \n 之前至少 n 个获取的子表达式,则 n 为后向引用。否则,如果 n 为八进制数字 (0-7),则 n 为一个八进制转义值。
\nm 标识一个八进制转义值或一个后向引用。如果 \nm 之前至少有is preceded by at least nm 个获取得子表达式,则 nm 为后向引用。如果 \nm 之前至少有 n 个获取,则 n 为一个后跟文字 的后向引用。如果前面的条件都不满足,若  n 和 m 均为八进制数字 (0-7),则 \nm 将匹配八进制转义值 nm
\nml 如果 n 为八进制数字 (0-3),且 m 和 l 均为八进制数字 (0-7),则匹配八进制转义值 nml。
\un 匹配 n,其中 n 是一个用四个十六进制数字表示的 Unicode 字符。例如, \u00A9 匹配版权符号 (?)。

jekyll的一些全局变量

http://jekyllrb.com/docs/variables/
octopress是基于jekyll,所以也可以用这些内容

Variables

Jekyll traverses your site looking for files to process. Any files with YAML front matter are subject to processing. For each of these files, Jekyll makes a variety of data available via the Liquid templating system. The following is a reference of the available data.

Global Variables
Variable Description

site

Sitewide information + configuration settings from _config.yml. See below for details.

page

Page specific information + the YAML front matter. Custom variables set via the YAML Front Matter will be available here. See below for details.

content

In layout files, the rendered content of the Post or Page being wrapped. Not defined in Post or Page files.

paginator

When the paginate configuration option is set, this variable becomes available for use.

Site Variables
Variable Description

site.time

The current time (when you run the jekyll command).

site.pages

A list of all Pages.

site.posts

A reverse chronological list of all Posts.

site.related_posts

If the page being processed is a Post, this contains a list of up to ten related Posts. By default, these are low quality but fast to compute. For high quality but slow to compute results, run the jekyll command with the --lsi (latent semantic indexing) option.

site.static_files

A list of all static files (i.e. files not processed by Jekyll's converters or the Liquid renderer). Each file has three properties: path, modified_time and extname.

site.html_pages

A list of all HTML Pages.

site.collections

A list of all the collections.

site.data

A list containing the data loaded from the YAML files located in the _data directory.

site.documents

A list of all the documents in every collection.

site.categories.CATEGORY

The list of all Posts in category CATEGORY.

site.tags.TAG

The list of all Posts with tag TAG.

site.[CONFIGURATION_DATA]

All the variables set via the command line and your _config.yml are available through the site variable. For example, if you have url: http://mysite.com in your configuration file, then in your Posts and Pages it will be stored in site.url. Jekyll does not parse changes to _config.yml in watch mode, you must restart Jekyll to see changes to variables.

Page Variables
Variable Description

page.content

The content of the Page, rendered or un-rendered depending upon what Liquid is being processed and what page is.

page.title

The title of the Page.

page.excerpt

The un-rendered excerpt of the Page.

page.url

The URL of the Post without the domain, but with a leading slash, e.g. /2008/12/14/my-post.html

page.date

The Date assigned to the Post. This can be overridden in a Post’s front matter by specifying a new date/time in the format YYYY-MM-DD HH:MM:SS (assuming UTC), or YYYY-MM-DD HH:MM:SS +/-TTTT (to specify a time zone using an offset from UTC. e.g. 2008-12-14 10:30:00 +0900).

page.id

An identifier unique to the Post (useful in RSS feeds). e.g. /2008/12/14/my-post

page.categories

The list of categories to which this post belongs. Categories are derived from the directory structure above the _posts directory. For example, a post at /work/code/_posts/2008-12-24-closures.md would have this field set to ['work', 'code']. These can also be specified in the YAML Front Matter.

page.tags

The list of tags to which this post belongs. These can be specified in the YAML Front Matter.

page.path

The path to the raw post or page. Example usage: Linking back to the page or post’s source on GitHub. This can be overridden in the YAML Front Matter.

page.next

The next post relative to the position of the current post in site.posts. Returns nil for the last entry.

page.previous

The previous post relative to the position of the current post in site.posts. Returns nil for the first entry.

Paginator
Variable Description

paginator.per_page

Number of Posts per page.

paginator.posts

Posts available for that page.

paginator.total_posts

Total number of Posts.

paginator.total_pages

Total number of Pages.

paginator.page

The number of the current page.

paginator.previous_page

The number of the previous page.

paginator.previous_page_path

The path to the previous page.

paginator.next_page

The number of the next page.

paginator.next_page_path

The path to the next page.

octopress优化

octopress优化

能够让octopress在50篇文章下跑进5s,不优化要跑60s左右
300篇15s左右

运行过程

看octopress目录下的Rakefile,里面有generate,preview,watch等。
输入rake generate是就是按照Rakefile中task :generate do执行的。
最主要的两条:

1
2
system "compass compile --css-dir #{source_dir}/stylesheets"
system "jekyll build"

第一条是编译css,第二条是生成文章。