linux/tools/perf/trace/beauty/socket_type.c
<<
>>
Prefs
   1#include <sys/types.h>
   2#include <sys/socket.h>
   3
   4#ifndef SOCK_DCCP
   5# define SOCK_DCCP              6
   6#endif
   7
   8#ifndef SOCK_CLOEXEC
   9# define SOCK_CLOEXEC           02000000
  10#endif
  11
  12#ifndef SOCK_NONBLOCK
  13# define SOCK_NONBLOCK          00004000
  14#endif
  15
  16#ifndef SOCK_TYPE_MASK
  17#define SOCK_TYPE_MASK 0xf
  18#endif
  19
  20static size_t syscall_arg__scnprintf_socket_type(char *bf, size_t size, struct syscall_arg *arg)
  21{
  22        size_t printed;
  23        int type = arg->val,
  24            flags = type & ~SOCK_TYPE_MASK;
  25
  26        type &= SOCK_TYPE_MASK;
  27        /*
  28         * Can't use a strarray, MIPS may override for ABI reasons.
  29         */
  30        switch (type) {
  31#define P_SK_TYPE(n) case SOCK_##n: printed = scnprintf(bf, size, #n); break;
  32        P_SK_TYPE(STREAM);
  33        P_SK_TYPE(DGRAM);
  34        P_SK_TYPE(RAW);
  35        P_SK_TYPE(RDM);
  36        P_SK_TYPE(SEQPACKET);
  37        P_SK_TYPE(DCCP);
  38        P_SK_TYPE(PACKET);
  39#undef P_SK_TYPE
  40        default:
  41                printed = scnprintf(bf, size, "%#x", type);
  42        }
  43
  44#define P_SK_FLAG(n) \
  45        if (flags & SOCK_##n) { \
  46                printed += scnprintf(bf + printed, size - printed, "|%s", #n); \
  47                flags &= ~SOCK_##n; \
  48        }
  49
  50        P_SK_FLAG(CLOEXEC);
  51        P_SK_FLAG(NONBLOCK);
  52#undef P_SK_FLAG
  53
  54        if (flags)
  55                printed += scnprintf(bf + printed, size - printed, "|%#x", flags);
  56
  57        return printed;
  58}
  59
  60#define SCA_SK_TYPE syscall_arg__scnprintf_socket_type
  61