c 语言使用lttng

以下内容来自lttng 官方文档,主要是学习记录

创建tracepoint

  • hello-tp.h
#undef TRACEPOINT_PROVIDER
#define TRACEPOINT_PROVIDER hello_world
#undef TRACEPOINT_INCLUDE
#define TRACEPOINT_INCLUDE "./hello-tp.h"
#if !defined(_HELLO_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
#define _HELLO_TP_H
#include <lttng/tracepoint.h>
TRACEPOINT_EVENT(
    hello_world,
    my_first_tracepoint,
    TP_ARGS(
        int, my_integer_arg,
        char*, my_string_arg
    ),
    TP_FIELDS(
        ctf_string(my_string_field, my_string_arg)
        ctf_integer(int, my_integer_field, my_integer_arg)
    )
)
#endif /* _HELLO_TP_H */
#include <lttng/tracepoint-event.h>
 
  • hello-tp.c
#define TRACEPOINT_CREATE_PROBES
#define TRACEPOINT_DEFINE
#include "hello-tp.h"
  • 构建
gcc -c -I. hello-tp.c
  • c 应用
    hello.c
#include <stdio.h>
#include "hello-tp.h"
int main(int argc, char *argv[])
{
    int x;
    puts("Hello, World!\nPress Enter to continue...");
    /*
     * The following getchar() call is only placed here for the purpose
     * of this demonstration, to pause the application in order for
     * you to have time to list its tracepoints. It's not needed
     * otherwise.
     */
    getchar();
    /*
     * A tracepoint() call.
     *
     * Arguments, as defined in hello-tp.h:
     *
     * 1. Tracepoint provider name   (required)
     * 2. Tracepoint name            (required)
     * 3. my_integer_arg             (first user-defined argument)
     * 4. my_string_arg              (second user-defined argument)
     *
     * Notice the tracepoint provider and tracepoint names are
     * NOT strings: they are in fact parts of variables that the
     * macros in hello-tp.h create.
     */
    tracepoint(hello_world, my_first_tracepoint, 23, "hi there!");
    for (x = 0; x < argc; ++x) {
        tracepoint(hello_world, my_first_tracepoint, x, argv[x]);
    }
    puts("Quitting now!");
    tracepoint(hello_world, my_first_tracepoint, x * x, "x^2");
    return 0;
}
 
  • 构建
gcc -c hello.c 
  • 链接应用
gcc -o hello hello.o hello-tp.o -llttng-ust -ldl
  • 构建流程

 

 

 

追踪应用

  • 启动应用
./hello world and beyond
  • 启动 session daemon
lttng-sessiond --daemonize
  • 查看tracepoint
lttng list --userspace
  • 创建会话
lttng create my-user-space-session
  • 创建event规则
lttng enable-event --userspace hello_world:my_first_tracepoint
  • 启动
lttng start
  • 操作
    输入enter,停止应用
  • 停止追踪
 
lttng destroy
  • 查看
babeltrace ~/lttng-traces/my-user-space-session*
  • 效果

 

 

说明

对于构建我们需要安装devel包,这个通过efficios提供的yum包就包含了

参考资料

https://lttng.org/docs/v2.12/#doc-tracing-your-own-user-application

posted on   荣锋亮  阅读(539)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-05-17 edgedb-js 来自官方的js 驱动
2019-05-17 edgedb 开发环境运行

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示