[LTTng实操]------设计一套东西监控某周期运行用户程序的执行时间和周期----架构设计

25 篇文章 6 订阅

目录

架构图

我花几分钟 画了个很简陋的极不规范的架构图。

使用的绘图工具是draw.io 网页版。
在这里插入图片描述
如图可见,架构设计稳定性可拓展性极差。商用可能性基本没有。不过无所谓,毕竟是自己当作demo。用来练手。

用户程序观测点插入

参加我之前的博文:
链接: [LTTng学习之旅]------在用户程序中简单的添加一个trace点

我的目的只是简单的提取时间戳。

在trace log中,本身每一条log都是带有时间戳的。并且转换为了日历时间。所以需要思考一下有没有必要添加field。

另外,如果直接提取时间戳可行的话,可以考虑使用lttng_ust_tracef()或者lttng_ust_tracelog()来简化我的工作。避免自己写个Tracepoint provider。

毕竟我要做的事情,只是把工具链打通。目标很简单。

用于控制LTTng Trace 的应用程序开发

作为嵌入式设备的开发人员,老板可能无法忍受每次启动后接入ssh然后敲命令行。

当然可能另外一种可以使用的方案是shell编程。

但是我还是选择基于LTTng的库来进行一个应用程序开发、从效率的角度考虑可能也是有必要的。

目前这个我还没有做过,之后会再开一篇专门记录这方面的内容。

目前可以看到的资料:

Tracing control library

在这里插入图片描述
The LTTng control library, liblttng-ctl, is used to communicate with a session daemon using a C API that hides the underlying details of the protocol.

liblttng-ctl is part of LTTng-tools.

The lttng command-line tool is linked with liblttng-ctl.

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.

/*
 * lttng.h
 *
 * Linux Trace Toolkit Control Library Header File
 *
 * Copyright (C) 2011 EfficiOS Inc.
 *
 * SPDX-License-Identifier: LGPL-2.1-only
 *
 */

#ifndef LTTNG_H
#define LTTNG_H

/* Error codes that can be returned by API calls */
#include <lttng/lttng-error.h>

/* Include every LTTng ABI/API available. */
#include <lttng/action/action.h>
#include <lttng/action/list.h>
#include <lttng/action/notify.h>
#include <lttng/action/path.h>
#include <lttng/action/rate-policy.h>
#include <lttng/action/rotate-session.h>
#include <lttng/action/snapshot-session.h>
#include <lttng/action/start-session.h>
#include <lttng/action/stop-session.h>
#include <lttng/channel.h>
#include <lttng/clear-handle.h>
#include <lttng/clear.h>
#include <lttng/condition/buffer-usage.h>
#include <lttng/condition/condition.h>
#include <lttng/condition/evaluation.h>
#include <lttng/condition/event-rule-matches.h>
#include <lttng/condition/session-consumed-size.h>
#include <lttng/condition/session-rotation.h>
#include <lttng/constant.h>
#include <lttng/destruction-handle.h>
#include <lttng/domain.h>
#include <lttng/endpoint.h>
#include <lttng/error-query.h>
#include <lttng/event-expr.h>
#include <lttng/event-field-value.h>
#include <lttng/event-rule/event-rule.h>
#include <lttng/event-rule/log4j-logging.h>
#include <lttng/event-rule/jul-logging.h>
#include <lttng/event-rule/kernel-kprobe.h>
#include <lttng/event-rule/kernel-syscall.h>
#include <lttng/event-rule/python-logging.h>
#include <lttng/event-rule/kernel-tracepoint.h>
#include <lttng/event-rule/kernel-uprobe.h>
#include <lttng/event-rule/user-tracepoint.h>
#include <lttng/event.h>
#include <lttng/handle.h>
#include <lttng/health.h>
#include <lttng/kernel-probe.h>
#include <lttng/load.h>
#include <lttng/location.h>
#include <lttng/log-level-rule.h>
#include <lttng/lttng-error.h>
#include <lttng/lttng-export.h>
#include <lttng/notification/channel.h>
#include <lttng/notification/notification.h>
#include <lttng/rotation.h>
#include <lttng/save.h>
#include <lttng/session-descriptor.h>
#include <lttng/session.h>
#include <lttng/snapshot.h>
#include <lttng/tracker.h>
#include <lttng/trigger/trigger.h>
#include <lttng/userspace-probe.h>

#ifdef __cplusplus
extern "C" {
#endif

enum lttng_calibrate_type {
	LTTNG_CALIBRATE_FUNCTION              = 0,
};

/* Machine interface output type */
enum lttng_mi_output_type {
	LTTNG_MI_XML                          = 1 /* XML output */
};

#define LTTNG_CALIBRATE_PADDING1           16
struct lttng_calibrate {
	enum lttng_calibrate_type type;

	char padding[LTTNG_CALIBRATE_PADDING1];
};

/*
 * Check if a session daemon is alive.
 *
 * Return 1 if alive or 0 if not. On error, returns a negative negative LTTng
 * error code.
 */
LTTNG_EXPORT extern int lttng_session_daemon_alive(void);

/*
 * Set the tracing group for the *current* flow of execution.
 *
 * On success, returns 0 else a negative LTTng error code.
 */
LTTNG_EXPORT extern int lttng_set_tracing_group(const char *name);

/*
 * This call registers an "outside consumer" for a session and an lttng domain.
 * No consumer will be spawned and all fds/commands will go through the socket
 * path given (socket_path).
 *
 * NOTE that this is not recommended unless you absolutely know what you are
 * doing.
 *
 * Return 0 on success else a negative LTTng error code.
 */
LTTNG_EXPORT extern int lttng_register_consumer(struct lttng_handle *handle,
		const char *socket_path);

/*
 * Start tracing for *all* domain(s) in the session.
 *
 * Return 0 on success else a negative LTTng error code.
 */
LTTNG_EXPORT extern int lttng_start_tracing(const char *session_name);

/*
 * Stop tracing for *all* domain(s) in the session.
 *
 * This call will wait for data availability for each domain of the session so
 * this can take an abritrary amount of time. However, when returning you have
 * the guarantee that the data is ready to be read and analyze. Use the
 * _no_wait call below to avoid this behavior.
 *
 * The session_name can't be NULL.
 *
 * Return 0 on success else a negative LTTng error code.
 */
LTTNG_EXPORT extern int lttng_stop_tracing(const char *session_name);

/*
 * Behave exactly like lttng_stop_tracing but does not wait for data
 * availability.
 */
LTTNG_EXPORT extern int lttng_stop_tracing_no_wait(const char *session_name);

/*
 * Deprecated: As of LTTng 2.9, this function always returns
 * -LTTNG_ERR_UND.
 */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
LTTNG_EXPORT extern int lttng_calibrate(struct lttng_handle *handle,
		struct lttng_calibrate *calibrate);
#pragma GCC diagnostic pop

/*
 * Set URL for a consumer for a session and domain.
 *
 * Both data and control URL must be defined. If both URLs are the same, only
 * the control URL is used even for network streaming.
 *
 * Default port are 5342 and 5343 respectively for control and data which uses
 * the TCP protocol.
 *
 * URL format: proto://[HOST|IP][:PORT1[:PORT2]][/TRACE_PATH]
 *
 * Possible protocols are:
 * > file://...
 *   Local filesystem full path.
 *
 * > net[6]://...
 *   This will use the default network transport layer which is TCP for both
 *   control (PORT1) and data port (PORT2).
 *
 * > tcp[6]://...
 *   TCP only streaming. For this one, both data and control URL must be given.
 *
 * Return 0 on success else a negative LTTng error code.
 */
LTTNG_EXPORT extern int lttng_set_consumer_url(struct lttng_handle *handle,
		const char *control_url, const char *data_url);

/*
 * For a given session name, this call checks if the data is ready to be read
 * or is still being extracted by the consumer(s) (pending) hence not ready to
 * be used by any readers.
 *
 * Return 0 if there is _no_ data pending in the buffers thus having a
 * guarantee that the data can be read safely. Else, return 1 if there is still
 * traced data is pending. On error, a negative value is returned and readable
 * by lttng_strerror().
 */
LTTNG_EXPORT extern int lttng_data_pending(const char *session_name);

/*
 * Deprecated, replaced by lttng_regenerate_metadata.
 */
LTTNG_DEPRECATED("Use lttng_regenerate_metadata")
LTTNG_EXPORT extern int lttng_metadata_regenerate(const char *session_name);

/*
 * Trigger the regeneration of the metadata for a session.
 * The new metadata overwrite the previous one locally or remotely (through
 * the lttng-relayd). Only kernel, per-uid and non-live sessions are supported.
 * Return 0 on success, a negative LTTng error code on error.
 */
LTTNG_EXPORT extern int lttng_regenerate_metadata(const char *session_name);

/*
 * Trigger the regeneration of the statedump for a session. The new statedump
 * information is appended to the currently active trace, the session needs to
 * be active.
 *
 * Return 0 on success, a negative LTTng error code on error.
 */
LTTNG_EXPORT extern int lttng_regenerate_statedump(const char *session_name);

#ifdef __cplusplus
}
#endif

#endif /* LTTNG_H */

这里需要注意的是:本套库是用来和session守护进程交互的库,所以可能没有拉起守护进程的API。也就是说,lttng 守护进程需要另外拉起来。这个可能可以通过添加在启动脚本序列中来实现。后面是否会通过类似指令的create record session 的方式自动新建守护进程,再做实验。

编写Trace数据处理程序

参加之前的文章:

Graph应用程序构造:
[LTTng学习之旅]------Trace 数据提取和格式转换—Babeltrace 2 C 应用程序开发

需要自己定制plugins的内容,还需要进一步实验摸索。

LTTng trace control程序和Babeltrace解读程序交互

这个方面可能有很多路子来做。分开写通过进程间通信同步。或者直接写在同一个程序里也可以。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小羊苏C

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

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

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

打赏作者

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

抵扣说明:

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

余额充值