Re: [lttng-dev] [PATCH lttng-modules v6 3/5] Extract the FDs and flags from poll and ppoll

2016-04-30 Thread Mathieu Desnoyers
- On Apr 29, 2016, at 6:53 PM, Julien Desfossez jdesfos...@efficios.com 
wrote:

> Instead of printing the pointer address of the poll set, extract all the
> FDs and flags from the poll set. For now, we only output the
> standardized set of events to limit the verbosity of the output, we also
> extract the raw value. When we switch to CTF2 we will be able to hide
> unset fields and then we will extract all the fields.
> 
> Here is an example of output with one FD:
> syscall_entry_poll: {
>  timeout_msecs = -1, nfds = 1, fds_length = 1,
>  fds = [
>[0] = { fd = 4, raw_events = 0x5, events = { POLLIN = 1, POLLPRI = 0,
>POLLOUT = 1, POLLERR = 0, POLLHUP = 0, padding = 0 } } ]
> }
> 
> syscall_exit_poll: {
>  ret = 1, nfds = 1, fds_length = 1,
>  fds = [ [0] = { fd = 4, raw_events = 0x4, events = { POLLIN = 0,
>  POLLPRI = 0, POLLOUT = 1, POLLERR = 0, POLLHUP = 0, padding = 0 } } ] }
> 
> Signed-off-by: Julien Desfossez 
> ---
> .../syscalls/headers/syscalls_pointers_override.h  | 254 +
> 1 file changed, 254 insertions(+)
> 
> diff --git a/instrumentation/syscalls/headers/syscalls_pointers_override.h
> b/instrumentation/syscalls/headers/syscalls_pointers_override.h
> index b9dd54a..11d5f3d 100644
> --- a/instrumentation/syscalls/headers/syscalls_pointers_override.h
> +++ b/instrumentation/syscalls/headers/syscalls_pointers_override.h
> @@ -301,4 +301,258 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(pselect6,
> )
> #endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) ||
> defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
> 
> +#ifndef ONCE_LTTNG_TRACE_POLL_H
> +#define ONCE_LTTNG_TRACE_POLL_H
> +
> +#define LTTNG_POLL_NRFLAGS (POLLNVAL + 1)
> +#define POLL_FLAGS_PADDING_SIZE (sizeof(uint8_t) * BITS_PER_BYTE) - \
> + ilog2(LTTNG_POLL_NRFLAGS - 1)
> +
> +/*
> + * Only extract the values specified by iBCS2 for now.
> + */
> +static struct lttng_event_field lttng_pollfd_flag_fields[] = {
> + [ilog2(POLLIN)] = {
> + .name = "POLLIN",
> + .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
> + },
> + [ilog2(POLLPRI)] = {
> + .name = "POLLPRI",
> + .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
> + },
> + [ilog2(POLLOUT)] = {
> + .name = "POLLOUT",
> + .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
> + },
> + [ilog2(POLLERR)] = {
> + .name = "POLLERR",
> + .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
> + },
> + [ilog2(POLLHUP)] = {
> + .name = "POLLHUP",
> + .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
> + },
> + [ilog2(POLLNVAL)] = {
> + .name = "POLLNVAL",
> + .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
> + },
> + [ilog2(LTTNG_POLL_NRFLAGS)] = {
> + .name = "padding",
> + .type = __type_integer(int, POLL_FLAGS_PADDING_SIZE, 1, 0,
> + __LITTLE_ENDIAN, 10, none),
> + },
> +};
> +
> +static struct lttng_event_field lttng_pollfd_fields[] = {
> + [0] = {
> + .name = "fd",
> + .type = __type_integer(int, 0, 0, 0, __BYTE_ORDER, 10, none),
> + },
> + [1] = {
> + .name = "raw_events",
> + .type = __type_integer(short, 0, 0, 0, __BYTE_ORDER, 16, none),
> + },
> + [2] = {
> + .name = "events",
> + .type = {
> + .atype = atype_struct,
> + .u._struct.nr_fields = 
> ARRAY_SIZE(lttng_pollfd_flag_fields),
> + .u._struct.fields = lttng_pollfd_flag_fields,
> + }
> + },
> +};
> +
> +static struct lttng_type lttng_pollfd_elem = {
> + .atype = atype_struct,
> + .u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_fields),
> + .u._struct.fields = lttng_pollfd_fields,
> +};
> +#endif /* ONCE_LTTNG_TRACE_POLL_H */
> +
> +#define LTTNG_SYSCALL_POLL_locvar\
> + unsigned int fds_length, fds_max_len, alloc_fds;\
> + struct pollfd *fds; \
> + uint8_t overflow;
> +
> +#define LTTNG_SYSCALL_POLL_code_pre  \
> + BUILD_BUG_ON(((ARRAY_SIZE(lttng_pollfd_flag_fields) - 1) +  
> \
> + POLL_FLAGS_PADDING_SIZE) != 
> \
> + sizeof(uint8_t) * BITS_PER_BYTE);   
> \
> + tp_locvar->fds = NULL;  
> \
> + tp_locvar->overflow = 0;
> \
> + 
> \
> + sc_in(  
> \
> + 

[lttng-dev] [PATCH lttng-modules v6 3/5] Extract the FDs and flags from poll and ppoll

2016-04-29 Thread Julien Desfossez
Instead of printing the pointer address of the poll set, extract all the
FDs and flags from the poll set. For now, we only output the
standardized set of events to limit the verbosity of the output, we also
extract the raw value. When we switch to CTF2 we will be able to hide
unset fields and then we will extract all the fields.

Here is an example of output with one FD:
syscall_entry_poll: {
  timeout_msecs = -1, nfds = 1, fds_length = 1,
  fds = [
[0] = { fd = 4, raw_events = 0x5, events = { POLLIN = 1, POLLPRI = 0,
POLLOUT = 1, POLLERR = 0, POLLHUP = 0, padding = 0 } } ]
}

syscall_exit_poll: {
  ret = 1, nfds = 1, fds_length = 1,
  fds = [ [0] = { fd = 4, raw_events = 0x4, events = { POLLIN = 0,
  POLLPRI = 0, POLLOUT = 1, POLLERR = 0, POLLHUP = 0, padding = 0 } } ] }

Signed-off-by: Julien Desfossez 
---
 .../syscalls/headers/syscalls_pointers_override.h  | 254 +
 1 file changed, 254 insertions(+)

diff --git a/instrumentation/syscalls/headers/syscalls_pointers_override.h 
b/instrumentation/syscalls/headers/syscalls_pointers_override.h
index b9dd54a..11d5f3d 100644
--- a/instrumentation/syscalls/headers/syscalls_pointers_override.h
+++ b/instrumentation/syscalls/headers/syscalls_pointers_override.h
@@ -301,4 +301,258 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(pselect6,
 )
 #endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || 
defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
 
+#ifndef ONCE_LTTNG_TRACE_POLL_H
+#define ONCE_LTTNG_TRACE_POLL_H
+
+#define LTTNG_POLL_NRFLAGS (POLLNVAL + 1)
+#define POLL_FLAGS_PADDING_SIZE (sizeof(uint8_t) * BITS_PER_BYTE) - \
+   ilog2(LTTNG_POLL_NRFLAGS - 1)
+
+/*
+ * Only extract the values specified by iBCS2 for now.
+ */
+static struct lttng_event_field lttng_pollfd_flag_fields[] = {
+   [ilog2(POLLIN)] = {
+   .name = "POLLIN",
+   .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+   },
+   [ilog2(POLLPRI)] = {
+   .name = "POLLPRI",
+   .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+   },
+   [ilog2(POLLOUT)] = {
+   .name = "POLLOUT",
+   .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+   },
+   [ilog2(POLLERR)] = {
+   .name = "POLLERR",
+   .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+   },
+   [ilog2(POLLHUP)] = {
+   .name = "POLLHUP",
+   .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+   },
+   [ilog2(POLLNVAL)] = {
+   .name = "POLLNVAL",
+   .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+   },
+   [ilog2(LTTNG_POLL_NRFLAGS)] = {
+   .name = "padding",
+   .type = __type_integer(int, POLL_FLAGS_PADDING_SIZE, 1, 0,
+   __LITTLE_ENDIAN, 10, none),
+   },
+};
+
+static struct lttng_event_field lttng_pollfd_fields[] = {
+   [0] = {
+   .name = "fd",
+   .type = __type_integer(int, 0, 0, 0, __BYTE_ORDER, 10, none),
+   },
+   [1] = {
+   .name = "raw_events",
+   .type = __type_integer(short, 0, 0, 0, __BYTE_ORDER, 16, none),
+   },
+   [2] = {
+   .name = "events",
+   .type = {
+   .atype = atype_struct,
+   .u._struct.nr_fields = 
ARRAY_SIZE(lttng_pollfd_flag_fields),
+   .u._struct.fields = lttng_pollfd_flag_fields,
+   }
+   },
+};
+
+static struct lttng_type lttng_pollfd_elem = {
+   .atype = atype_struct,
+   .u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_fields),
+   .u._struct.fields = lttng_pollfd_fields,
+};
+#endif /* ONCE_LTTNG_TRACE_POLL_H */
+
+#define LTTNG_SYSCALL_POLL_locvar  \
+   unsigned int fds_length, fds_max_len, alloc_fds;\
+   struct pollfd *fds; \
+   uint8_t overflow;
+
+#define LTTNG_SYSCALL_POLL_code_pre\
+   BUILD_BUG_ON(((ARRAY_SIZE(lttng_pollfd_flag_fields) - 1) +  
\
+   POLL_FLAGS_PADDING_SIZE) != 
\
+   sizeof(uint8_t) * BITS_PER_BYTE);   
\
+   tp_locvar->fds = NULL;  
\
+   tp_locvar->overflow = 0;
\
+   
\
+   sc_in(  
\
+   if (nfds * sizeof(struct pollfd) > PAGE_SIZE) { 
\
+   tp_locvar->fds_length = PAGE_SIZE / sizeof(struct 
pollfd);  \
+