diff options
| author | zhengchao <[email protected]> | 2018-12-12 14:12:59 +0600 |
|---|---|---|
| committer | zhengchao <[email protected]> | 2018-12-12 14:12:59 +0600 |
| commit | f77859345214f5e12924464ef9d49e27fe2630bb (patch) | |
| tree | c2ec7a7185ecc2932cba5bcdac91a89bba4ccedb | |
| parent | e98d6c170790ac5c10e0ed5802d93a93abe25398 (diff) | |
readme中补充fs_operate的说明
| -rw-r--r-- | readme.md | 54 |
1 files changed, 39 insertions, 15 deletions
@@ -4,7 +4,9 @@ Field Stat是一个运行状态输出与统计库。 ## 本地显示风格(style) - 输出到屏幕或文件,可选择输出瞬时值 `FS_CALC_SPEED`或累计值`FS_CALC_CURRENT`。 + 本地显示会输出到屏幕或文件,可选择输出瞬时值 `FS_CALC_SPEED`或累计值`FS_CALC_CURRENT`。 + + 允许在`FS_start`启动后注册非Column的统计域。 ### 域(Field ) @@ -42,7 +44,7 @@ status_ids[i]=FS_register(handle, FS_STYLE_STATUS, FS_CALC_CURRENT, "status_01") ``` ___________________________________________________________________________________ - column_0 column_1 column_3 column_4 column_5 c0/c1 + column_0 column_1 column_3 column_4 column_5 c0/c1 line_0 2.76e+04 5.53e+04 1.11e+05 1.38e+05 1.66e+05 5.00e-01 line_1 2.76e+04 5.53e+04 1.11e+05 1.38e+05 1.66e+05 5.00e-01 line_2 2.76e+04 5.53e+04 1.11e+05 1.38e+05 1.66e+05 5.00e-01 @@ -122,6 +124,38 @@ line,app_name=APPNAME column1=value,column2=value `percentiles = [50, 60, 80, 90, 95, 99]` +## 统计 + +### 记录统计值 + + 通过`FS_operate`函数操作统计域,函数内部使用原子变量,无锁且线程安全。 + +``` +//handle: FieldStat句柄 +//id: FS_register_**返回的ID +//column_id: 列ID,非column类型填0 +//filed_op: FS_OP_ADD: + value +// FS_OP_SUB: - value +// FS_OP_SET: = value +int FS_operate(screen_stat_handle_t handle,int id,int column_id,enum field_op op,long long value); +``` + +### 记录事件耗时 + + 应使用clock_gettime函数获得事件的耗时,[永远不要用gettimeofday计算时间](https://blog.habets.se/2010/09/gettimeofday-should-never-be-used-to-measure-time.html)。 + + 也可使用field_stat2.h中提供的简单封装。 + +``` +struct timespec start; +record_time_start(&start); +//do something +long eplapses=record_time_elapse_us(&start); +FS_operate(fs_handle, histogram_id, 0, FS_OP_SET, eplapsed); +``` + + + ## 使用建议 ### 命名建议 @@ -132,8 +166,11 @@ line,app_name=APPNAME column1=value,column2=value 2. 除若干单词首字母组成的缩写外,不要大写。如Kernel Network Interface 可以缩写为KNI,packet缩写为pkt,而不是PKT 3. 一般不要超过10个字节,不然本地刷新不美观。 - htable->htab, read->rd,write->wr,send ->tx,receive->rx + - send packets,可缩写为tx_pkts,send bytes可缩写为tx_bytes + 禁止注册名称包含 `|:\n\r. \t<>[]#!@`的统计域。 + ### 显示字段数量 Status和Field每行固定展示8个统计值。Column和Histogram取决于注册数量,建议Column一般不超过8个,Histogram的bins不超过5个。 @@ -144,16 +181,3 @@ line,app_name=APPNAME column1=value,column2=value 在shell执行`watch -d cat 日志文件`,观察实时的输出结果。 -### 记录事件耗时 - - 应使用clock_gettime函数获得事件的耗时,[永远不要用gettimeofday计算时间](https://blog.habets.se/2010/09/gettimeofday-should-never-be-used-to-measure-time.html)。 - - 也可使用field_stat2.h中提供的简单封装。 - -``` -struct timespec start; -record_time_start(&start); -//do something -long eplapses=record_time_elapse_us(&start); -``` - |
