使用lttng的TRACEPOINT CLASS
2023-06-23 13:56:42 来源: 不倒翁78232022
(资料图片)
接着上篇我们继续学习lttng的功能,本节我们来讲讲lttnp的class功能,废话不多说了,上代码。
[root@ceph-1 test3]# cat tp.h#undef TRACEPOINT_PROVIDER#define TRACEPOINT_PROVIDER self_lttng_ust#undef TRACEPOINT_INCLUDE#define TRACEPOINT_INCLUDE "tp.h"#if !defined(TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)#define TP_H#include <lttng/tracepoint.h>#include "my-struct.h"TRACEPOINT_EVENT(self_lttng_ust,main_tracepoint,TP_ARGS (int32_t, grade,const struct student *, student_info),TP_FIELDS (ctf_string(name, student_info->name)ctf_integer(int32_t, grade, grade)ctf_integer(int32_t, age, student_info->age)ctf_float(float, score, student_info->score)))TRACEPOINT_EVENT(self_lttng_ust,main_tracepoint2,TP_ARGS (int32_t, grade,const struct student *, student_info),TP_FIELDS (ctf_string(name, student_info->name)ctf_integer(int32_t, grade, grade)ctf_integer(int32_t, age, student_info->age)ctf_float(float, score, student_info->score)))TRACEPOINT_EVENT(self_lttng_ust,main_tracepoint3,TP_ARGS (int32_t, grade,const struct student *, student_info),TP_FIELDS (ctf_string(name, student_info->name)ctf_integer(int32_t, grade, grade)ctf_integer(int32_t, age, student_info->age)ctf_float(float, score, student_info->score)))#endif#include <lttng/tracepoint-event.h>
[root@ceph-1 test3]# cat my-struct.h#ifndef MY_STRUCT_H#define MY_STRUCT_H#include <stdint.h>struct student { int8_t name[32]; uint8_t age; float score;};#endif
[root@ceph-1 test3]# cat tp.c#define TRACEPOINT_CREATE_PROBES#define TRACEPOINT_DEFINE#include "tp.h"
[root@ceph-1 test3]# cat main.c#include <stdio.h>#include <stdlib.h>#include <stdint.h>#include <unistd.h>#include "tp.h"#include "my-struct.h"int main(int argc, char *argv[]){ struct student s = { .name = "sdc", .age = 18, .score = 123.5 }; int32_t grade = 1; while(1) {grade++;tracepoint(self_lttng_ust, main_tracepoint, grade, &s);tracepoint(self_lttng_ust, main_tracepoint2, grade, &s);tracepoint(self_lttng_ust, main_tracepoint3, grade, &s);sleep(1); } return 0;}
[root@ceph-1 test3]# cat CMakeLists.txtcmake_minimum_required(VERSION 3.12)project(self-ust)include_directories(${CMAKE_CURRENT_LIST_DIR})aux_source_directory(. SRC_FILES)add_executable(${PROJECT_NAME} ${SRC_FILES})target_link_libraries(${PROJECT_NAME} lttng-ust dl)
mkdir build;cmake ..make./self-ust[root@ceph-1 tracing]# lttng create my-user-space-sessionSession my-user-space-session created.Traces will be written in /root/lttng-traces/my-user-space-session-20230623-115058[root@ceph-1 tracing]# lttng enable-event --userspace self_lttng_ust:main_tracepoin*UST event self_lttng_ust:main_tracepoin* created in channel channel0[root@ceph-1 tracing]# lttng startTracing started for session my-user-space-session[root@ceph-1 tracing]# lttng stopWaiting for data availability.Tracing stopped for session my-user-space-session[root@ceph-1 tracing]# lttng destroySession my-user-space-session destroyedbabeltrace2 ~/lttng-traces/my-user-space-session*
我们可以将如上的重复代码进行合并,合并结果如下:
[root@ceph-1 build]# cat ../tp.h#undef TRACEPOINT_PROVIDER#define TRACEPOINT_PROVIDER self_lttng_ust#undef TRACEPOINT_INCLUDE#define TRACEPOINT_INCLUDE "tp.h"#if !defined(TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)#define TP_H#include <lttng/tracepoint.h>#include "my-struct.h"TRACEPOINT_EVENT_CLASS(self_lttng_ust,self_lttng_class,TP_ARGS (int32_t, grade,const struct student *, student_info),TP_FIELDS (ctf_string(name, student_info->name)ctf_integer(int32_t, grade, grade)ctf_integer(int32_t, age, student_info->age)ctf_float(float, score, student_info->score)))TRACEPOINT_EVENT_INSTANCE(self_lttng_ust,self_lttng_class,main_tracepoint,TP_ARGS (int32_t, grade,const struct student *, student_info))TRACEPOINT_EVENT_INSTANCE(self_lttng_ust,self_lttng_class,main_tracepoint2,TP_ARGS (int32_t, grade,const struct student *, student_info))TRACEPOINT_EVENT_INSTANCE(self_lttng_ust,self_lttng_class,main_tracepoint3,TP_ARGS (int32_t, grade,const struct student *, student_info))#endif#include <lttng/tracepoint-event.h>
mkdir build;cmake ..make./self-ust[root@ceph-1 tracing]# lttng create my-user-space-sessionSession my-user-space-session created.Traces will be written in /root/lttng-traces/my-user-space-session-20230623-115058[root@ceph-1 tracing]# lttng enable-event --userspace self_lttng_ust:main_tracepoin*UST event self_lttng_ust:main_tracepoin* created in channel channel0[root@ceph-1 tracing]# lttng startTracing started for session my-user-space-session[root@ceph-1 tracing]# lttng stopWaiting for data availability.Tracing stopped for session my-user-space-session[root@ceph-1 tracing]# lttng destroySession my-user-space-session destroyedbabeltrace2 ~/lttng-traces/my-user-space-session*
可以看到效果是一样的,就是简化了,tracepoint provider的写法
标签:
[责任编辑:]
猜你喜欢
- (2023-06-23)使用lttng的TRACEPOINT CLASS
- (2023-06-23)固定收益专题报告:价格维度下如何挖掘地产债 焦点简讯
- (2023-06-23)长江存储亲儿子!致态TiPlus7100 1TB固态全年新低389元
- (2023-06-23)天天时讯:旋极信息最新公告:终止向特定对象发行A股股票事项
- (2023-06-23)全球新动态:蒙古包蚊帐和方形蚊帐哪个好_2021蒙古包蚊帐十大品牌排行榜蒙古包蚊帐哪个牌子好
- (2023-06-23)俄罗斯称美正扩充驻叙兵力 想进一步破坏叙稳定?-微速讯
- (2023-06-23)马斯克隔空约架扎克伯格到八角笼中格斗,UFC对举办这场比赛“垂涎欲滴”|世界时讯