1*3ce311afSJiri Olsa // SPDX-License-Identifier: GPL-2.0-only 2*3ce311afSJiri Olsa 3*3ce311afSJiri Olsa #define __printf(a, b) __attribute__((format(printf, a, b))) 4*3ce311afSJiri Olsa 5*3ce311afSJiri Olsa #include <stdio.h> 6*3ce311afSJiri Olsa #include <stdarg.h> 7*3ce311afSJiri Olsa #include <unistd.h> 8*3ce311afSJiri Olsa #include <linux/compiler.h> 9*3ce311afSJiri Olsa #include <perf/core.h> 10*3ce311afSJiri Olsa #include <internal/lib.h> 11*3ce311afSJiri Olsa #include "internal.h" 12*3ce311afSJiri Olsa 13*3ce311afSJiri Olsa static int __base_pr(enum libperf_print_level level __maybe_unused, const char *format, 14*3ce311afSJiri Olsa va_list args) 15*3ce311afSJiri Olsa { 16*3ce311afSJiri Olsa return vfprintf(stderr, format, args); 17*3ce311afSJiri Olsa } 18*3ce311afSJiri Olsa 19*3ce311afSJiri Olsa static libperf_print_fn_t __libperf_pr = __base_pr; 20*3ce311afSJiri Olsa 21*3ce311afSJiri Olsa __printf(2, 3) 22*3ce311afSJiri Olsa void libperf_print(enum libperf_print_level level, const char *format, ...) 23*3ce311afSJiri Olsa { 24*3ce311afSJiri Olsa va_list args; 25*3ce311afSJiri Olsa 26*3ce311afSJiri Olsa if (!__libperf_pr) 27*3ce311afSJiri Olsa return; 28*3ce311afSJiri Olsa 29*3ce311afSJiri Olsa va_start(args, format); 30*3ce311afSJiri Olsa __libperf_pr(level, format, args); 31*3ce311afSJiri Olsa va_end(args); 32*3ce311afSJiri Olsa } 33*3ce311afSJiri Olsa 34*3ce311afSJiri Olsa void libperf_init(libperf_print_fn_t fn) 35*3ce311afSJiri Olsa { 36*3ce311afSJiri Olsa page_size = sysconf(_SC_PAGE_SIZE); 37*3ce311afSJiri Olsa __libperf_pr = fn; 38*3ce311afSJiri Olsa } 39