ceph perf counter 源码分析及使用
来源:互联网 发布:诺基亚s60软件下载 编辑:程序博客网 时间:2024/06/05 02:08
ceph perf counter 源码分析及使用
示例
1 enum {2 test_perfcounter_first = 200,3 test_perfcounter_count,4 test_perfcounter_time,5 test_perfcounter_sum,6 test_perfcounter_last,7 };89 PerfCountersCollection *coll = g_ceph_context->get_perfcounters_collection();1011 PerfCountersBuilder test_plb(g_ceph_context, "test_perfcounter", test_perfcounter_first, test_perfcounter_last);1213 test_plb.add_u64_counter(test_perfcounter_count, "test_count");14 test_plb.add_time(test_perfcounter_time, "test_time", "Time of system service");15 test_plb.add_u64(test_perfcounter_sum, "test_sum", "Sum of variable", "wr_bytes_sum");1617 test_logger = test_plb.create_perf_counters();1819 coll->add(test_plb);2021 test_logger->set(test_perfcounter_count, 1);22 test_logger->tset(test_perfcounter_time, utime_t(0, 1));23 test_logger->set(test_perfcounter_sum, 1);2425 test_logger->inc(test_perfcounter_count);26 test_logger->tinc(test_perfcounter_time, utime_t());27 test_logger->inc(test_percounter_sum, 10);2829 test_logger->dec(test_perfcounter_count);30 test_logger->dec(test_perfcounter_sum, 5);3132 test_logger->reset();3334 coll->reset(string("test_perfcounter"));35 coll->reset(string("all"));36 coll->remove(test_logger);37 coll->clear();
分析
1-7: 定义一个枚举型,在使用perf counter的时候,每一个couter会有一个data size,也就是有多少个perf counter对象,所以都会定义一个enum,enum的第一个和最后一个元素是必须要有的(也就是first和last),然后我们要计算perf的指标都定义在这两个enum元素之间就OK。
9: 定义了一个PerfCounterCollection对象,该类中有perf_counters_set_t m_loggers成员变量,该类是多个PerfCounter子模块的集合,所有的Perf counter模块都在这个集合中。
11: 定义了一个PerfCountersBuilder对象,该类中有PerfCounters *m_perf_counters成员变量。
m_perf_counters变量在实例化类的时候,通过类的构造函数初始化了,初始化:new PerfCounters(cct, name, first, last),实例化一个PerfCounters对象。
PerfCounters类中有perf_counter_data_vec_t m_data及int m_lower_bound, int m_upper_bound, string m_name;
PerfCounters类的构造函数:PerfCounters::PerfCounters(CephContext *cct, const std::string &name, int lower_bound, int upper_bound),构造函数的参数中的name是计算perf子模块的名称, 在这里就是”test_perfcounter”, lower_bound和high_bound是我们要跟踪计算perf的子模块的上下界限,主要是为了调整m_data(是一个vector)的长度。
13-15:将具体的跟踪指标(test_perfcounter_count等)加入到跟踪子模块(test_perfcounter)中。
根据不同的指标的类型不同,调用的函数也不同,也是根据不同的类型来区分的。这些函数最后还是调用同样的函数:add_impl(idx, name, description, nick, PERFCOUNTER_U64);只是最后这个type参数不同。目前根据time、普通数值、计量值来区分,分别有add_time()、add_u64()、add_u64_counter().
add_impl(…)函数如下:
0 PerfCounters::perf_counter_data_vec_t &vec(m_perf_counters->m_data); 1 PerfCounters::perf_counter_data_any_d 2 &data(vec[idx - m_perf_counters->m_lower_bound - 1]); 3 assert(data.type == PERFCOUNTER_NONE); 4 data.name = name; 5 data.description = description; 6 data.nick = nick; 7 data.type = (enum perfcounter_type_d)ty;
0: 取m_data的值
1-2: 取m_data中的和具体的跟踪指标对应index的值
4-7: 给m_data对应的index位置赋值,从上层传下来的关于这个指标的信息,主要是index、指标名称、指标描述信息、指标的别名、指标类型
17: 返回一个完整perf counter的PerfCounter类型的m_perf_counters; 上面关于perf指标的操作都是为了创建一个完整的PerfCounter对象。
1 PerfCounters *PerfCountersBuilder::create_perf_counters() 2 { 3 PerfCounters::perf_counter_data_vec_t::const_iterator d = m_perf_counters->m_data.begin(); 4 PerfCounters::perf_counter_data_vec_t::const_iterator d_end = m_perf_counters->m_data.end(); 5 for (; d != d_end; ++d) { 6 if (d->type == PERFCOUNTER_NONE) { 7 assert(d->type != PERFCOUNTER_NONE); 8 } 9 }10 PerfCounters *ret = m_perf_counters;11 m_perf_counters = NULL;12 return ret;13 }
19: 将新的Perf Counter字模块加入Perf Counters集合中。
21-30: Perf具体的计算函数,包括set()、tset()、inc()、tinc()、dec()
这些函数都有一个参数: int idx, 就是前面我们定义的enum类型的具体指标。函数首字母是’t’的是关于time的处理。
set()/tset():设置一个值。
inc()/tinc(): 增加,如果给定了增加多少,就增加具体的值;如果没有指定增加多少,+1.
dec(): 减少,如果给定了减少的值,就减少多少;如果没有指定,-1
32: 将test_perfcounter子模块中的所有指标都清0
34-35: 在perf counter集合的层面上清空,其实内部最后还是调用的PerfCounter::reset(), 也就是32行的调用函数
PerfCounterCollection::reset(string name)函数中的参数如果是”all”的话,perf集合会遍历所有的perf counter,依次调用reset();
参数可以是具体的perf counter子模块名,就只清空该模块, 比如reset(“test_perfcounter”)
36: 从perf counter集合中删除某个子perf counter模块
37: 从perf counter集合中删除所有的perf counter模块
参考
ceph源代码: test/perf_counters.cc
- ceph perf counter 源码分析及使用
- 使用systemtap分析ceph源码流程
- Hadoop源码分析[5]-counter的使用和默认counter的含义
- ceph存储 ceph-fuse源码分析一
- ceph 中的performance counter
- ceph源码分析: Log实现
- Ceph Crush 算法源码分析
- 《ceph源码分析》 学习笔记
- 使用 Counter Analyzer 进行 Performance Monitor Counter 数据分析
- 性能分析工具perf的使用
- [Ceph分析]源码目录结构分析
- Perf使用
- ceph存储 ceph的CRUSH算法的源码分析
- Ceph 学习——CRUSH算法及源码分析(一)
- Ceph 学习——CRUSH算法及源码分析(二)
- Ceph架构介绍及使用
- ceph的CRUSH算法的源码分析
- ceph源码分析之线程介绍
- Lua编程中遇到的table类型传递引用问题
- DOM节点删除之detach()和remove()区别
- SpringBoot加https的配置
- 客户端(android/ios)与java服务端tomcat的gzip实现
- 回溯算法解八皇后问题(java版)
- ceph perf counter 源码分析及使用
- 利用游标更新字段值
- oracle 线上环境创建用户、表空间、授权
- 在Spring Boot框架下使用WebSocket实现聊天功能
- BZOJ2160 拉拉队排练 解题报告【字符串】【Manacher】【差分】
- hdu 2119 最小顶点能覆盖
- 首博
- html video 视频的播放与暂停
- 文件操作工具类