[LTTng学习之旅]------Components of LTTng 解构

25 篇文章 6 订阅

LTTng是想干大事的,是想玩生态的。
可惜十几年了 还是没有被Linux主线合并
况且现在eBPF已成燎原之势

Control and trace data paths between LTTng components.
在这里插入图片描述

The LTTng project integrates:

  • LTTng-tools

Libraries and command-line interface to control recording sessions:

Session daemon (lttng-sessiond(8)).

Consumer daemon (lttng-consumerd).

Relay daemon (lttng-relayd(8)).这个是前面说的远程Trace中继

Tracing control library (liblttng-ctl).

Tracing control command-line tool (lttng(1)).

lttng-crash command-line tool (lttng-crash(1)).

  • LTTng-UST

Libraries and Java/Python packages to instrument and trace user applications:

User space tracing library (liblttng-ust) and its headers to instrument and trace any native user application.

Preloadable user space tracing helpers:

liblttng-ust-libc-wrapper

liblttng-ust-pthread-wrapper

liblttng-ust-cyg-profile

liblttng-ust-cyg-profile-fast

liblttng-ust-dl

  • LTTng-modules

Linux kernel modules to instrument and trace the kernel:

LTTng kernel tracer module.

Recording ring buffer kernel modules.

Probe kernel modules.

LTTng logger kernel module.

Tracing control command-line interface

The lttng(1) command-line tool is the standard user interface to control LTTng recording sessions.

The lttng tool is part of LTTng-tools.

The lttng tool is linked with liblttng-ctl to communicate with one or more session daemons behind the scenes.

背后是通过这个服务和守护进程通讯

The lttng tool has a Git-like interface:

lttng [GENERAL OPTIONS] [COMMAND OPTIONS]

Tracing control library

在这里插入图片描述
Use liblttng-ctl in C or C++ source code by including its “master” header:

#include <lttng/lttng.h>

As of LTTng 2.13, the best available developer documentation for liblttng-ctl is its installed header files. Functions and structures are documented with header comments.

这个文件我在 /usr/local/include/lttng 下面找到了

User space tracing library

在这里插入图片描述
The user space tracing library, liblttng-ust (see lttng-ust(3)), is the LTTng user space tracer.
==库 ==
liblttng-ust receives commands from a session daemon, for example to allow specific instrumentation points to emit LTTng events, and writes event records to ring buffers shared with a consumer daemon.

liblttng-ust is part of LTTng-UST.

liblttng-ust can also send asynchronous messages to the session daemon when it emits an event. This supports the “event rule matches” trigger condition feature (see “Add an “event rule matches” trigger to a session daemon”).

Public C header files are installed beside liblttng-ust to instrument any C or C++ application.
这是说 的写代码的时候,引用这个头文件来打桩是吗
LTTng-UST agents, which are regular Java and Python packages, use their own tracepoint provider package which is linked with liblttng-ust.

An application or library doesn’t have to initialize liblttng-ust manually: its constructor does the necessary tasks to register the application to a session daemon. The initialization phase also configures instrumentation points depending on the event rules that you already created.
构造函数自动初始化

User space tracing agents

Java和Python的。先跳过。

LTTng kernel modules

在这里插入图片描述

The LTTng kernel modules are a set of Linux kernel modules which implement the kernel tracer of the LTTng project.

The LTTng kernel modules are part of LTTng-modules.

The LTTng kernel modules include:

A set of probe modules.

Each module attaches to a specific subsystem of the Linux kernel using its tracepoint instrument points.
加载的内核模块attach到对应的内核子系统上,来利用他们的tracepoint代码
There are also modules to attach to the entry and return points of the Linux system call functions.
当然也attach到 systemcall 的出入口。说起来,system call的出入口 也是被各种疯狂使用啊
Ring buffer modules.

A ring buffer implementation is provided as kernel modules. The LTTng kernel tracer writes to ring buffers; a consumer daemon reads from ring buffers.

The LTTng kernel tracer module.

The LTTng logger module.

The LTTng logger module implements the special /proc/lttng-logger (and /dev/lttng-logger, since LTTng 2.11) files so that any executable can generate LTTng events by opening those files and writing to them.
这个类似虚拟文件系统的概念了吧 来操作寻设备和文件 实现交互。 Linux老套路了

The LTTng kernel tracer can also send asynchronous messages to the session daemon when it emits an event. This supports the “event rule matches” trigger condition feature (see “Add an “event rule matches” trigger to a session daemon”).
满足条件了发异步消息
Generally**, you don’t have to load the LTTng kernel modules manually** (using modprobe(8), for example): a root session daemon loads the necessary modules when starting. If you have extra probe modules, you can specify to load them to the session daemon on the command line (see the --extra-kmod-probes option).
不需要手动加载中内核模块
The LTTng kernel modules are installed in /usr/lib/modules/release/extra by default, where release is the kernel release (output of uname --kernel-release).

Session daemon

在这里插入图片描述
The session daemon, lttng-sessiond(8), is a daemon which:

核心管理守护进程了属于是

  • Manages recording sessions.
  • Controls the various components (like tracers and consumer daemons)
    of LTTng.
  • Sends asynchronous notifications to user applications.

The session daemon is part of LTTng-tools.

The session daemon sends control requests to and receives control responses from:

  • The user space tracing library.

    Any instance of the user space tracing library first registers to a
    session daemon. Then, the session daemon can send requests to this
    instance, such as:
    实例化了user space 库的APP来找session daemon注册,上报 信息和接受下发的策略和信息
    1、Get the list of tracepoints.

    2、Share a recording event rule so that the user space tracing library
    can decide whether or not a given tracepoint can emit events. Amongst
    the possible conditions of a recording event rule is a filter
    expression which liblttng-ust evaluates before it emits an event.

    3、Share channel attributes and ring buffer locations.

    The session daemon and the user space tracing library use a Unix
    domain socket to communicate.

  • The user space tracing agents.
    这个说的是Java和Python的吧
    Any instance of a user space tracing agent first registers to a
    session daemon. Then, the session daemon can send requests to this
    instance, such as:

    1、Get the list of loggers.

    2、Enable or disable a specific logger.

    The session daemon and the user space tracing agent use a TCP
    connection to communicate.

  • The LTTng kernel tracer.
    加载的内核模块发来的

  • The consumer daemon.
    The session daemon sends requests to the consumer daemon to instruct it where to send the trace data streams, amongst other information.
    消费获得的Trace数据 ring buffer相关的

  • The relay daemon.
    数据类型转换?远程Trace中继?

The session daemon receives commands from the tracing control library.

The session daemon can receive asynchronous messages from the user space and kernel tracers when they emit events.
root seesion deamon的工作:
The root session daemon loads the appropriate LTTng kernel modules on startup. It also spawns one or more consumer daemons as soon as you create a recording event rule.

The session daemon doesn’t send and receive trace data: this is the role of the consumer daemon and relay daemon. It does, however, generate the CTF metadata stream.
独立性:
Each Unix user can have its own session daemon instance. The recording sessions which different session daemons manage are completely independent.

内核的归root管
The root user’s session daemon is the only one which is allowed to control the LTTng kernel tracer, and its spawned consumer daemon is the only one which is allowed to consume trace data from the LTTng kernel tracer.
Note, however, that any Unix user which is a member of the tracing group is allowed to create channels in the Linux kernel tracing domain, and therefore to use the Linux kernel LTTng tracer.普通用户被允许在内核域内创建channel,也没说数据让你看啊,那也得root来消费不是吗?

The lttng command-line tool automatically starts a session daemon when using its create command if none is currently running. You can also start the session daemon manually.
lttng create的时候 如果没有就自动建立一个daemon

Consumer daemon

在这里插入图片描述

The consumer daemon, lttng-consumerd, is a daemon which shares ring buffers with user applications or with the LTTng kernel modules to collect trace data and send it to some location (file system or to a relay daemon over the network).

The consumer daemon is part of LTTng-tools.
不需要手动建立,他是session deamon的子进程。建立 recording event rule 的时候,自动建立本deamon
You don’t start a consumer daemon manually: a consumer daemon is always spawned by a session daemon as soon as you create a recording event rule, that is, before you start recording. When you kill its owner session daemon, the consumer daemon also exits because it’s the child process of the session daemon. Command-line options of lttng-sessiond(8) target the consumer daemon process.

每个用户 session deamon和 consumer deamon的数量。root居然可以有三个
There are up to two running consumer daemons per Unix user, whereas only one session daemon can run per user. This is because each process can be either 32-bit or 64-bit: if the target system runs a mixture of 32-bit and 64-bit processes, it’s more efficient to have separate corresponding 32-bit and 64-bit consumer daemons. The root user is an exception: it can have up to three running consumer daemons: 32-bit and 64-bit instances for its user applications, and one more reserved for collecting kernel trace data.

Relay daemon

在这里插入图片描述
The relay daemon, lttng-relayd(8), is a daemon acting as a bridge between remote session and consumer daemons, local trace files, and a remote live trace reader.

The relay daemon is part of LTTng-tools.

The main purpose of the relay daemon is to implement a receiver of trace data over the network. This is useful when the target system doesn’t have much file system space to write trace files locally.

The relay daemon is also a server to which a live trace reader can connect. The live trace reader sends requests to the relay daemon to receive trace data as the target system records events. The communication protocol is named LTTng live; it’s used over TCP connections.

Note that you can start the relay daemon on the target system directly. This is the setup of choice when the use case is to view/analyze events as the target system records them without the need of a remote system.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小羊苏C

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值