From 910bbb6f447e5faced32c63e56d6600fe9ced0a9 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 1 Dec 2015 23:23:33 +0100 Subject: [PATCH 01/10] UTIL: Add a PROBE macro into probes.h The macros are inspired by very similar macros in libvirt code. Adds a macro PROBE that can be used by SSSD developers to add systemtap marks to code. These marks, when coupled with a location in a binary can be in turn used to call probes. The mark can be called like this: PROBE(PROBE_NAME, arguments) This is cleaner than using the SSSD_$(PROBE_NAME) directly as it directly shows that a probe is being called at that place. If the systemtap tracing is disabled, they would expand to an empty macro. If the systemtap tracing is enabled, the systemtap probe will be called. The overhead of calling the probes is close to zero. As one of the systemtap developers explained to me: """ STAP_PROBE() macros cost apprx. one nop in the executable, so apprx. no cost at all. The more the merrier. Only when activated by a stap script do we generally think of it like a microsecond of time. """ The probe arguments can be used in the probes to be printed or passed on to functions. There was an issue in case a string argument was NULL. This commit adds a helper macro to deal with NULL-strings as if they were empty (""). This file would be included by any source file that wants to call the PROBE() macro. --- Makefile.am | 1 + src/util/probes.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/util/probes.h diff --git a/Makefile.am b/Makefile.am index a504a4f613b881afcbc096a03de0f284ebf34896..eb4ea65fad6ff1adb3d1e31b801a48feed194115 100644 --- a/Makefile.am +++ b/Makefile.am @@ -682,6 +682,7 @@ dist_noinst_HEADERS = \ src/tests/cmocka/test_utils.h \ src/tools/common/sss_tools.h \ src/tools/common/sss_colondb.h \ + src/util/probes.h \ $(NULL) diff --git a/src/util/probes.h b/src/util/probes.h new file mode 100644 index 0000000000000000000000000000000000000000..349f29086e86a51b4551f09f542d0f45bf6f1aae --- /dev/null +++ b/src/util/probes.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2015 Red Hat + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __PROBES_H_ +#define __PROBES_H_ + +#ifdef HAVE_SYSTEMTAP + +/* Probe expansion inspired by libvirt */ +#define PROBE_EXPAND(NAME, ...) NAME(__VA_ARGS__) + +#define PROBE(NAME, ...) do { \ + if (SSSD_ ## NAME ## _ENABLED()) { \ + PROBE_EXPAND(SSSD_ ## NAME, \ + __VA_ARGS__); \ + } \ +} while(0); + +/* Systemtap doesn't handle copying NULL strings well */ +#define PROBE_SAFE_STR(s) ((s) ? (s) : "") + +#else + +/* No systemtap, define empty macros */ +#define PROBE(NAME, ...) do { \ +} while(0); + +#endif + +#endif /* __PROBES_H_ */ -- 2.4.11