perf python: Add macro to simplify maintainance of the constants array
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 24 Jul 2015 16:00:03 +0000 (13:00 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 29 Jul 2015 13:51:45 +0000 (10:51 -0300)
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/n/tip-ffuchgsbr5mqu91xl9oggfss@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/python.c

index 626422eda7274264c46ebca2aad48a51981788a2..a851b791151bc72f128c62b11d8a87bb01ce843f 100644 (file)
@@ -941,76 +941,78 @@ static int pyrf_evlist__setup_types(void)
        return PyType_Ready(&pyrf_evlist__type);
 }
 
+#define PERF_CONST(name) { #name, PERF_##name }
+
 static struct {
        const char *name;
        int         value;
 } perf__constants[] = {
-       { "TYPE_HARDWARE",   PERF_TYPE_HARDWARE },
-       { "TYPE_SOFTWARE",   PERF_TYPE_SOFTWARE },
-       { "TYPE_TRACEPOINT", PERF_TYPE_TRACEPOINT },
-       { "TYPE_HW_CACHE",   PERF_TYPE_HW_CACHE },
-       { "TYPE_RAW",        PERF_TYPE_RAW },
-       { "TYPE_BREAKPOINT", PERF_TYPE_BREAKPOINT },
-
-       { "COUNT_HW_CPU_CYCLES",          PERF_COUNT_HW_CPU_CYCLES },
-       { "COUNT_HW_INSTRUCTIONS",        PERF_COUNT_HW_INSTRUCTIONS },
-       { "COUNT_HW_CACHE_REFERENCES",    PERF_COUNT_HW_CACHE_REFERENCES },
-       { "COUNT_HW_CACHE_MISSES",        PERF_COUNT_HW_CACHE_MISSES },
-       { "COUNT_HW_BRANCH_INSTRUCTIONS", PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
-       { "COUNT_HW_BRANCH_MISSES",       PERF_COUNT_HW_BRANCH_MISSES },
-       { "COUNT_HW_BUS_CYCLES",          PERF_COUNT_HW_BUS_CYCLES },
-       { "COUNT_HW_CACHE_L1D",           PERF_COUNT_HW_CACHE_L1D },
-       { "COUNT_HW_CACHE_L1I",           PERF_COUNT_HW_CACHE_L1I },
-       { "COUNT_HW_CACHE_LL",            PERF_COUNT_HW_CACHE_LL },
-       { "COUNT_HW_CACHE_DTLB",          PERF_COUNT_HW_CACHE_DTLB },
-       { "COUNT_HW_CACHE_ITLB",          PERF_COUNT_HW_CACHE_ITLB },
-       { "COUNT_HW_CACHE_BPU",           PERF_COUNT_HW_CACHE_BPU },
-       { "COUNT_HW_CACHE_OP_READ",       PERF_COUNT_HW_CACHE_OP_READ },
-       { "COUNT_HW_CACHE_OP_WRITE",      PERF_COUNT_HW_CACHE_OP_WRITE },
-       { "COUNT_HW_CACHE_OP_PREFETCH",   PERF_COUNT_HW_CACHE_OP_PREFETCH },
-       { "COUNT_HW_CACHE_RESULT_ACCESS", PERF_COUNT_HW_CACHE_RESULT_ACCESS },
-       { "COUNT_HW_CACHE_RESULT_MISS",   PERF_COUNT_HW_CACHE_RESULT_MISS },
-
-       { "COUNT_HW_STALLED_CYCLES_FRONTEND",     PERF_COUNT_HW_STALLED_CYCLES_FRONTEND },
-       { "COUNT_HW_STALLED_CYCLES_BACKEND",      PERF_COUNT_HW_STALLED_CYCLES_BACKEND },
-
-       { "COUNT_SW_CPU_CLOCK",        PERF_COUNT_SW_CPU_CLOCK },
-       { "COUNT_SW_TASK_CLOCK",       PERF_COUNT_SW_TASK_CLOCK },
-       { "COUNT_SW_PAGE_FAULTS",      PERF_COUNT_SW_PAGE_FAULTS },
-       { "COUNT_SW_CONTEXT_SWITCHES", PERF_COUNT_SW_CONTEXT_SWITCHES },
-       { "COUNT_SW_CPU_MIGRATIONS",   PERF_COUNT_SW_CPU_MIGRATIONS },
-       { "COUNT_SW_PAGE_FAULTS_MIN",  PERF_COUNT_SW_PAGE_FAULTS_MIN },
-       { "COUNT_SW_PAGE_FAULTS_MAJ",  PERF_COUNT_SW_PAGE_FAULTS_MAJ },
-       { "COUNT_SW_ALIGNMENT_FAULTS", PERF_COUNT_SW_ALIGNMENT_FAULTS },
-       { "COUNT_SW_EMULATION_FAULTS", PERF_COUNT_SW_EMULATION_FAULTS },
-       { "COUNT_SW_DUMMY",            PERF_COUNT_SW_DUMMY },
-
-       { "SAMPLE_IP",        PERF_SAMPLE_IP },
-       { "SAMPLE_TID",       PERF_SAMPLE_TID },
-       { "SAMPLE_TIME",      PERF_SAMPLE_TIME },
-       { "SAMPLE_ADDR",      PERF_SAMPLE_ADDR },
-       { "SAMPLE_READ",      PERF_SAMPLE_READ },
-       { "SAMPLE_CALLCHAIN", PERF_SAMPLE_CALLCHAIN },
-       { "SAMPLE_ID",        PERF_SAMPLE_ID },
-       { "SAMPLE_CPU",       PERF_SAMPLE_CPU },
-       { "SAMPLE_PERIOD",    PERF_SAMPLE_PERIOD },
-       { "SAMPLE_STREAM_ID", PERF_SAMPLE_STREAM_ID },
-       { "SAMPLE_RAW",       PERF_SAMPLE_RAW },
-
-       { "FORMAT_TOTAL_TIME_ENABLED", PERF_FORMAT_TOTAL_TIME_ENABLED },
-       { "FORMAT_TOTAL_TIME_RUNNING", PERF_FORMAT_TOTAL_TIME_RUNNING },
-       { "FORMAT_ID",                 PERF_FORMAT_ID },
-       { "FORMAT_GROUP",              PERF_FORMAT_GROUP },
-
-       { "RECORD_MMAP",       PERF_RECORD_MMAP },
-       { "RECORD_LOST",       PERF_RECORD_LOST },
-       { "RECORD_COMM",       PERF_RECORD_COMM },
-       { "RECORD_EXIT",       PERF_RECORD_EXIT },
-       { "RECORD_THROTTLE",   PERF_RECORD_THROTTLE },
-       { "RECORD_UNTHROTTLE", PERF_RECORD_UNTHROTTLE },
-       { "RECORD_FORK",       PERF_RECORD_FORK },
-       { "RECORD_READ",       PERF_RECORD_READ },
-       { "RECORD_SAMPLE",     PERF_RECORD_SAMPLE },
+       PERF_CONST(TYPE_HARDWARE),
+       PERF_CONST(TYPE_SOFTWARE),
+       PERF_CONST(TYPE_TRACEPOINT),
+       PERF_CONST(TYPE_HW_CACHE),
+       PERF_CONST(TYPE_RAW),
+       PERF_CONST(TYPE_BREAKPOINT),
+
+       PERF_CONST(COUNT_HW_CPU_CYCLES),
+       PERF_CONST(COUNT_HW_INSTRUCTIONS),
+       PERF_CONST(COUNT_HW_CACHE_REFERENCES),
+       PERF_CONST(COUNT_HW_CACHE_MISSES),
+       PERF_CONST(COUNT_HW_BRANCH_INSTRUCTIONS),
+       PERF_CONST(COUNT_HW_BRANCH_MISSES),
+       PERF_CONST(COUNT_HW_BUS_CYCLES),
+       PERF_CONST(COUNT_HW_CACHE_L1D),
+       PERF_CONST(COUNT_HW_CACHE_L1I),
+       PERF_CONST(COUNT_HW_CACHE_LL),
+       PERF_CONST(COUNT_HW_CACHE_DTLB),
+       PERF_CONST(COUNT_HW_CACHE_ITLB),
+       PERF_CONST(COUNT_HW_CACHE_BPU),
+       PERF_CONST(COUNT_HW_CACHE_OP_READ),
+       PERF_CONST(COUNT_HW_CACHE_OP_WRITE),
+       PERF_CONST(COUNT_HW_CACHE_OP_PREFETCH),
+       PERF_CONST(COUNT_HW_CACHE_RESULT_ACCESS),
+       PERF_CONST(COUNT_HW_CACHE_RESULT_MISS),
+
+       PERF_CONST(COUNT_HW_STALLED_CYCLES_FRONTEND),
+       PERF_CONST(COUNT_HW_STALLED_CYCLES_BACKEND),
+
+       PERF_CONST(COUNT_SW_CPU_CLOCK),
+       PERF_CONST(COUNT_SW_TASK_CLOCK),
+       PERF_CONST(COUNT_SW_PAGE_FAULTS),
+       PERF_CONST(COUNT_SW_CONTEXT_SWITCHES),
+       PERF_CONST(COUNT_SW_CPU_MIGRATIONS),
+       PERF_CONST(COUNT_SW_PAGE_FAULTS_MIN),
+       PERF_CONST(COUNT_SW_PAGE_FAULTS_MAJ),
+       PERF_CONST(COUNT_SW_ALIGNMENT_FAULTS),
+       PERF_CONST(COUNT_SW_EMULATION_FAULTS),
+       PERF_CONST(COUNT_SW_DUMMY),
+
+       PERF_CONST(SAMPLE_IP),
+       PERF_CONST(SAMPLE_TID),
+       PERF_CONST(SAMPLE_TIME),
+       PERF_CONST(SAMPLE_ADDR),
+       PERF_CONST(SAMPLE_READ),
+       PERF_CONST(SAMPLE_CALLCHAIN),
+       PERF_CONST(SAMPLE_ID),
+       PERF_CONST(SAMPLE_CPU),
+       PERF_CONST(SAMPLE_PERIOD),
+       PERF_CONST(SAMPLE_STREAM_ID),
+       PERF_CONST(SAMPLE_RAW),
+
+       PERF_CONST(FORMAT_TOTAL_TIME_ENABLED),
+       PERF_CONST(FORMAT_TOTAL_TIME_RUNNING),
+       PERF_CONST(FORMAT_ID),
+       PERF_CONST(FORMAT_GROUP),
+
+       PERF_CONST(RECORD_MMAP),
+       PERF_CONST(RECORD_LOST),
+       PERF_CONST(RECORD_COMM),
+       PERF_CONST(RECORD_EXIT),
+       PERF_CONST(RECORD_THROTTLE),
+       PERF_CONST(RECORD_UNTHROTTLE),
+       PERF_CONST(RECORD_FORK),
+       PERF_CONST(RECORD_READ),
+       PERF_CONST(RECORD_SAMPLE),
        { .name = NULL, },
 };