Skip to content

Commit 1169044

Browse files
committed
stap doc
1 parent a459afd commit 1169044

File tree

14 files changed

+3369
-0
lines changed

14 files changed

+3369
-0
lines changed

201308/20130814_02.md

Lines changed: 404 additions & 0 deletions
Large diffs are not rendered by default.

201308/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
##### 20130823_02.md [《PostgreSQL Streaming Replication COMMAND used in psql》](20130823_02.md)
66
##### 20130823_01.md [《PostgreSQL WHY modify numeric scale must rewrite table》](20130823_01.md)
77
##### 20130817_01.md [《PostgreSQL How can i decode the NUMERIC precision and scale in pg_attribute.atttypmod》](20130817_01.md)
8+
##### 20130814_02.md [《PostgreSQL SystemTap on Linux - 1》](20130814_02.md)
89
##### 20130814_01.md [《PostgreSQL 9.4 pending patch : UNNEST with multiple args, and TABLE with multiple funcs》](20130814_01.md)
910
##### 20130811_01.md [《PostgreSQL pg_stats used to estimate top N freps values and explain rows》](20130811_01.md)
1011
##### 20130806_03.md [《PostgreSQL pending patch : fail-back without fresh backup (have bug?)》](20130806_03.md)

201309/20130903_01.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Eclipse Systemtap IDE
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2013-09-03
8+
9+
### 标签
10+
PostgreSQL , Linux , systemtap , stap , dtrace
11+
12+
----
13+
14+
## 背景
15+
## 参考
16+
http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.linuxtools.systemtap.ui.doc%2FLinux_Tools_Project%2FSystemtap%2FUser_Guide%2FSystemTap-IDE.html
17+
18+
19+
<a rel="nofollow" href="http://info.flagcounter.com/h9V1" ><img src="http://s03.flagcounter.com/count/h9V1/bg_FFFFFF/txt_000000/border_CCCCCC/columns_2/maxflags_12/viewers_0/labels_0/pageviews_0/flags_0/" alt="Flag Counter" border="0" ></a>
20+

201309/20130903_02.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
## Systemtap supported data type (long,string,array,statistic), note don't support numeric except long
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2013-09-03
8+
9+
### 标签
10+
PostgreSQL , Linux , systemtap , stap , dtrace
11+
12+
----
13+
14+
## 背景
15+
systemtap支持4种数据类型, 分别为long整型, 字符串, 数组, 统计类型.
16+
17+
数字只支持长整型, 不支持浮点.
18+
19+
例1 :
20+
21+
```
22+
[root@db-172-16-3-39 ~]# cat test.stp
23+
function fun:long() %{
24+
float a=1.9;
25+
STAP_RETVALUE=a;
26+
%}
27+
probe begin {
28+
printf("%d\n", fun())
29+
exit()
30+
}
31+
```
32+
33+
输出为转换成长整型后的值, 1;
34+
35+
```
36+
[root@db-172-16-3-39 ~]# stap -g test.stp
37+
1
38+
```
39+
40+
例2 :
41+
42+
```printf("%d\n", fun())``` 改成 ```printf("%f\n", fun())``` 将报错.
43+
44+
```
45+
[root@db-172-16-3-39 ~]# stap -g test.stp
46+
parse error: invalid or missing conversion specifier
47+
saw: string '%f\n' at test.stp:6:10
48+
source: printf("%f\n", fun())
49+
^
50+
1 parse error.
51+
Pass 1: parse failed. Try again with another '--vp 1' option.
52+
```
53+
54+
因为输出格式只有```%d,%s.``` 分别代表整型和字符串.
55+
56+
例3 :
57+
58+
改函数输出类型float.
59+
60+
```
61+
[root@db-172-16-3-39 ~]# cat test.stp
62+
function fun:float() %{
63+
float a=1.9;
64+
STAP_RETVALUE=a;
65+
%}
66+
probe begin {
67+
printf("%d\n", fun())
68+
exit()
69+
}
70+
```
71+
72+
同样报错, 因为systemtap不支持这个类型.
73+
74+
```
75+
[root@db-172-16-3-39 ~]# stap -g test.stp
76+
parse error: expected 'string' or 'long'
77+
saw: identifier 'float' at test.stp:1:14
78+
source: function fun:float() %{
79+
^
80+
1 parse error.
81+
Pass 1: parse failed. Try again with another '--vp 1' option.
82+
```
83+
84+
例4 :
85+
86+
接下来去掉内嵌C函数, 直接将1.9赋予本地变量.
87+
88+
```
89+
[root@db-172-16-3-39 ~]# cat test.stp
90+
probe begin {
91+
var = 1.9
92+
printf("%d\n", var)
93+
exit()
94+
}
95+
```
96+
97+
执行时报错, 因为.这个操作符是字符串连接符号. 而不是小数点.
98+
99+
```
100+
[root@db-172-16-3-39 ~]# stap test.stp
101+
semantic error: type mismatch (string vs. long): identifier 'var' at test.stp:2:3
102+
source: var = 1.9
103+
^
104+
105+
semantic error: type was first inferred here (long): identifier 'var' at :3:18
106+
source: printf("%d\n", var)
107+
^
108+
109+
semantic error: type mismatch (long vs. string): number '1' at :2:9
110+
source: var = 1.9
111+
^
112+
113+
semantic error: type mismatch (long vs. string): number '9' at :2:11
114+
source: var = 1.9
115+
^
116+
117+
Pass 2: analysis failed. Try again with another '--vp 01' option.
118+
```
119+
120+
```.``` 在systemtap中是字符串的连接符号.
121+
122+
例5 :
123+
124+
```
125+
[root@db-172-16-3-39 ~]# vi test.stp
126+
probe begin {
127+
var = 1.9
128+
printf("%s\n", var)
129+
exit()
130+
}
131+
[root@db-172-16-3-39 ~]# stap test.stp
132+
semantic error: type mismatch (long vs. string): number '1' at test.stp:2:9
133+
source: var = 1.9
134+
^
135+
136+
semantic error: type mismatch (long vs. string): number '9' at :2:11
137+
source: var = 1.9
138+
^
139+
140+
Pass 2: analysis failed. Try again with another '--vp 01' option.
141+
```
142+
143+
例6 :
144+
145+
连接字符串时, 字符串必须使用""双引号.
146+
147+
```
148+
[root@db-172-16-3-39 ~]# vi test.stp
149+
probe begin {
150+
var = "1"."9"
151+
printf("%s\n", var)
152+
exit()
153+
}
154+
[root@db-172-16-3-39 ~]# stap test.stp
155+
19
156+
```
157+
158+
var 在这里存储的是"19"字符串.
159+
160+
## 参考
161+
1\. https://sourceware.org/systemtap/langref/Language_elements.html
162+
163+
164+
<a rel="nofollow" href="http://info.flagcounter.com/h9V1" ><img src="http://s03.flagcounter.com/count/h9V1/bg_FFFFFF/txt_000000/border_CCCCCC/columns_2/maxflags_12/viewers_0/labels_0/pageviews_0/flags_0/" alt="Flag Counter" border="0" ></a>
165+

201309/20130903_03.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
## Systemtap statistics type example
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2013-09-03
8+
9+
### 标签
10+
PostgreSQL , Linux , systemtap , stap , dtrace , probe
11+
12+
----
13+
14+
## 背景
15+
systemtap统计数据类型, 同array一样, 必须定义为global变量. ( 换句话说, 统计元素可以存储在全局变量(scalar)或者 全局array中. )
16+
17+
Aggregate instances are used to collect statistics on numerical values, when it is important to accumulate new data quickly and in large volume. These instances operate without exclusive locks, and store only aggregated stream statistics. Aggregates make sense only for global variables. They are stored individually or as elements of an associative array.
18+
19+
相比array的好处是, 操作时不需要exclusive lock. 在执行统计时处理所有数据.
20+
21+
For each instance of a distinct extraction function operating on a given identifier, the translator computes a set of statistics. With each execution of an extraction function, the aggregation is computed for that moment across all processors. The first argument of each function is the same style of l-value as used on the left side of the aggregation operation.
22+
23+
统计类型可以想象成存储一串整型, 目前统计类型支持count, max, min, avg, sum这种统计操作. 同时还支持柱状图输出, hist_linear(自定义low, high和width), hist_log(2^n次方) .
24+
25+
例如 :
26+
27+
```
28+
[root@db-172-16-3-39 ~]# vi test.stp
29+
global var
30+
probe begin {
31+
var <<< 12
32+
var <<< 12
33+
var <<< 33
34+
var <<< 44
35+
var <<< 55
36+
var <<< 16
37+
printf("count, min, max, avg, sum\n")
38+
printf("%d, %d, %d, %d, %d\n", @count(var), @min(var), @max(var), @avg(var), @sum(var))
39+
//print(@hist_linear(var,0,100,10))
40+
print(@hist_log(var))
41+
exit()
42+
}
43+
```
44+
45+
输出
46+
47+
```
48+
[root@db-172-16-3-39 ~]# stap test.stp
49+
count, min, max, avg, sum
50+
6, 12, 55, 28, 172
51+
value |-------------------------------------------------- count
52+
2 | 0 -- >=2 && <4 的元素有多少个.
53+
4 | 0 -- >=4 && <8 的元素有多少个.
54+
8 |@@ 2 -- >=8 && <16 的元素有多少个.
55+
16 |@ 1 -- >=16 && <32 的元素有多少个.
56+
32 |@@@ 3 -- >=32 && <64 的元素有多少个.
57+
64 | 0 -- >=64 && <128 的元素有多少个.
58+
128 | 0 -- >=128的元素有多少个.
59+
```
60+
61+
稍微解释一下
62+
63+
```
64+
count : 存储的元素个数.
65+
min : 所有元素中的最小值.
66+
max : 所有元素中的最大值.
67+
avg : 平均值
68+
sum : 总和
69+
hist_log : 以2^n次方为动态width. 输出每个bucket中元素的个数. @表示有元素, ~表示没有元素(中间省略的bucket),
70+
```
71+
72+
自定义width, 使用hist_linear :
73+
74+
```
75+
[root@db-172-16-3-39 ~]# cat test.stp
76+
global var
77+
probe begin {
78+
var <<< 12
79+
var <<< 12
80+
var <<< 33
81+
var <<< 44
82+
var <<< 55
83+
var <<< 16
84+
printf("count, min, max, avg, sum\n")
85+
printf("%d, %d, %d, %d, %d\n", @count(var), @min(var), @max(var), @avg(var), @sum(var))
86+
print(@hist_linear(var,0,1000,10))
87+
//print(@hist_log(var))
88+
exit()
89+
}
90+
```
91+
92+
输出 :
93+
94+
```
95+
[root@db-172-16-3-39 ~]# stap test.stp
96+
count, min, max, avg, sum
97+
6, 12, 55, 28, 172
98+
value |-------------------------------------------------- count
99+
0 | 0
100+
10 |@@@ 3
101+
20 | 0
102+
30 |@ 1
103+
40 |@ 1
104+
50 |@ 1
105+
60 | 0
106+
70 | 0
107+
```
108+
109+
解释 :
110+
111+
```
112+
print(@hist_linear(var,0,1000,10))
113+
lower=0
114+
high=1000
115+
width=10
116+
```
117+
118+
那么一共有101个bucket.
119+
120+
## 参考
121+
1\. https://sourceware.org/systemtap/langref/Statistics_aggregates.html
122+
123+
2\. https://sourceware.org/systemtap/tutorial/Analysis.html
124+
125+
126+
<a rel="nofollow" href="http://info.flagcounter.com/h9V1" ><img src="http://s03.flagcounter.com/count/h9V1/bg_FFFFFF/txt_000000/border_CCCCCC/columns_2/maxflags_12/viewers_0/labels_0/pageviews_0/flags_0/" alt="Flag Counter" border="0" ></a>
127+

0 commit comments

Comments
 (0)