summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
299dc8f)
Samba (for example) uses a DEBUG() macro, which triggers these heuristics.
Better to make it per-module anyway.
#include <string.h>
#include <ccan/compiler/compiler.h>
#include <assert.h>
#include <string.h>
#include <ccan/compiler/compiler.h>
#include <assert.h>
#include <stdio.h>
#endif
#include <stdio.h>
#endif
const char *errstr;
/* Used if !NDEBUG */
int num_accesses;
const char *errstr;
/* Used if !NDEBUG */
int num_accesses;
+ /* Used if CCAN_JMAP_DEBUG */
unsigned long *acc_value;
unsigned long acc_index;
const char *funcname;
unsigned long *acc_value;
unsigned long acc_index;
const char *funcname;
unsigned long *val,
const char *funcname)
{
unsigned long *val,
const char *funcname)
{
if (!map->acc_value) {
((struct jmap *)map)->acc_value = val;
((struct jmap *)map)->acc_index = index;
if (!map->acc_value) {
((struct jmap *)map)->acc_value = val;
((struct jmap *)map)->acc_index = index;
static inline void jmap_debug_del_access(struct jmap *map, unsigned long **val)
{
assert(--map->num_accesses >= 0);
static inline void jmap_debug_del_access(struct jmap *map, unsigned long **val)
{
assert(--map->num_accesses >= 0);
if (map->acc_value == *val)
map->acc_value = NULL;
#endif
if (map->acc_value == *val)
map->acc_value = NULL;
#endif
static inline void jmap_debug_access(struct jmap *map)
{
static inline void jmap_debug_access(struct jmap *map)
{
if (map->num_accesses && map->acc_value)
fprintf(stderr,
"jmap: still got index %lu, val %lu (%p) from %s\n",
if (map->num_accesses && map->acc_value)
fprintf(stderr,
"jmap: still got index %lu, val %lu (%p) from %s\n",
#include <ccan/tap/tap.h>
#include <ccan/tap/tap.h>
#include <ccan/jmap/jmap.c>
int main(int argc, char *argv[])
#include <ccan/jmap/jmap.c>
int main(int argc, char *argv[])
+#ifdef CCAN_LIKELY_DEBUG
#include <ccan/likely/likely.h>
#include <ccan/hash/hash.h>
#include <ccan/htable/htable.h>
#include <ccan/likely/likely.h>
#include <ccan/hash/hash.h>
#include <ccan/htable/htable.h>
+#endif /*CCAN_LIKELY_DEBUG*/
#include <ccan/str/str.h>
#include <stdbool.h>
#include <ccan/str/str.h>
#include <stdbool.h>
+#ifndef CCAN_LIKELY_DEBUG
#if HAVE_BUILTIN_EXPECT
/**
* likely - indicate that a condition is likely to be true.
#if HAVE_BUILTIN_EXPECT
/**
* likely - indicate that a condition is likely to be true.
#define likely(cond) (!!(cond))
#define unlikely(cond) (!!(cond))
#endif
#define likely(cond) (!!(cond))
#define unlikely(cond) (!!(cond))
#endif
-#else /* DEBUG versions */
+#else /* CCAN_LIKELY_DEBUG versions */
#define likely(cond) \
(_likely_trace(!!(cond), 1, stringify(cond), __FILE__, __LINE__))
#define unlikely(cond) \
#define likely(cond) \
(_likely_trace(!!(cond), 1, stringify(cond), __FILE__, __LINE__))
#define unlikely(cond) \
const char *file, unsigned int line);
#endif
const char *file, unsigned int line);
#endif
+#ifdef CCAN_LIKELY_DEBUG
/**
* likely_stats - return description of abused likely()/unlikely()
* @min_hits: minimum number of hits
* @percent: maximum percentage correct
*
/**
* likely_stats - return description of abused likely()/unlikely()
* @min_hits: minimum number of hits
* @percent: maximum percentage correct
*
- * When DEBUG is defined, likely() and unlikely() trace their results: this
- * causes a significant slowdown, but allows analysis of whether the stats
- * are correct.
+ * When CCAN_LIKELY_DEBUG is defined, likely() and unlikely() trace their
+ * results: this causes a significant slowdown, but allows analysis of
+ * whether the branches are labelled correctly.
*
* This function returns a malloc'ed description of the least-correct
* usage of likely() or unlikely(). It ignores places which have been
*
* This function returns a malloc'ed description of the least-correct
* usage of likely() or unlikely(). It ignores places which have been
* // Print every place hit more than twice which was wrong > 5%.
* static void report_stats(void)
* {
* // Print every place hit more than twice which was wrong > 5%.
* static void report_stats(void)
* {
+ * #ifdef CCAN_LIKELY_DEBUG
* const char *bad;
*
* while ((bad = likely_stats(2, 95)) != NULL) {
* const char *bad;
*
* while ((bad = likely_stats(2, 95)) != NULL) {
* }
*/
const char *likely_stats(unsigned int min_hits, unsigned int percent);
* }
*/
const char *likely_stats(unsigned int min_hits, unsigned int percent);
+#endif /* CCAN_LIKELY_DEBUG */
#endif /* CCAN_LIKELY_H */
#endif /* CCAN_LIKELY_H */
+#define CCAN_LIKELY_DEBUG 1
#include <ccan/likely/likely.c>
#include <ccan/likely/likely.h>
#include <ccan/tap/tap.h>
#include <ccan/likely/likely.c>
#include <ccan/likely/likely.h>
#include <ccan/tap/tap.h>
off = frec_prev(r) + offsetof(struct tdb_free_record, next);
}
off = frec_prev(r) + offsetof(struct tdb_free_record, next);
}
if (tdb_read_off(tdb, off) != r_off) {
tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
"remove_from_list: %llu bad prev in list %llu",
if (tdb_read_off(tdb, off) != r_off) {
tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
"remove_from_list: %llu bad prev in list %llu",
off = r->next + offsetof(struct tdb_free_record,magic_and_prev);
/* r->next->prev = r->prev */
off = r->next + offsetof(struct tdb_free_record,magic_and_prev);
/* r->next->prev = r->prev */
if (tdb_read_off(tdb, off) & TDB_OFF_MASK != r_off) {
tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
"remove_from_list: %llu bad list %llu",
if (tdb_read_off(tdb, off) & TDB_OFF_MASK != r_off) {
tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
"remove_from_list: %llu bad list %llu",
return -1;
if (new.next) {
return -1;
if (new.next) {
if (tdb_read_off(tdb,
new.next + offsetof(struct tdb_free_record,
magic_and_prev))
if (tdb_read_off(tdb,
new.next + offsetof(struct tdb_free_record,
magic_and_prev))