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;

描述

The posix_trace_create_withlog subroutine creates an active trace stream, as the posix_trace_create subroutine does, and associates the stream with a trace log.

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_rewind posix_trace_close子程序,不能使用 "posix_trace_create_withlog子程序返回的跟踪流标识符调用。

对于带日志的活动跟踪流,当调用 posix_trace_shutdown子程序时,所有尚未刷新到跟踪日志的跟踪事件都会被刷新,就像在 "posix_trace_flush子程序中一样,跟踪日志也会被关闭。

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

如果调用 "posix_trace_create_withlog子程序时使用了一个未初始化的属性对象作为参数,则不会指定结果。

参数

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

返回值

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

错误

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

文件

文件参考中的trace.htypes.h文件