]> git.feebdaed.xyz Git - 0xmirror/libreswan.git/commitdiff
timing: replace pri_cpu_usage() with jam_cpu_usage()
authorAndrew Cagney <cagney@gnu.org>
Tue, 16 Dec 2025 23:13:47 +0000 (18:13 -0500)
committerAndrew Cagney <cagney@gnu.org>
Wed, 17 Dec 2025 14:13:17 +0000 (09:13 -0500)
include/cputime.h
lib/libswan/cputime.c
lib/libswan/verbose.c
programs/pluto/pluto_timing.c
programs/pluto/state.c

index d6d149635c669a117b5a2d63faec027ef2ec935f..2ca3c66d74c8dcbb57016e727aaa5a4d3fad9c0a 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <time.h>              /* for struct timespec */
 
+struct jambuf;
+
 /*
  * Try to format all cpu usage messaages the same.  All delta-times
  * use double and are in seconds.
@@ -34,8 +36,7 @@ struct cpu_usage {
        double wall_seconds;
 };
 
-#define PRI_CPU_USAGE "spent %.3g (%.3g) milliseconds"
-#define pri_cpu_usage(C) ((C).thread_seconds * 1000), ((C).wall_seconds * 1000)
+size_t jam_cpu_usage(struct jambuf *buf, struct cpu_usage usage);
 
 #define cpu_usage_add(TOTAL, USAGE)                                    \
        {                                                               \
index c24ff1a4e9ad611bd0f4d38999ac400b89ffe3c6..c52f1e35bbebfe6baa0ef182ce4d576b67163f82 100644 (file)
@@ -70,3 +70,10 @@ struct cpu_usage cputime_stop(const cputime_t start)
        cputime_t stop = cputime_start();
        return cputime_sub(stop, start);
 }
+
+size_t jam_cpu_usage(struct jambuf *buf, struct cpu_usage usage)
+{
+       return jam(buf, "spent %.3g (%.3g) milliseconds",
+                  usage.thread_seconds * 1000,
+                  usage.wall_seconds * 1000);
+}
index 1112f40347dcce004f22d9af6b6f5a9744618399..fc875e741018225b5e73696632646341f60d0927 100644 (file)
@@ -56,7 +56,8 @@ struct cpu_usage vdbg_stop_where(struct verbose *verbose,
                usage = cputime_stop(start->time);
                LLOG_JAMBUF(DEBUG_STREAM, verbose->logger, buf) {
                        jam_vtime_prefix(buf, verbose);
-                       jam(buf, PRI_CPU_USAGE" in ", pri_cpu_usage(usage));
+                       jam_cpu_usage(buf, usage);
+                       jam_string(buf, " in ");
                        /* FMT, ... */
                        va_list ap;
                        va_start(ap, fmt);
index 0d60ae3bfcd726b2e1b0442dcaad9fa6bb39f30a..6eb3172b48c7db6aa2d1e55d444ff177263e9113 100644 (file)
@@ -37,7 +37,8 @@ void threadtime_stop(const threadtime_t *start, const char *fmt, ...)
        if (LDBGP(DBG_CPU_USAGE, logger)) {
                struct cpu_usage usage = cputime_stop(*start);
                LLOG_JAMBUF(DEBUG_STREAM, logger, buf) {
-                       jam(buf, PRI_CPU_USAGE" in ", pri_cpu_usage(usage));
+                       jam_cpu_usage(buf, usage);
+                       jam_string(buf, " in ");
                        va_list ap;
                        va_start(ap, fmt);
                        jam_va_list(buf, fmt, ap);
@@ -68,7 +69,8 @@ struct cpu_usage logtime_stop(const logtime_t *start, const char *fmt, ...)
                                jam_string(buf, INDENT INDENT);
                        }
                        jam_logger_prefix(buf, start->logger);
-                       jam(buf, PRI_CPU_USAGE" in ", pri_cpu_usage(usage));
+                       jam_cpu_usage(buf, usage);
+                       jam_string(buf, " in ");
                        va_list ap;
                        va_start(ap, fmt);
                        jam_va_list(buf, fmt, ap);
@@ -98,7 +100,8 @@ static void DBG_missing(const statetime_t *start, cputime_t now,
                                jam_string(buf, INDENT INDENT);
                        }
                        jam_so(buf, start->so);
-                       jam(buf, " "PRI_CPU_USAGE, pri_cpu_usage(missing));
+                       jam_string(buf, " ");
+                       jam_cpu_usage(buf, missing);
                }
        }
 }
@@ -220,7 +223,9 @@ void statetime_stop(const statetime_t *start, const char *fmt, ...)
                                jam_string(buf, INDENT INDENT);
                        }
                        jam_so(buf, st->st_serialno);
-                       jam(buf, " "PRI_CPU_USAGE" in ", pri_cpu_usage(usage));
+                       jam_string(buf, " ");
+                       jam_cpu_usage(buf, usage);
+                       jam_string(buf," in ");
                        va_list ap;
                        va_start(ap, fmt);
                        jam_va_list(buf, fmt, ap);
index 92ca183462490eb83b45d5b0bf7fce37cf40b30d..fbba601b7f2ce2b30a60b05ed80a704a821b14ca 100644 (file)
@@ -913,11 +913,16 @@ void delete_state(struct state *st)
         * it when debugging - values range from very approximate to
         * (in the case of IKEv1) simply wrong.
         */
-       if (LDBGP(DBG_CPU_USAGE, st->logger) || LDBGP(DBG_BASE, st->logger)) {
-               LDBG_log(st->logger, PRI_SO" main thread "PRI_CPU_USAGE" helper thread "PRI_CPU_USAGE" in total",
-                        pri_so(st->st_serialno),
-                        pri_cpu_usage(st->st_timing.main_usage),
-                        pri_cpu_usage(st->st_timing.helper_usage));
+       if (LDBGP(DBG_CPU_USAGE, st->logger) ||
+           LDBGP(DBG_BASE, st->logger)) {
+               LLOG_JAMBUF(DEBUG_STREAM, st->logger, buf) {
+                       jam_so(buf, st->st_serialno);
+                       jam_string(buf, " main thread ");
+                       jam_cpu_usage(buf, st->st_timing.main_usage);
+                       jam_string(buf, " helper thread ");
+                       jam_cpu_usage(buf, st->st_timing.helper_usage);
+                       jam_string(buf, " in total");
+               }
        }
 
        /*