X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fadd_context.cpp;h=076fa83a44a69b717f3fad2f719bcec8861f0559;hp=d078471d3d784ca88e041bddf96b5c2acc95b8c3;hb=HEAD;hpb=f895927f329180ca1e6f4426e9d3c6250ae698ba diff --git a/src/bin/lttng/commands/add_context.cpp b/src/bin/lttng/commands/add_context.cpp index d078471d3..3a0613bd0 100644 --- a/src/bin/lttng/commands/add_context.cpp +++ b/src/bin/lttng/commands/add_context.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 EfficiOS Inc. * Copyright (C) 2016 Jérémie Galarneau * * SPDX-License-Identifier: GPL-2.0-only @@ -7,6 +7,12 @@ */ #define _LGPL_SOURCE +#include "../command.hpp" + +#include + +#include + #include #include #include @@ -15,14 +21,8 @@ #include #include #include - #include -#include -#include - -#include "../command.h" - static char *opt_channel_name; static char *opt_session_name; static int opt_kernel; @@ -34,7 +34,7 @@ static char *opt_type; #ifdef LTTNG_EMBED_HELP static const char help_msg[] = #include -; + ; #endif enum { @@ -51,51 +51,52 @@ static struct lttng_handle *handle; static struct mi_writer *writer; /* - * Taken from the LTTng ABI + * Taken from the LTTng ABI except for "UNKNOWN". */ enum context_type { - CONTEXT_PID = 0, - CONTEXT_PERF_COUNTER = 1, /* Backward compat. */ - CONTEXT_PROCNAME = 2, - CONTEXT_PRIO = 3, - CONTEXT_NICE = 4, - CONTEXT_VPID = 5, - CONTEXT_TID = 6, - CONTEXT_VTID = 7, - CONTEXT_PPID = 8, - CONTEXT_VPPID = 9, - CONTEXT_PTHREAD_ID = 10, - CONTEXT_HOSTNAME = 11, - CONTEXT_IP = 12, + CONTEXT_UNKNOWN = -1, + CONTEXT_PID = 0, + CONTEXT_PERF_COUNTER = 1, /* Backward compat. */ + CONTEXT_PROCNAME = 2, + CONTEXT_PRIO = 3, + CONTEXT_NICE = 4, + CONTEXT_VPID = 5, + CONTEXT_TID = 6, + CONTEXT_VTID = 7, + CONTEXT_PPID = 8, + CONTEXT_VPPID = 9, + CONTEXT_PTHREAD_ID = 10, + CONTEXT_HOSTNAME = 11, + CONTEXT_IP = 12, CONTEXT_PERF_CPU_COUNTER = 13, CONTEXT_PERF_THREAD_COUNTER = 14, - CONTEXT_APP_CONTEXT = 15, + CONTEXT_APP_CONTEXT = 15, CONTEXT_INTERRUPTIBLE = 16, - CONTEXT_PREEMPTIBLE = 17, + CONTEXT_PREEMPTIBLE = 17, CONTEXT_NEED_RESCHEDULE = 18, - CONTEXT_MIGRATABLE = 19, + CONTEXT_MIGRATABLE = 19, CONTEXT_CALLSTACK_KERNEL = 20, CONTEXT_CALLSTACK_USER = 21, - CONTEXT_CGROUP_NS = 22, - CONTEXT_IPC_NS = 23, - CONTEXT_MNT_NS = 24, - CONTEXT_NET_NS = 25, - CONTEXT_PID_NS = 26, - CONTEXT_USER_NS = 27, - CONTEXT_UTS_NS = 28, - CONTEXT_UID = 29, - CONTEXT_EUID = 30, - CONTEXT_SUID = 31, - CONTEXT_GID = 32, - CONTEXT_EGID = 33, - CONTEXT_SGID = 34, - CONTEXT_VUID = 35, - CONTEXT_VEUID = 36, - CONTEXT_VSUID = 37, - CONTEXT_VGID = 38, - CONTEXT_VEGID = 39, - CONTEXT_VSGID = 40, - CONTEXT_TIME_NS = 41, + CONTEXT_CGROUP_NS = 22, + CONTEXT_IPC_NS = 23, + CONTEXT_MNT_NS = 24, + CONTEXT_NET_NS = 25, + CONTEXT_PID_NS = 26, + CONTEXT_USER_NS = 27, + CONTEXT_UTS_NS = 28, + CONTEXT_UID = 29, + CONTEXT_EUID = 30, + CONTEXT_SUID = 31, + CONTEXT_GID = 32, + CONTEXT_EGID = 33, + CONTEXT_SGID = 34, + CONTEXT_VUID = 35, + CONTEXT_VEUID = 36, + CONTEXT_VSUID = 37, + CONTEXT_VGID = 38, + CONTEXT_VEGID = 39, + CONTEXT_VSGID = 40, + CONTEXT_TIME_NS = 41, }; /* @@ -109,25 +110,25 @@ enum perf_type { }; enum perf_count_hard { - PERF_COUNT_HW_CPU_CYCLES = 0, - PERF_COUNT_HW_INSTRUCTIONS = 1, - PERF_COUNT_HW_CACHE_REFERENCES = 2, - PERF_COUNT_HW_CACHE_MISSES = 3, - PERF_COUNT_HW_BRANCH_INSTRUCTIONS = 4, - PERF_COUNT_HW_BRANCH_MISSES = 5, - PERF_COUNT_HW_BUS_CYCLES = 6, - PERF_COUNT_HW_STALLED_CYCLES_FRONTEND = 7, - PERF_COUNT_HW_STALLED_CYCLES_BACKEND = 8, + PERF_COUNT_HW_CPU_CYCLES = 0, + PERF_COUNT_HW_INSTRUCTIONS = 1, + PERF_COUNT_HW_CACHE_REFERENCES = 2, + PERF_COUNT_HW_CACHE_MISSES = 3, + PERF_COUNT_HW_BRANCH_INSTRUCTIONS = 4, + PERF_COUNT_HW_BRANCH_MISSES = 5, + PERF_COUNT_HW_BUS_CYCLES = 6, + PERF_COUNT_HW_STALLED_CYCLES_FRONTEND = 7, + PERF_COUNT_HW_STALLED_CYCLES_BACKEND = 8, }; enum perf_count_soft { - PERF_COUNT_SW_CPU_CLOCK = 0, - PERF_COUNT_SW_TASK_CLOCK = 1, - PERF_COUNT_SW_PAGE_FAULTS = 2, + PERF_COUNT_SW_CPU_CLOCK = 0, + PERF_COUNT_SW_TASK_CLOCK = 1, + PERF_COUNT_SW_PAGE_FAULTS = 2, PERF_COUNT_SW_CONTEXT_SWITCHES = 3, - PERF_COUNT_SW_CPU_MIGRATIONS = 4, - PERF_COUNT_SW_PAGE_FAULTS_MIN = 5, - PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6, + PERF_COUNT_SW_CPU_MIGRATIONS = 4, + PERF_COUNT_SW_PAGE_FAULTS_MIN = 5, + PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6, PERF_COUNT_SW_ALIGNMENT_FAULTS = 7, PERF_COUNT_SW_EMULATION_FAULTS = 8, }; @@ -140,121 +141,121 @@ enum perf_count_soft { * { accesses, misses } */ enum perf_hw_cache_id { - PERF_COUNT_HW_CACHE_L1D = 0, - PERF_COUNT_HW_CACHE_L1I = 1, - PERF_COUNT_HW_CACHE_LL = 2, - PERF_COUNT_HW_CACHE_DTLB = 3, - PERF_COUNT_HW_CACHE_ITLB = 4, - PERF_COUNT_HW_CACHE_BPU = 5, - - PERF_COUNT_HW_CACHE_MAX, /* non-ABI */ + PERF_COUNT_HW_CACHE_L1D = 0, + PERF_COUNT_HW_CACHE_L1I = 1, + PERF_COUNT_HW_CACHE_LL = 2, + PERF_COUNT_HW_CACHE_DTLB = 3, + PERF_COUNT_HW_CACHE_ITLB = 4, + PERF_COUNT_HW_CACHE_BPU = 5, + + PERF_COUNT_HW_CACHE_MAX, /* non-ABI */ }; enum perf_hw_cache_op_id { - PERF_COUNT_HW_CACHE_OP_READ = 0, - PERF_COUNT_HW_CACHE_OP_WRITE = 1, - PERF_COUNT_HW_CACHE_OP_PREFETCH = 2, + PERF_COUNT_HW_CACHE_OP_READ = 0, + PERF_COUNT_HW_CACHE_OP_WRITE = 1, + PERF_COUNT_HW_CACHE_OP_PREFETCH = 2, - PERF_COUNT_HW_CACHE_OP_MAX, /* non-ABI */ + PERF_COUNT_HW_CACHE_OP_MAX, /* non-ABI */ }; enum perf_hw_cache_op_result_id { - PERF_COUNT_HW_CACHE_RESULT_ACCESS = 0, - PERF_COUNT_HW_CACHE_RESULT_MISS = 1, + PERF_COUNT_HW_CACHE_RESULT_ACCESS = 0, + PERF_COUNT_HW_CACHE_RESULT_MISS = 1, - PERF_COUNT_HW_CACHE_RESULT_MAX, /* non-ABI */ + PERF_COUNT_HW_CACHE_RESULT_MAX, /* non-ABI */ }; static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ - {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, - {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, - {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0}, - {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, - {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, - {"jul", 'j', POPT_ARG_NONE, 0, OPT_JUL, 0, 0}, - {"log4j", 'l', POPT_ARG_NONE, 0, OPT_LOG4J, 0, 0}, - {"type", 't', POPT_ARG_STRING, &opt_type, OPT_TYPE, 0, 0}, - {"list", 0, POPT_ARG_NONE, NULL, OPT_LIST, NULL, NULL}, - {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, - {0, 0, 0, 0, 0, 0, 0} + { "help", 'h', POPT_ARG_NONE, nullptr, OPT_HELP, nullptr, nullptr }, + { "session", 's', POPT_ARG_STRING, &opt_session_name, 0, nullptr, nullptr }, + { "channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, nullptr, nullptr }, + { "kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, nullptr, nullptr }, + { "userspace", 'u', POPT_ARG_NONE, nullptr, OPT_USERSPACE, nullptr, nullptr }, + { "jul", 'j', POPT_ARG_NONE, nullptr, OPT_JUL, nullptr, nullptr }, + { "log4j", 'l', POPT_ARG_NONE, nullptr, OPT_LOG4J, nullptr, nullptr }, + { "type", 't', POPT_ARG_STRING, &opt_type, OPT_TYPE, nullptr, nullptr }, + { "list", 0, POPT_ARG_NONE, nullptr, OPT_LIST, nullptr, nullptr }, + { "list-options", 0, POPT_ARG_NONE, nullptr, OPT_LIST_OPTIONS, nullptr, nullptr }, + { nullptr, 0, 0, nullptr, 0, nullptr, nullptr } }; /* * Context options */ -#define PERF_HW(optstr, name, type, hide) \ - { \ - optstr, type, PERF_COUNT_HW_##name, hide \ +#define PERF_HW(optstr, name, type, hide) \ + { \ + optstr, type, PERF_COUNT_HW_##name, hide \ } -#define PERF_SW(optstr, name, type, hide) \ - { \ - optstr, type, PERF_COUNT_SW_##name, hide \ +#define PERF_SW(optstr, name, type, hide) \ + { \ + optstr, type, PERF_COUNT_SW_##name, hide \ } -#define _PERF_HW_CACHE(optstr, name, type, op, result, hide) \ - { \ - optstr, type, \ - PERF_COUNT_HW_CACHE_##name, \ - PERF_COUNT_HW_CACHE_OP_##op, \ - PERF_COUNT_HW_CACHE_RESULT_##result, \ - hide, \ +#define _PERF_HW_CACHE(optstr, name, type, op, result, hide) \ + { \ + optstr, type, PERF_COUNT_HW_CACHE_##name, PERF_COUNT_HW_CACHE_OP_##op, \ + PERF_COUNT_HW_CACHE_RESULT_##result, hide, \ } -#define PERF_HW_CACHE(optstr, name, type, hide) \ - _PERF_HW_CACHE(optstr "-loads", name, type, \ - READ, ACCESS, hide), \ - _PERF_HW_CACHE(optstr "-load-misses", name, type, \ - READ, MISS, hide), \ - _PERF_HW_CACHE(optstr "-stores", name, type, \ - WRITE, ACCESS, hide), \ - _PERF_HW_CACHE(optstr "-store-misses", name, type, \ - WRITE, MISS, hide), \ - _PERF_HW_CACHE(optstr "-prefetches", name, type, \ - PREFETCH, ACCESS, hide), \ - _PERF_HW_CACHE(optstr "-prefetch-misses", name, type, \ - PREFETCH, MISS, hide) - -static +#define PERF_HW_CACHE(optstr, name, type, hide) \ + _PERF_HW_CACHE(optstr "-loads", name, type, READ, ACCESS, hide), \ + _PERF_HW_CACHE(optstr "-load-misses", name, type, READ, MISS, hide), \ + _PERF_HW_CACHE(optstr "-stores", name, type, WRITE, ACCESS, hide), \ + _PERF_HW_CACHE(optstr "-store-misses", name, type, WRITE, MISS, hide), \ + _PERF_HW_CACHE(optstr "-prefetches", name, type, PREFETCH, ACCESS, hide), \ + _PERF_HW_CACHE(optstr "-prefetch-misses", name, type, PREFETCH, MISS, hide) + +namespace { const struct ctx_opts { /* Needed for end-of-list item. */ - ctx_opts() - : symbol(nullptr) - {} + ctx_opts() : ctx_opts(nullptr, CONTEXT_UNKNOWN) + { + } - ctx_opts(const char *symbol_, context_type ctx_type_, bool hide_help_ = false) - : symbol((char *) symbol_), ctx_type(ctx_type_), hide_help(hide_help_) - {} + ctx_opts(const char *symbol_, context_type ctx_type_, bool hide_help_ = false) : + symbol((char *) symbol_), ctx_type(ctx_type_), hide_help(hide_help_) + { + } - ctx_opts(const char *symbol_, context_type ctx_type_, perf_count_hard perf_count_hard, bool hide_help_) - : ctx_opts(symbol_, ctx_type_, hide_help_) + ctx_opts(const char *symbol_, + context_type ctx_type_, + perf_count_hard perf_count_hard, + bool hide_help_) : + ctx_opts(symbol_, ctx_type_, hide_help_) { u.perf.type = PERF_TYPE_HARDWARE; u.perf.config = perf_count_hard; } - ctx_opts(const char *symbol_, context_type ctx_type_, perf_count_soft perf_count_soft, bool hide_help_) - : ctx_opts(symbol_, ctx_type_, hide_help_) + ctx_opts(const char *symbol_, + context_type ctx_type_, + perf_count_soft perf_count_soft, + bool hide_help_) : + ctx_opts(symbol_, ctx_type_, hide_help_) { u.perf.type = PERF_TYPE_SOFTWARE; u.perf.config = perf_count_soft; } - ctx_opts(const char *symbol_, context_type ctx_type_, - perf_hw_cache_id perf_hw_cache_id, - perf_hw_cache_op_id perf_hw_cache_op_id, - perf_hw_cache_op_result_id perf_hw_cache_op_result_id, - bool hide_help_) - : ctx_opts(symbol_, ctx_type_, hide_help_) + ctx_opts(const char *symbol_, + context_type ctx_type_, + perf_hw_cache_id perf_hw_cache_id, + perf_hw_cache_op_id perf_hw_cache_op_id, + perf_hw_cache_op_result_id perf_hw_cache_op_result_id, + bool hide_help_) : + ctx_opts(symbol_, ctx_type_, hide_help_) { u.perf.type = PERF_TYPE_HW_CACHE; - u.perf.config = perf_hw_cache_id | perf_hw_cache_op_id << 8 | perf_hw_cache_op_result_id << 16; + u.perf.config = perf_hw_cache_id | perf_hw_cache_op_id << 8 | + perf_hw_cache_op_result_id << 16; } char *symbol; enum context_type ctx_type; - bool hide_help; /* Hide from --help */ + bool hide_help; /* Hide from --help */ union { struct { uint32_t type; @@ -287,7 +288,7 @@ const struct ctx_opts { { (char *) "need_reschedule", CONTEXT_NEED_RESCHEDULE }, { (char *) "migratable", CONTEXT_MIGRATABLE }, { (char *) "callstack-kernel", CONTEXT_CALLSTACK_KERNEL }, -#if HAVE_MODULES_USERSPACE_CALLSTACK_CONTEXT +#ifdef HAVE_MODULES_USERSPACE_CALLSTACK_CONTEXT { (char *) "callstack-user", CONTEXT_CALLSTACK_USER }, #endif { (char *) "cgroup_ns", CONTEXT_CGROUP_NS }, @@ -314,219 +315,147 @@ const struct ctx_opts { /* Perf options */ /* Perf per-CPU counters */ - PERF_HW("perf:cpu:cpu-cycles", CPU_CYCLES, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:cycles", CPU_CYCLES, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:stalled-cycles-frontend", STALLED_CYCLES_FRONTEND, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:idle-cycles-frontend", STALLED_CYCLES_FRONTEND, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:stalled-cycles-backend", STALLED_CYCLES_BACKEND, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:idle-cycles-backend", STALLED_CYCLES_BACKEND, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:instructions", INSTRUCTIONS, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:cache-references", CACHE_REFERENCES, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:cache-misses", CACHE_MISSES, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:branch-instructions", BRANCH_INSTRUCTIONS, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:branches", BRANCH_INSTRUCTIONS, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:branch-misses", BRANCH_MISSES, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW("perf:cpu:bus-cycles", BUS_CYCLES, - CONTEXT_PERF_CPU_COUNTER, 0), - - PERF_HW_CACHE("perf:cpu:L1-dcache", L1D, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW_CACHE("perf:cpu:L1-icache", L1I, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW_CACHE("perf:cpu:LLC", LL, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_HW_CACHE("perf:cpu:dTLB", DTLB, - CONTEXT_PERF_CPU_COUNTER, 0), - _PERF_HW_CACHE("perf:cpu:iTLB-loads", ITLB, - CONTEXT_PERF_CPU_COUNTER, READ, ACCESS, 0), - _PERF_HW_CACHE("perf:cpu:iTLB-load-misses", ITLB, - CONTEXT_PERF_CPU_COUNTER, READ, MISS, 0), - _PERF_HW_CACHE("perf:cpu:branch-loads", BPU, - CONTEXT_PERF_CPU_COUNTER, READ, ACCESS, 0), - _PERF_HW_CACHE("perf:cpu:branch-load-misses", BPU, - CONTEXT_PERF_CPU_COUNTER, READ, MISS, 0), - - PERF_SW("perf:cpu:cpu-clock", CPU_CLOCK, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_SW("perf:cpu:task-clock", TASK_CLOCK, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_SW("perf:cpu:page-fault", PAGE_FAULTS, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_SW("perf:cpu:faults", PAGE_FAULTS, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_SW("perf:cpu:major-faults", PAGE_FAULTS_MAJ, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_SW("perf:cpu:minor-faults", PAGE_FAULTS_MIN, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_SW("perf:cpu:context-switches", CONTEXT_SWITCHES, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_SW("perf:cpu:cs", CONTEXT_SWITCHES, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_SW("perf:cpu:cpu-migrations", CPU_MIGRATIONS, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_SW("perf:cpu:migrations", CPU_MIGRATIONS, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_SW("perf:cpu:alignment-faults", ALIGNMENT_FAULTS, - CONTEXT_PERF_CPU_COUNTER, 0), - PERF_SW("perf:cpu:emulation-faults", EMULATION_FAULTS, - CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW("perf:cpu:cpu-cycles", CPU_CYCLES, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW("perf:cpu:cycles", CPU_CYCLES, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW("perf:cpu:stalled-cycles-frontend", + STALLED_CYCLES_FRONTEND, + CONTEXT_PERF_CPU_COUNTER, + 0), + PERF_HW("perf:cpu:idle-cycles-frontend", + STALLED_CYCLES_FRONTEND, + CONTEXT_PERF_CPU_COUNTER, + 0), + PERF_HW("perf:cpu:stalled-cycles-backend", + STALLED_CYCLES_BACKEND, + CONTEXT_PERF_CPU_COUNTER, + 0), + PERF_HW("perf:cpu:idle-cycles-backend", STALLED_CYCLES_BACKEND, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW("perf:cpu:instructions", INSTRUCTIONS, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW("perf:cpu:cache-references", CACHE_REFERENCES, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW("perf:cpu:cache-misses", CACHE_MISSES, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW("perf:cpu:branch-instructions", BRANCH_INSTRUCTIONS, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW("perf:cpu:branches", BRANCH_INSTRUCTIONS, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW("perf:cpu:branch-misses", BRANCH_MISSES, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW("perf:cpu:bus-cycles", BUS_CYCLES, CONTEXT_PERF_CPU_COUNTER, 0), + + PERF_HW_CACHE("perf:cpu:L1-dcache", L1D, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW_CACHE("perf:cpu:L1-icache", L1I, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW_CACHE("perf:cpu:LLC", LL, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_HW_CACHE("perf:cpu:dTLB", DTLB, CONTEXT_PERF_CPU_COUNTER, 0), + _PERF_HW_CACHE("perf:cpu:iTLB-loads", ITLB, CONTEXT_PERF_CPU_COUNTER, READ, ACCESS, 0), + _PERF_HW_CACHE("perf:cpu:iTLB-load-misses", ITLB, CONTEXT_PERF_CPU_COUNTER, READ, MISS, 0), + _PERF_HW_CACHE("perf:cpu:branch-loads", BPU, CONTEXT_PERF_CPU_COUNTER, READ, ACCESS, 0), + _PERF_HW_CACHE("perf:cpu:branch-load-misses", BPU, CONTEXT_PERF_CPU_COUNTER, READ, MISS, 0), + + PERF_SW("perf:cpu:cpu-clock", CPU_CLOCK, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_SW("perf:cpu:task-clock", TASK_CLOCK, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_SW("perf:cpu:page-fault", PAGE_FAULTS, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_SW("perf:cpu:faults", PAGE_FAULTS, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_SW("perf:cpu:major-faults", PAGE_FAULTS_MAJ, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_SW("perf:cpu:minor-faults", PAGE_FAULTS_MIN, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_SW("perf:cpu:context-switches", CONTEXT_SWITCHES, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_SW("perf:cpu:cs", CONTEXT_SWITCHES, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_SW("perf:cpu:cpu-migrations", CPU_MIGRATIONS, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_SW("perf:cpu:migrations", CPU_MIGRATIONS, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_SW("perf:cpu:alignment-faults", ALIGNMENT_FAULTS, CONTEXT_PERF_CPU_COUNTER, 0), + PERF_SW("perf:cpu:emulation-faults", EMULATION_FAULTS, CONTEXT_PERF_CPU_COUNTER, 0), /* Perf per-thread counters */ - PERF_HW("perf:thread:cpu-cycles", CPU_CYCLES, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:cycles", CPU_CYCLES, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:stalled-cycles-frontend", STALLED_CYCLES_FRONTEND, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:idle-cycles-frontend", STALLED_CYCLES_FRONTEND, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:stalled-cycles-backend", STALLED_CYCLES_BACKEND, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:idle-cycles-backend", STALLED_CYCLES_BACKEND, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:instructions", INSTRUCTIONS, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:cache-references", CACHE_REFERENCES, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:cache-misses", CACHE_MISSES, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:branch-instructions", BRANCH_INSTRUCTIONS, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:branches", BRANCH_INSTRUCTIONS, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:branch-misses", BRANCH_MISSES, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW("perf:thread:bus-cycles", BUS_CYCLES, - CONTEXT_PERF_THREAD_COUNTER, 0), - - PERF_HW_CACHE("perf:thread:L1-dcache", L1D, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW_CACHE("perf:thread:L1-icache", L1I, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW_CACHE("perf:thread:LLC", LL, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_HW_CACHE("perf:thread:dTLB", DTLB, - CONTEXT_PERF_THREAD_COUNTER, 0), - _PERF_HW_CACHE("perf:thread:iTLB-loads", ITLB, - CONTEXT_PERF_THREAD_COUNTER, READ, ACCESS, 0), - _PERF_HW_CACHE("perf:thread:iTLB-load-misses", ITLB, - CONTEXT_PERF_THREAD_COUNTER, READ, MISS, 0), - _PERF_HW_CACHE("perf:thread:branch-loads", BPU, - CONTEXT_PERF_THREAD_COUNTER, READ, ACCESS, 0), - _PERF_HW_CACHE("perf:thread:branch-load-misses", BPU, - CONTEXT_PERF_THREAD_COUNTER, READ, MISS, 0), - - PERF_SW("perf:thread:cpu-clock", CPU_CLOCK, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_SW("perf:thread:task-clock", TASK_CLOCK, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_SW("perf:thread:page-fault", PAGE_FAULTS, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_SW("perf:thread:faults", PAGE_FAULTS, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_SW("perf:thread:major-faults", PAGE_FAULTS_MAJ, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_SW("perf:thread:minor-faults", PAGE_FAULTS_MIN, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_SW("perf:thread:context-switches", CONTEXT_SWITCHES, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_SW("perf:thread:cs", CONTEXT_SWITCHES, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_SW("perf:thread:cpu-migrations", CPU_MIGRATIONS, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_SW("perf:thread:migrations", CPU_MIGRATIONS, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_SW("perf:thread:alignment-faults", ALIGNMENT_FAULTS, - CONTEXT_PERF_THREAD_COUNTER, 0), - PERF_SW("perf:thread:emulation-faults", EMULATION_FAULTS, - CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_HW("perf:thread:cpu-cycles", CPU_CYCLES, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_HW("perf:thread:cycles", CPU_CYCLES, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_HW("perf:thread:stalled-cycles-frontend", + STALLED_CYCLES_FRONTEND, + CONTEXT_PERF_THREAD_COUNTER, + 0), + PERF_HW("perf:thread:idle-cycles-frontend", + STALLED_CYCLES_FRONTEND, + CONTEXT_PERF_THREAD_COUNTER, + 0), + PERF_HW("perf:thread:stalled-cycles-backend", + STALLED_CYCLES_BACKEND, + CONTEXT_PERF_THREAD_COUNTER, + 0), + PERF_HW("perf:thread:idle-cycles-backend", + STALLED_CYCLES_BACKEND, + CONTEXT_PERF_THREAD_COUNTER, + 0), + PERF_HW("perf:thread:instructions", INSTRUCTIONS, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_HW("perf:thread:cache-references", CACHE_REFERENCES, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_HW("perf:thread:cache-misses", CACHE_MISSES, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_HW("perf:thread:branch-instructions", + BRANCH_INSTRUCTIONS, + CONTEXT_PERF_THREAD_COUNTER, + 0), + PERF_HW("perf:thread:branches", BRANCH_INSTRUCTIONS, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_HW("perf:thread:branch-misses", BRANCH_MISSES, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_HW("perf:thread:bus-cycles", BUS_CYCLES, CONTEXT_PERF_THREAD_COUNTER, 0), + + PERF_HW_CACHE("perf:thread:L1-dcache", L1D, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_HW_CACHE("perf:thread:L1-icache", L1I, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_HW_CACHE("perf:thread:LLC", LL, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_HW_CACHE("perf:thread:dTLB", DTLB, CONTEXT_PERF_THREAD_COUNTER, 0), + _PERF_HW_CACHE("perf:thread:iTLB-loads", ITLB, CONTEXT_PERF_THREAD_COUNTER, READ, ACCESS, 0), + _PERF_HW_CACHE( + "perf:thread:iTLB-load-misses", ITLB, CONTEXT_PERF_THREAD_COUNTER, READ, MISS, 0), + _PERF_HW_CACHE( + "perf:thread:branch-loads", BPU, CONTEXT_PERF_THREAD_COUNTER, READ, ACCESS, 0), + _PERF_HW_CACHE( + "perf:thread:branch-load-misses", BPU, CONTEXT_PERF_THREAD_COUNTER, READ, MISS, 0), + + PERF_SW("perf:thread:cpu-clock", CPU_CLOCK, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_SW("perf:thread:task-clock", TASK_CLOCK, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_SW("perf:thread:page-fault", PAGE_FAULTS, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_SW("perf:thread:faults", PAGE_FAULTS, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_SW("perf:thread:major-faults", PAGE_FAULTS_MAJ, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_SW("perf:thread:minor-faults", PAGE_FAULTS_MIN, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_SW("perf:thread:context-switches", CONTEXT_SWITCHES, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_SW("perf:thread:cs", CONTEXT_SWITCHES, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_SW("perf:thread:cpu-migrations", CPU_MIGRATIONS, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_SW("perf:thread:migrations", CPU_MIGRATIONS, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_SW("perf:thread:alignment-faults", ALIGNMENT_FAULTS, CONTEXT_PERF_THREAD_COUNTER, 0), + PERF_SW("perf:thread:emulation-faults", EMULATION_FAULTS, CONTEXT_PERF_THREAD_COUNTER, 0), /* * Perf per-CPU counters, backward compatibilty for names. * Hidden from help listing. */ - PERF_HW("perf:cpu-cycles", CPU_CYCLES, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:cycles", CPU_CYCLES, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:stalled-cycles-frontend", STALLED_CYCLES_FRONTEND, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:idle-cycles-frontend", STALLED_CYCLES_FRONTEND, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:stalled-cycles-backend", STALLED_CYCLES_BACKEND, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:idle-cycles-backend", STALLED_CYCLES_BACKEND, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:instructions", INSTRUCTIONS, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:cache-references", CACHE_REFERENCES, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:cache-misses", CACHE_MISSES, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:branch-instructions", BRANCH_INSTRUCTIONS, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:branches", BRANCH_INSTRUCTIONS, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:branch-misses", BRANCH_MISSES, - CONTEXT_PERF_COUNTER, 1), - PERF_HW("perf:bus-cycles", BUS_CYCLES, - CONTEXT_PERF_COUNTER, 1), - - PERF_HW_CACHE("perf:L1-dcache", L1D, - CONTEXT_PERF_COUNTER, 1), - PERF_HW_CACHE("perf:L1-icache", L1I, - CONTEXT_PERF_COUNTER, 1), - PERF_HW_CACHE("perf:LLC", LL, - CONTEXT_PERF_COUNTER, 1), - PERF_HW_CACHE("perf:dTLB", DTLB, - CONTEXT_PERF_COUNTER, 1), - _PERF_HW_CACHE("perf:iTLB-loads", ITLB, - CONTEXT_PERF_COUNTER, READ, ACCESS, 1), - _PERF_HW_CACHE("perf:iTLB-load-misses", ITLB, - CONTEXT_PERF_COUNTER, READ, MISS, 1), - _PERF_HW_CACHE("perf:branch-loads", BPU, - CONTEXT_PERF_COUNTER, READ, ACCESS, 1), - _PERF_HW_CACHE("perf:branch-load-misses", BPU, - CONTEXT_PERF_COUNTER, READ, MISS, 1), - - PERF_SW("perf:cpu-clock", CPU_CLOCK, - CONTEXT_PERF_COUNTER, 1), - PERF_SW("perf:task-clock", TASK_CLOCK, - CONTEXT_PERF_COUNTER, 1), - PERF_SW("perf:page-fault", PAGE_FAULTS, - CONTEXT_PERF_COUNTER, 1), - PERF_SW("perf:faults", PAGE_FAULTS, - CONTEXT_PERF_COUNTER, 1), - PERF_SW("perf:major-faults", PAGE_FAULTS_MAJ, - CONTEXT_PERF_COUNTER, 1), - PERF_SW("perf:minor-faults", PAGE_FAULTS_MIN, - CONTEXT_PERF_COUNTER, 1), - PERF_SW("perf:context-switches", CONTEXT_SWITCHES, - CONTEXT_PERF_COUNTER, 1), - PERF_SW("perf:cs", CONTEXT_SWITCHES, - CONTEXT_PERF_COUNTER, 1), - PERF_SW("perf:cpu-migrations", CPU_MIGRATIONS, - CONTEXT_PERF_COUNTER, 1), - PERF_SW("perf:migrations", CPU_MIGRATIONS, - CONTEXT_PERF_COUNTER, 1), - PERF_SW("perf:alignment-faults", ALIGNMENT_FAULTS, - CONTEXT_PERF_COUNTER, 1), - PERF_SW("perf:emulation-faults", EMULATION_FAULTS, - CONTEXT_PERF_COUNTER, 1), - - {}, /* Closure */ + PERF_HW("perf:cpu-cycles", CPU_CYCLES, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:cycles", CPU_CYCLES, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:stalled-cycles-frontend", STALLED_CYCLES_FRONTEND, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:idle-cycles-frontend", STALLED_CYCLES_FRONTEND, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:stalled-cycles-backend", STALLED_CYCLES_BACKEND, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:idle-cycles-backend", STALLED_CYCLES_BACKEND, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:instructions", INSTRUCTIONS, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:cache-references", CACHE_REFERENCES, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:cache-misses", CACHE_MISSES, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:branch-instructions", BRANCH_INSTRUCTIONS, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:branches", BRANCH_INSTRUCTIONS, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:branch-misses", BRANCH_MISSES, CONTEXT_PERF_COUNTER, 1), + PERF_HW("perf:bus-cycles", BUS_CYCLES, CONTEXT_PERF_COUNTER, 1), + + PERF_HW_CACHE("perf:L1-dcache", L1D, CONTEXT_PERF_COUNTER, 1), + PERF_HW_CACHE("perf:L1-icache", L1I, CONTEXT_PERF_COUNTER, 1), + PERF_HW_CACHE("perf:LLC", LL, CONTEXT_PERF_COUNTER, 1), + PERF_HW_CACHE("perf:dTLB", DTLB, CONTEXT_PERF_COUNTER, 1), + _PERF_HW_CACHE("perf:iTLB-loads", ITLB, CONTEXT_PERF_COUNTER, READ, ACCESS, 1), + _PERF_HW_CACHE("perf:iTLB-load-misses", ITLB, CONTEXT_PERF_COUNTER, READ, MISS, 1), + _PERF_HW_CACHE("perf:branch-loads", BPU, CONTEXT_PERF_COUNTER, READ, ACCESS, 1), + _PERF_HW_CACHE("perf:branch-load-misses", BPU, CONTEXT_PERF_COUNTER, READ, MISS, 1), + + PERF_SW("perf:cpu-clock", CPU_CLOCK, CONTEXT_PERF_COUNTER, 1), + PERF_SW("perf:task-clock", TASK_CLOCK, CONTEXT_PERF_COUNTER, 1), + PERF_SW("perf:page-fault", PAGE_FAULTS, CONTEXT_PERF_COUNTER, 1), + PERF_SW("perf:faults", PAGE_FAULTS, CONTEXT_PERF_COUNTER, 1), + PERF_SW("perf:major-faults", PAGE_FAULTS_MAJ, CONTEXT_PERF_COUNTER, 1), + PERF_SW("perf:minor-faults", PAGE_FAULTS_MIN, CONTEXT_PERF_COUNTER, 1), + PERF_SW("perf:context-switches", CONTEXT_SWITCHES, CONTEXT_PERF_COUNTER, 1), + PERF_SW("perf:cs", CONTEXT_SWITCHES, CONTEXT_PERF_COUNTER, 1), + PERF_SW("perf:cpu-migrations", CPU_MIGRATIONS, CONTEXT_PERF_COUNTER, 1), + PERF_SW("perf:migrations", CPU_MIGRATIONS, CONTEXT_PERF_COUNTER, 1), + PERF_SW("perf:alignment-faults", ALIGNMENT_FAULTS, CONTEXT_PERF_COUNTER, 1), + PERF_SW("perf:emulation-faults", EMULATION_FAULTS, CONTEXT_PERF_COUNTER, 1), + + {}, /* Closure */ }; #undef PERF_HW_CACHE @@ -551,8 +480,7 @@ struct ctx_type_list { } ctx_type_list = { .head = CDS_LIST_HEAD_INIT(ctx_type_list.head), }; - - +} /* namespace */ /* * Find context numerical value from string. @@ -563,7 +491,7 @@ static int find_ctx_type_idx(const char *opt) { int ret, i = 0; - while (ctx_opts[i].symbol != NULL) { + while (ctx_opts[i].symbol != nullptr) { if (strcmp(opt, ctx_opts[i].symbol) == 0) { ret = i; goto end; @@ -576,8 +504,7 @@ end: return ret; } -static -enum lttng_domain_type get_domain(void) +static enum lttng_domain_type get_domain() { if (opt_kernel) { return LTTNG_DOMAIN_KERNEL; @@ -592,8 +519,7 @@ enum lttng_domain_type get_domain(void) } } -static -int mi_open(void) +static int mi_open() { int ret; @@ -617,16 +543,14 @@ int mi_open(void) } /* Open command element */ - ret = mi_lttng_writer_command_open(writer, - mi_lttng_element_command_add_context); + ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_add_context); if (ret) { ret = CMD_ERROR; goto end; } /* Open output element */ - ret = mi_lttng_writer_open_element(writer, - mi_lttng_element_command_output); + ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output); if (ret) { ret = CMD_ERROR; goto end; @@ -635,8 +559,7 @@ end: return ret; } -static -int mi_close(enum cmd_error_code success) +static int mi_close(enum cmd_error_code success) { int ret; @@ -653,8 +576,8 @@ int mi_close(enum cmd_error_code success) } /* Success ? */ - ret = mi_lttng_writer_write_element_bool(writer, - mi_lttng_element_command_success, !success); + ret = mi_lttng_writer_write_element_bool( + writer, mi_lttng_element_command_success, !success); if (ret) { ret = CMD_ERROR; goto end; @@ -670,9 +593,7 @@ end: return ret; } -static -void populate_context(struct lttng_event_context *context, - const struct ctx_opts *opt) +static void populate_context(struct lttng_event_context *context, const struct ctx_opts *opt) { char *ptr; @@ -683,22 +604,19 @@ void populate_context(struct lttng_event_context *context, case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER: context->u.perf_counter.type = opt->u.perf.type; context->u.perf_counter.config = opt->u.perf.config; - strncpy(context->u.perf_counter.name, opt->symbol, - LTTNG_SYMBOL_NAME_LEN); + strncpy(context->u.perf_counter.name, opt->symbol, LTTNG_SYMBOL_NAME_LEN); context->u.perf_counter.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; /* Replace : and - by _ */ - while ((ptr = strchr(context->u.perf_counter.name, '-')) != NULL) { + while ((ptr = strchr(context->u.perf_counter.name, '-')) != nullptr) { *ptr = '_'; } - while ((ptr = strchr(context->u.perf_counter.name, ':')) != NULL) { + while ((ptr = strchr(context->u.perf_counter.name, ':')) != nullptr) { *ptr = '_'; } break; case LTTNG_EVENT_CONTEXT_APP_CONTEXT: - context->u.app_ctx.provider_name = - opt->u.app_ctx.provider_name; - context->u.app_ctx.ctx_name = - opt->u.app_ctx.ctx_name; + context->u.app_ctx.provider_name = opt->u.app_ctx.provider_name; + context->u.app_ctx.ctx_name = opt->u.app_ctx.ctx_name; break; default: break; @@ -708,10 +626,8 @@ void populate_context(struct lttng_event_context *context, /* * Pretty print context type. */ -static -int print_ctx_type(void) +static int print_ctx_type() { - FILE *ofp = stdout; int i = 0; int ret; @@ -734,7 +650,7 @@ int print_ctx_type(void) } } - while (ctx_opts[i].symbol != NULL) { + while (ctx_opts[i].symbol != nullptr) { if (!ctx_opts[i].hide_help) { if (lttng_opt_mi) { populate_context(&context, &ctx_opts[i]); @@ -745,9 +661,9 @@ int print_ctx_type(void) } ret = mi_lttng_writer_write_element_string( - writer, - mi_lttng_element_context_symbol, - ctx_opts[i].symbol); + writer, + mi_lttng_element_context_symbol, + ctx_opts[i].symbol); if (ret) { ret = CMD_ERROR; goto end; @@ -796,7 +712,7 @@ static int add_context(char *session_name) dom.type = get_domain(); handle = lttng_create_handle(session_name, &dom); - if (handle == NULL) { + if (handle == nullptr) { ret = CMD_ERROR; goto error; } @@ -810,7 +726,7 @@ static int add_context(char *session_name) } /* Iterate over all the context types given */ - cds_list_for_each_entry(type, &ctx_type_list.head, list) { + cds_list_for_each_entry (type, &ctx_type_list.head, list) { DBG("Adding context..."); populate_context(&context, type->opt); @@ -823,16 +739,15 @@ static int add_context(char *session_name) goto error; } - ret = mi_lttng_writer_write_element_string(writer, - mi_lttng_element_context_symbol, - type->opt->symbol); + ret = mi_lttng_writer_write_element_string( + writer, mi_lttng_element_context_symbol, type->opt->symbol); if (ret) { ret = CMD_ERROR; goto error; } } - ret = lttng_add_context(handle, &context, NULL, opt_channel_name); + ret = lttng_add_context(handle, &context, nullptr, opt_channel_name); if (ret < 0) { ERR("%s: %s", type->opt->symbol, lttng_strerror(ret)); warn = 1; @@ -840,21 +755,21 @@ static int add_context(char *session_name) } else { if (opt_channel_name) { MSG("%s context %s added to channel %s", - lttng_domain_type_str(dom.type), - type->opt->symbol, - opt_channel_name); + lttng_domain_type_str(dom.type), + type->opt->symbol, + opt_channel_name); } else { MSG("%s context %s added to all channels", - lttng_domain_type_str(dom.type), - type->opt->symbol); + lttng_domain_type_str(dom.type), + type->opt->symbol); } success = 1; } if (lttng_opt_mi) { /* Is the single operation a success ? */ - ret = mi_lttng_writer_write_element_bool(writer, - mi_lttng_element_success, success); + ret = mi_lttng_writer_write_element_bool( + writer, mi_lttng_element_success, success); if (ret) { ret = CMD_ERROR; goto error; @@ -892,42 +807,46 @@ error: return ret; } -static -void destroy_ctx_type(struct ctx_type *type) +static void destroy_ctx_type(struct ctx_type *type) { if (!type) { return; } + if (type->opt) { free(type->opt->symbol); + + if (type->opt->ctx_type == CONTEXT_APP_CONTEXT) { + free(type->opt->u.app_ctx.ctx_name); + free(type->opt->u.app_ctx.provider_name); + } } - free(type->opt); + + delete type->opt; free(type); } -static -struct ctx_type *create_ctx_type(void) +static struct ctx_type *create_ctx_type() { - struct ctx_type *type = (ctx_type *) zmalloc(sizeof(*type)); + struct ctx_type *type = zmalloc(); if (!type) { PERROR("malloc ctx_type"); goto end; } - type->opt = (struct ctx_opts *) zmalloc(sizeof(*type->opt)); + type->opt = new struct ctx_opts; if (!type->opt) { PERROR("malloc ctx_type options"); destroy_ctx_type(type); - type = NULL; + type = nullptr; goto end; } end: return type; } -static -int find_ctx_type_perf_raw(const char *ctx, struct ctx_type *type) +static int find_ctx_type_perf_raw(const char *ctx, struct ctx_type *type) { int ret; int field_pos = 0; @@ -948,7 +867,7 @@ int find_ctx_type_perf_raw(const char *ctx, struct ctx_type *type) if (!next) { break; } - cur_list = NULL; + cur_list = nullptr; switch (field_pos) { case 0: if (strncmp(next, "perf", 4) != 0) { @@ -982,7 +901,7 @@ int find_ctx_type_perf_raw(const char *ctx, struct ctx_type *type) goto end; } errno = 0; - type->opt->u.perf.config = strtoll(next + 1, &endptr, 16); + type->opt->u.perf.config = strtoll(next + 1, &endptr, 16); if (errno != 0 || !endptr || *endptr) { ERR("Wrong perf raw mask format: expected rNNN"); ret = -1; @@ -1003,8 +922,8 @@ int find_ctx_type_perf_raw(const char *ctx, struct ctx_type *type) if (field_pos < 5) { ERR("Invalid perf counter specifier, expected a specifier of " - "the form perf:cpu:raw:rNNN: or " - "perf:thread:raw:rNNN:"); + "the form perf:cpu:raw:rNNN: or " + "perf:thread:raw:rNNN:"); ret = -1; goto end; } @@ -1017,13 +936,12 @@ end: return ret; } -static -struct ctx_type *get_context_type(const char *ctx) +static struct ctx_type *get_context_type(const char *ctx) { int opt_index, ret; - struct ctx_type *type = NULL; + struct ctx_type *type = nullptr; const char app_ctx_prefix[] = "$app."; - char *provider_name = NULL, *ctx_name = NULL; + char *provider_name = nullptr, *ctx_name = nullptr; size_t i, len, colon_pos = 0, provider_name_len, ctx_name_len; if (!ctx) { @@ -1065,7 +983,7 @@ struct ctx_type *get_context_type(const char *ctx) } /* String starts with $app. */ - if (strncmp(ctx, app_ctx_prefix, sizeof(app_ctx_prefix) - 1)) { + if (strncmp(ctx, app_ctx_prefix, sizeof(app_ctx_prefix) - 1) != 0) { goto not_found; } @@ -1083,24 +1001,22 @@ struct ctx_type *get_context_type(const char *ctx) * No colon found or no ctx name ("$app.provider:") or no provider name * given ("$app.:..."), which is invalid. */ - if (!colon_pos || colon_pos == len || - colon_pos == sizeof(app_ctx_prefix)) { + if (!colon_pos || colon_pos == len || colon_pos == sizeof(app_ctx_prefix)) { ERR("Invalid application context provided: no provider or context name provided."); goto not_found; } provider_name_len = colon_pos - sizeof(app_ctx_prefix) + 2; - provider_name = (char *) zmalloc(provider_name_len); + provider_name = calloc(provider_name_len); if (!provider_name) { PERROR("malloc provider_name"); goto not_found; } - strncpy(provider_name, ctx + sizeof(app_ctx_prefix) - 1, - provider_name_len - 1); + strncpy(provider_name, ctx + sizeof(app_ctx_prefix) - 1, provider_name_len - 1); type->opt->u.app_ctx.provider_name = provider_name; ctx_name_len = len - colon_pos; - ctx_name = (char *) zmalloc(ctx_name_len); + ctx_name = calloc(ctx_name_len); if (!ctx_name) { PERROR("malloc ctx_name"); goto not_found; @@ -1115,7 +1031,7 @@ not_found: free(provider_name); free(ctx_name); destroy_ctx_type(type); - return NULL; + return nullptr; } /* @@ -1126,15 +1042,15 @@ int cmd_add_context(int argc, const char **argv) int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS; static poptContext pc; struct ctx_type *type, *tmptype; - char *session_name = NULL; - const char *leftover = NULL; + char *session_name = nullptr; + const char *leftover = nullptr; if (argc < 2) { ret = CMD_ERROR; goto end; } - pc = poptGetContext(NULL, argc, argv, long_options, 0); + pc = poptGetContext(nullptr, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); while ((opt = poptGetNextOpt(pc)) != -1) { @@ -1181,8 +1097,8 @@ int cmd_add_context(int argc, const char **argv) goto end; } - ret = print_missing_or_multiple_domains( - opt_kernel + opt_userspace + opt_jul + opt_log4j, true); + ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace + opt_jul + opt_log4j, + true); if (ret) { ret = CMD_ERROR; goto end; @@ -1196,7 +1112,7 @@ int cmd_add_context(int argc, const char **argv) if (!opt_session_name) { session_name = get_session_name(); - if (session_name == NULL) { + if (session_name == nullptr) { ret = CMD_ERROR; goto end; } @@ -1227,7 +1143,7 @@ end: } /* Cleanup allocated memory */ - cds_list_for_each_entry_safe(type, tmptype, &ctx_type_list.head, list) { + cds_list_for_each_entry_safe (type, tmptype, &ctx_type_list.head, list) { destroy_ctx_type(type); }