kk Blog —— 通用基础


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

高精度定时器示例

这样设置会更好???

1
nohz=off highres=off

http://blog.chinaunix.net/uid-361890-id-257337.html

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
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/hrtimer.h>
#include <linux/jiffies.h>

static struct hrtimer timer;
ktime_t kt;

static enum hrtimer_restart hrtimer_handler(struct hrtimer *timer)
{
	//kt = ktime_set(1, 10);
	printk(" ------ I am in hrtimer -----\n");
	hrtimer_forward(timer, timer->base->get_time(), kt);
	return HRTIMER_RESTART;
}

static int __init test_init(void)
{
	pr_info("timer resolution: %lu\n", TICK_NSEC);
	kt = ktime_set(1, 10); /* 1 sec, 10 nsec */
	hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	//hrtimer_set_expires(&timer, kt);
	hrtimer_start(&timer, kt, HRTIMER_MODE_REL);
	timer.function = hrtimer_handler;

	printk("\n-------- test start ---------\n");
	return 0;
}

static void __exit test_exit(void)
{
	hrtimer_cancel(&timer);
	printk("-------- test over ----------\n");
	return;
}

MODULE_LICENSE("GPL");

module_init(test_init);
module_exit(test_exit);

编译:

1
2
3
4
5
6
7
8
9
10
name = test.o
obj-m := $(name)

KERNELDIR := /home/tangyt/tmp/linux-2.6-cloud.p1020/

default:
	make -C $(KERNELDIR) M=$(shell pwd) modules

clean:
	make -C $(KERNELDIR) M=$(shell pwd) clean

perf 火焰图分析程序性能

https://www.cnblogs.com/happyliu/p/6142929.html

使用火焰图展示结果

1、Flame Graph项目位于GitHub上:https://github.com/brendangregg/FlameGraph

2、可以用git将其clone下来:git clone https://github.com/brendangregg/FlameGraph.git

我们以perf为例,看一下flamegraph的使用方法:

1、第一步

1
sudo perf record -e cpu-clock -g -p 28591

Ctrl+c结束执行后,在当前目录下会生成采样数据perf.data.

2、第二步

用perf script工具对perf.data进行解析

1
perf script -i perf.data &> perf.unfold

3、第三步

将perf.unfold中的符号进行折叠:

1
./stackcollapse-perf.pl perf.unfold &> perf.folded

4、最后生成svg图:

1
./flamegraph.pl perf.folded > perf.svg

Ubuntu+SS

Shadows启动报错undefined symbol EVP_CIPHER_CTX_cleanup

vim /usr/local/lib/python2.7/dist-packages/shadowsocks/crypto/openssl.py

cleanup替换为reset

测试socks5命令:

curl –socks5 192.168.8.107:8388 http://www.baidu.com/


https://www.codetd.com/article/1418936

1 安装

1
2
sudo apt-get install python-pip
pip install shadowsocks

2 配置

vim config.json

1
2
3
4
5
6
7
8
9
10
{
	"server":"0.0.0.0",
	"port_password": {
		"8388": "your_password1",
		"8389": "your_password2"
	},
	"timeout":600,
	"method":"aes-256-cfb",
	"fast_open": false
}

3. 启动

1
2
3
4
ssserver -c config.json start

ssserver -c config.json -d start
ssserver -c config.json -d stop

4. server

vim /etc/systemd/system/shadowsocks.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[Unit]
Description=Shadowsocks
After=network.target

[Service]
Type=forking
PIDFile=/run/shadowsocks/server.pid
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -p /run/shadowsocks
ExecStartPre=/bin/chown root:root /run/shadowsocks
ExecStart=/usr/local/bin/ssserver --pid-file /var/run/shadowsocks/server.pid -c /etc/shadowsocks/config.json -d start
Restart=on-abort
User=root
Group=root
UMask=0027

[Install]
WantedBy=multi-user.target

设置文件权限:

1
chmod 755 /etc/systemd/system/shadowsocks.service

启动服务:

1
2
systemctl start shadowsocks
systemctl enable shadowsocks

5. 客户端

https://github.com/shadowsocks/shadowsocks-qt5/releases