]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: memprof: export the minimum definitions for memory profiling
authorWilly Tarreau <w@1wt.eu>
Wed, 17 Aug 2022 06:53:36 +0000 (08:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 17 Aug 2022 07:03:57 +0000 (09:03 +0200)
Right now it's not possible to feed memory profiling info from outside
activity.c, so let's export the function and move the enum and struct
to the include file.

include/haproxy/activity-t.h
include/haproxy/activity.h
src/activity.c

index 63779ff9ab19d8ecfc8f1f2a9ce1a9ff743fbd43..f21f8057c01ba790bc0e17912eec3b93b707fbca 100644 (file)
 
 #define HA_PROF_MEMORY      0x00000004     /* memory profiling */
 
+
+#ifdef USE_MEMORY_PROFILING
+/* Elements used by memory profiling. This determines the number of buckets to
+ * store stats.
+ */
+#define MEMPROF_HASH_BITS 10
+#define MEMPROF_HASH_BUCKETS (1U << MEMPROF_HASH_BITS)
+
+enum memprof_method {
+       MEMPROF_METH_UNKNOWN = 0,
+       MEMPROF_METH_MALLOC,
+       MEMPROF_METH_CALLOC,
+       MEMPROF_METH_REALLOC,
+       MEMPROF_METH_FREE,
+       MEMPROF_METH_METHODS /* count, must be last */
+};
+
+/* stats:
+ *   - malloc increases alloc
+ *   - free increases free (if non null)
+ *   - realloc increases either depending on the size change.
+ * when the real size is known (malloc_usable_size()), it's used in free_tot
+ * and alloc_tot, otherwise the requested size is reported in alloc_tot and
+ * zero in free_tot.
+ */
+struct memprof_stats {
+       const void *caller;
+       enum memprof_method method;
+       /* 4-7 bytes hole here */
+       unsigned long long alloc_calls;
+       unsigned long long free_calls;
+       unsigned long long alloc_tot;
+       unsigned long long free_tot;
+};
+#endif
+
 /* per-thread activity reports. It's important that it's aligned on cache lines
  * because some elements will be updated very often. Most counters are OK on
  * 32-bit since this will be used during debugging sessions for troubleshooting
index 0c5727ba9819ff479e28225d7f621d4c27f1c677..383e1ee0984b36d7a81087f7898e63bc1a15d793 100644 (file)
@@ -33,6 +33,10 @@ void report_stolen_time(uint64_t stolen);
 void activity_count_runtime(uint32_t run_time);
 struct sched_activity *sched_activity_entry(struct sched_activity *array, const void *func);
 
+#ifdef USE_MEMORY_PROFILING
+struct memprof_stats *memprof_get_bin(const void *ra, enum memprof_method meth);
+#endif
+
 #endif /* _HAPROXY_ACTIVITY_H */
 
 /*
index ff9effbde3744583b0b8d73069e8bf2148033b4b..c020f24d26a3e8904b63c6913b33ff11bfbaf63e 100644 (file)
@@ -51,41 +51,11 @@ struct sched_activity sched_activity[256] __attribute__((aligned(64))) = { };
 
 
 #ifdef USE_MEMORY_PROFILING
-/* determine the number of buckets to store stats */
-#define MEMPROF_HASH_BITS 10
-#define MEMPROF_HASH_BUCKETS (1U << MEMPROF_HASH_BITS)
-
-enum memprof_method {
-       MEMPROF_METH_UNKNOWN = 0,
-       MEMPROF_METH_MALLOC,
-       MEMPROF_METH_CALLOC,
-       MEMPROF_METH_REALLOC,
-       MEMPROF_METH_FREE,
-       MEMPROF_METH_METHODS /* count, must be last */
-};
 
 static const char *const memprof_methods[MEMPROF_METH_METHODS] = {
        "unknown", "malloc", "calloc", "realloc", "free",
 };
 
-/* stats:
- *   - malloc increases alloc
- *   - free increases free (if non null)
- *   - realloc increases either depending on the size change.
- * when the real size is known (malloc_usable_size()), it's used in free_tot
- * and alloc_tot, otherwise the requested size is reported in alloc_tot and
- * zero in free_tot.
- */
-struct memprof_stats {
-       const void *caller;
-       enum memprof_method method;
-       /* 4-7 bytes hole here */
-       unsigned long long alloc_calls;
-       unsigned long long free_calls;
-       unsigned long long alloc_tot;
-       unsigned long long free_tot;
-};
-
 /* last one is for hash collisions ("others") and has no caller address */
 struct memprof_stats memprof_stats[MEMPROF_HASH_BUCKETS + 1] = { };
 
@@ -210,7 +180,7 @@ static void  memprof_free_initial_handler(void *ptr)
  * case, returns a default bin). The caller address is atomically set except
  * for the default one which is never set.
  */
-static struct memprof_stats *memprof_get_bin(const void *ra, enum memprof_method meth)
+struct memprof_stats *memprof_get_bin(const void *ra, enum memprof_method meth)
 {
        int retries = 16; // up to 16 consecutive entries may be tested.
        const void *old;