当前位置:网站首页>[LTTng学习之旅]------在用户程序中简单的添加一个trace点
[LTTng学习之旅]------在用户程序中简单的添加一个trace点
2022-07-22 10:54:00 【小羊苏C】
编写 trace provider
在头文件中定义tracepoint event.
#undef LTTNG_UST_TRACEPOINT_PROVIDER
#define LTTNG_UST_TRACEPOINT_PROVIDER provider_my
#undef LTTNG_UST_TRACEPOINT_INCLUDE
#define LTTNG_UST_TRACEPOINT_INCLUDE "./my_lttng_usr.h"
#if !defined(_MY_LTTNG_USR_H) || defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ)
#define _MY_LTTNG_USR_H
#include <lttng/tracepoint.h>
/* * Use LTTNG_UST_TRACEPOINT_EVENT(), LTTNG_UST_TRACEPOINT_EVENT_CLASS(), * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(), and * LTTNG_UST_TRACEPOINT_LOGLEVEL() here. */
LTTNG_UST_TRACEPOINT_EVENT(
/* Tracepoint provider name */
provider_my,
/* Tracepoint name */
enter_app,
/* Input arguments */
LTTNG_UST_TP_ARGS(
int, index,
double,start_time_record
),
/* Output event fields */
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(int,app_run_index,index)
lttng_ust_field_float(double, period_record, start_time_record)
)
)
#endif /* _MY_LTTNG_USR_H */
#include <lttng/tracepoint-event.h>
在C文件中简单包含头文件即可,如果使用多组tracepoint event。 可以在C 文件中包含多个头文件。
#define LTTNG_UST_TRACEPOINT_CREATE_PROBES
#include "my_lttng_usr.h"
编译为.o文件:
gcc -I. -c my_lttng_usr.c
在代码中包含tracepoint
#include<pthread.h>
#include<stdio.h>
#include<chrono>
#include <iostream>
#include<ratio>
#include<thread>
#define LTTNG_UST_TRACEPOINT_DEFINE
#include"my_lttng_usr.h"
using namespace std;
void my_print_thread(void){
}
int main(){
//get the start time
auto time_point_start = chrono::steady_clock::now();
cout<<"start--------"<<endl;
int i = 0;
auto last_time = time_point_start;
chrono::milliseconds ms10(10);
while(i<=100){
auto this_time = chrono::steady_clock::now();
chrono::duration<double,milli>init_spend_time= this_time-time_point_start;
chrono::duration<double,milli>period_spend_time=this_time-last_time;
last_time = this_time;
cout<<"run "<<i<<" times, now is"<<init_spend_time.count()<<"ms, period is "<<period_spend_time.count()<<"ms..."<<endl;
lttng_ust_tracepoint(provider_my,enter_app,i,period_spend_time.count());
i++;
if(i>50) i=1;
this_thread::sleep_until(this_time+ms10);
}
if(chrono::steady_clock::is_steady) cout<<"steady clock is steady"<<endl;
auto end_time_high = chrono::steady_clock::now()-time_point_start;
cout<<"total time spend:"<<chrono::duration_cast<chrono::nanoseconds>(end_time_high).count()<<endl;
cout<<"exit..."<<endl;
return 0;
}
app也编译成.o
g++ -lpthread -c multi.cpp
最后编译链接成app运行
g++ -o app multi.o my_lttng_usr.o -llttng-ust -ldl
边栏推荐
猜你喜欢
随机推荐
Multithread 01 -- create thread and thread state
NSSCTF-01-[SWPUCTF 2021 新生赛]gift_F12
浅谈 filter伪协议的特性
BUUCTF闯关日记--[MRCTF2020]Ez_bypass1
Using MySQL database in Django
postman接口测试
Set colSpan invalidation for TD of table
next中的样式写法
脚本执行方式
Bash基本功能—通配符和其他特殊符号
Pycharm settings
面向高性能计算场景的存储系统解决方案
多线程01--创建线程和线程状态
条件判断.
Desensitization of mobile phone, name and ID card information in the project in the log and response data
Multithreading 03 -- synchronized and lock escalation
selenium测试框架快速搭建(ui自动化测试)
微信小程序入门教程学习笔记
多线程03--synchronized和锁升级
Buuctf breakthrough diary -- [ciscn2019 North China division Day2 web1]hack world