当前位置:科学 > 正文
当前速看:使用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的替代传统车型,也是我们中国 【详细】
相关新闻
- 当前速看:使用lttng的TRACEPOINT CLASS
- 每日看点!极难降解,一旦进入血液长久积存…化工巨头因污染环境赔钱:高达740亿元!
- 环球热推荐:WPS布局AI大模型,恐难为其商业化加分
- 三星Galaxy Z Fold5海报亮相,屏幕收窄,缝隙消失
- lol 可用符号大全(lol符号大全可以用的)_环球精选
- 低压为什么会高(血压高压正常低压高是怎么回事)
- 锋兰达油耗_老款伊兰特油耗 世界观速讯
- 蓝山县压实防汛抗灾和燃气安全责任 今日关注
- 超氢打印机,宜商宜家超氢便携 环球关注
- 厚6.81mm成千元机天花板!8+256G仅1219元,小米11青春版加速清货
- 中国在喜马拉雅山发现千公里稀土矿带,人工智能如何助力开采?-今日精选
- 一双aj大约多少钱_aj一双价格多少钱
- 每日看点!口炎清颗粒主治什么(苏子降气丸,清金开音片,口炎清颗粒,这几种药合起来有什么作用?)
- 沪上古风端午节引关注 在玉佛禅寺沉浸式体验传统文化-天天时快讯
- 充电桩股有哪些股票龙头_关注这三只充电桩龙头股
- 环球要闻:大摩:予太平洋航运“增持”评级 下调目标价至3.25港元
- languagemodels:512MB内存运行大模型,可以用来做开发测试用
- 当前动态:中国“重器”,亮相巴黎!
- OpenLLM:最简单把各热门大语言模型部署到我们云端或本地服务器
- 全球即时:国家电网首次采用X射线检测作业 有效保障京津冀地区电力供应