posix_trace_create_withlog 子例程

用途

创建活动跟踪流并将其与跟踪日志相关联。

Posix 跟踪库 (libposixtrace.a)

语法

#include <sys/types.h>
#include <trace.h>

int posix_trace_create_withlog (pid, attr, file_desc, trid)
pid_t pid;
const trace_attr_t *restrict attr;
int file_desc;
trace_id_t *restrict trid;

描述

posix_trace_create_withlog 子例程会像 posix_trace_create 子例程一样创建活动跟踪流,并将该流与跟踪日志相关联。

file_desc 参数必须是指定跟踪日志目标的文件描述符。 如果此文件描述符引用了使用 O_APPEND 标志打开的文件,或者此文件描述符引用了非常规文件,那么子例程将失败。

trid 参数指向 posix_trace_create_withlog 子例程返回跟踪流标识的参数,该标识唯一地标识新创建的跟踪流。 可以在后续调用中使用跟踪流标识来控制跟踪。 trid 参数仅由以下子例程使用:
  • posix_trace_clear
  • posix_trace_eventid_equal
  • posix_trace_eventid_get_name
  • posix_trace_eventtypelist_getnext_id
  • posix_trace_eventtypelist_rewind
  • posix_trace_flush
  • posix_trace_get_attr
  • posix_trace_get_filter
  • posix_trace_get_status
  • posix_trace_set_filter
  • posix_trace_shutdown
  • posix_trace_start
  • posix_trace_stop
  • posix_trace_trid_eventid_open
请注意,无法使用 posix_trace_create_withlog 子例程返回的跟踪流标识来调用跟踪分析器进程 (例如 posix_trace_rewind posix_trace_close 子例程) 所使用的操作。

对于具有日志的活动跟踪流,当调用 posix_trace_shutdown 子例程时,将像 posix_trace_flush 子例程一样清空所有尚未清空到跟踪日志的跟踪事件,并且将关闭跟踪日志。

当跟踪日志关闭时,以后可以通过跟踪接口从跟踪日志中检索的所有信息都将写入跟踪日志。 此信息包括跟踪属性,跟踪事件类型列表 (带有跟踪事件名称和跟踪事件类型标识之间的映射) 以及跟踪状态。

如果使用未初始化的属性对象作为参数来调用 posix_trace_create_withlog 子例程,那么不会指定结果。

参数

表 1. 参数
描述
pid 指定跟踪进程的进程标识。
attr 指定跟踪属性对象。
文件描述 指定跟踪日志的打开文件描述符。
叛徒 指定跟踪流标识。

返回值

成功完成时,此子例程返回值零,并将跟踪流标识值存储在 trid 参数指向的对象中。 否则,将返回相应的错误号。

错误

表 2。 错误
描述
EAGAIN 现在无法启动更多跟踪流。 已超过 TRACE_SYS_MAX 的值。
EBADF file_desc 参数不是打开用于写入的有效文件描述符。
EINVAL attr 参数为空或其他参数无效。 file_desc 参数引用文件类型不支持与跟踪日志关联的日志策略的文件。
ENOMEM 没有足够的内存来创建具有指定参数的跟踪流。
ENOSPC 设备上没有剩余空间。 对应于 file_desc 参数的设备不包含创建此跟踪日志所需的空间。
EPERM 没有适当的特权来跟踪由 pid 参数指定的进程。
ESRCH pid 参数不引用现有进程。

文件

Files Reference 中的 trace.htypes.h 文件