posix_trace_create 子例程

用途

创建活动跟踪流。

Posix 跟踪库 (libposixtrace.a)

语法

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

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

描述

posix_trace_create 子例程创建活动跟踪流。 它根据 attr 参数分配正在创建的跟踪流所需的所有资源,以跟踪由 pid 参数指定的进程。

attr 参数表示跟踪流的初始属性,在调用 posix_trace_create 子例程之前,必须由 posix_trace_attr_init 子例程进行初始化。 如果 attr 参数为 NULL ,那么将使用缺省属性。

可以通过 posix_trace_attr 子例程系列中描述的一组子例程来处理 attr 属性对象。 如果稍后修改 attr 参数指向的对象的属性,那么不会影响跟踪流的属性。

新创建的跟踪流的创建时间属性设置为 CLOCK_REALTIME 时钟的值。

pid 参数表示要跟踪的目标进程。 如果 pid 参数为零,那么将跟踪调用进程。 如果执行此子例程的进程没有适当的特权来跟踪由 pid标识的进程,那么将返回错误。

posix_trace_create 子例程将新跟踪流的跟踪流标识存储在 trid 参数指向的对象中。 可以在后续调用中使用此跟踪流标识来控制跟踪。 trid 参数仅由以下子例程使用:
  • posix_trace_clear
  • posix_trace_eventid_equal
  • posix_trace_eventid_get_name
  • posix_trace_eventtypelist_getnext_id
  • posix_trace_eventtypelist_rewind
  • 实数 (posix_trace_get_attr)
  • posix_trace_get_filter
  • posix_trace_get_status
  • posix_trace_getnext_event
  • posix_trace_set_filter
  • posix_trace_shutdown
  • posix_trace_start
  • posix_trace_stop
  • posix_trace_timedgetnext_event
  • posix_trace_trid_eventid_open
  • posix_trace_trygetnext_event
请注意,不能使用 posix_trace_create 子例程返回的跟踪流标识来调用通常由跟踪分析器进程 (例如 posix_trace_rewindposix_trace_close 子例程) 使用的操作。

使用空的跟踪事件类型过滤器以暂挂状态创建跟踪流。

可以从相同或不同进程多次调用 posix_trace_create 子例程,其系统范围限制由运行时不变量值 TRACE_SYS_MAX指示,该值的最小值为 _POSIX_TRACE_SYS_MAX

posix_trace_create 子例程在 trid 参数所指向的参数中返回的跟踪流标识仅在进行子例程调用的进程中有效。 如果在 IEEE 标准 1003.1-2001中定义的子例程中从另一个进程 (即子进程) 使用此子进程,那么这些子例程将返回 EINVAL 错误。

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

参数

描述
pid 指定被跟踪进程的进程标识。
属性 指定跟踪属性对象。
trid 指定跟踪流标识。

返回值

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

错误

描述
EAGAIN 现在无法启动更多跟踪流。 已超过 TRACE_SYS_MAX 的值。
EINVAL attr 参数为空或其他参数无效。
ENOMEM 没有足够的内存来创建具有指定参数的跟踪流。
EPERM 没有适当的特权来跟踪由 pid 参数指定的进程。
ESRCH pid 参数不引用现有进程。

文件

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