当前位置:科学 > 正文

当前速看:使用lttng的TRACEPOINT CLASS

2023-06-23 14:00:06  来源:不倒翁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的写法

关键词:

推荐阅读

域名抢注是是什么意思?投资角度来看什么域名好?

域名抢注是是什么意思域名抢注是通过抢先注册的方式获得互联网删除的域名的使用权。域名是由点分隔的一串数字,用于标记一台计算机或一组计 【详细】

捷达保养费用是多少?捷达是哪个国家的品牌?

捷达保养费用是多少?全新捷达的保修期为2年或6万公里,以先到者为准,新车可享受一次免费保养,首次免费保养在5000-7500km或1年内进行。如 【详细】

天然气泄露会造成爆炸吗?天然气泄漏怎么办?

天然气泄露会造成爆炸吗?家里用的天然气如果泄露是会发生爆炸的。当空气中含有混合天然气时,在与火源接触的一系列爆炸危险中,就会发生爆 【详细】

四部门明确App收集个人信息范围 个人信息保护范围判断标准

四部门明确App收集个人信息范围近日,国家互联网信息办公室、工业和信息化部、公安部、国家市场监督管理总局联合印发《常见类型移动互联网 【详细】

丰田致炫介绍 致炫威驰对比汇总

丰田致炫介绍参考价格: 6 88ー10 28W,基本参数: 1 3升 1 5升 5mt,5 3升 100公里。YARiS L致炫是YARiS L的替代传统车型,也是我们中国 【详细】

相关新闻

关于我们  |  联系方式  |  免责条款  |  招聘信息  |  广告服务  |  帮助中心

联系我们:85 572 98@qq.com备案号:粤ICP备18023326号-40

科技资讯网 版权所有