File: fix-mem_log-for-32-bit.patch

package info (click to toggle)
charliecloud 0.42-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,076 kB
  • sloc: python: 5,975; sh: 4,282; ansic: 3,818; makefile: 597
file content (91 lines) | stat: -rw-r--r-- 3,540 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From: Jordan Ogas <jogas@lanl.gov>
Date: Thu, 16 Oct 2025 16:29:19 -0600
Subject: fix mem_log for 32-bit

Origin: https://gitlab.com/charliecloud/charliecloud/-/merge_requests/1989
---
 bin/mem.c | 47 +++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/bin/mem.c b/bin/mem.c
index 0da4b95..5c8787a 100644
--- a/bin/mem.c
+++ b/bin/mem.c
@@ -258,7 +258,9 @@ void mem_log(const char *when)
 #ifdef HAVE_GC
    struct GC_prof_stats_s ps;
    ssize_t used, used_prev;
-   long time_collecting;
+   long time_collecting; // ms (matches %ld)
+   static unsigned long s_gc_no_prev = 0;
+   static long          s_time_collecting_prev = 0;  // ms
 #endif
 
    /* Compute stack, heap, and anonymous mapping sizes. While awkward, AFAICT
@@ -284,11 +286,11 @@ void mem_log(const char *when)
          break;
       }
       if (strlen(path) == 0)
-         anon_len += end - start;
+         anon_len += (char*)end - (char*)start;
       else if (streq(path, "[stack]"))
-         stack_len += end - start;
+         stack_len += (char*)end - (char*)start;
       else if (streq(path, "[heap]"))
-         heap_len += end - start;
+         heap_len += (char*)end - (char*)start;
    }
    Z_e (fclose(fp));
 
@@ -313,32 +315,33 @@ void mem_log(const char *when)
    // log GC stuff
 #ifdef HAVE_GC
    GC_get_prof_stats(&ps, sizeof(ps));
-   time_collecting = GC_get_full_gc_total_time();
-   // space
-   used = ps.heapsize_full - ps.free_bytes_full;
-   used_prev = heapsize_prev - free_prev;
+   time_collecting = (long)GC_get_full_gc_total_time();  // ms
+   used = (ssize_t)(ps.heapsize_full - ps.free_bytes_full);
+   used_prev = (ssize_t)(heapsize_prev - free_prev);
+
    s = asprintf_ch("gc:  %s: "
          "%zdkB %+zd (used %zdkB %+zd, free %zdkB %+zd, unmp %zdkB %+zd)",
          when,
-         kB(ps.heapsize_full), kB(ps.heapsize_full - heapsize_prev),
-         kB(used), kB(used - used_prev),
-         kB(ps.free_bytes_full), kB(ps.free_bytes_full - free_prev),
-         kB(ps.unmapped_bytes), kB(ps.unmapped_bytes - unmapped_prev));
-   heapsize_prev = ps.heapsize_full;
-   free_prev = ps.free_bytes_full;
-   unmapped_prev = ps.unmapped_bytes;
+         kB(ps.heapsize_full),   kB((ssize_t)ps.heapsize_full - (ssize_t)heapsize_prev),
+         kB(used),               kB(used - used_prev),
+         kB(ps.free_bytes_full), kB((ssize_t)ps.free_bytes_full - (ssize_t)free_prev),
+         kB(ps.unmapped_bytes),  kB((ssize_t)ps.unmapped_bytes - (ssize_t)unmapped_prev));
+   heapsize_prev   = ps.heapsize_full;
+   free_prev       = ps.free_bytes_full;
+   unmapped_prev   = ps.unmapped_bytes;
    DEBUG("%s", s);
 #ifdef ENABLE_SYSLOG
    syslog(SYSLOG_PRI, "%s", s);
 #endif
-   // time
-   s = asprintf_ch("gc:  "
-         "%s: %ld collections (%+ld) in %zdms (%+zd)",
+   // time — use %lu for absolute (unsigned long), %+ld for signed delta, %ld for ms
+   s = asprintf_ch("gc:  %s: %lu collections (%+ld) in %ldms (%+ld)",
          when,
-         ps.gc_no, ps.gc_no - gc_no_prev,
-         time_collecting, time_collecting - time_collecting_prev);
-   gc_no_prev = ps.gc_no;
-   time_collecting_prev = time_collecting;
+         (unsigned long)ps.gc_no,
+         (long)((long)ps.gc_no - (long)s_gc_no_prev),
+         time_collecting,
+         time_collecting - s_time_collecting_prev);
+   s_gc_no_prev = (unsigned long)ps.gc_no;
+   s_time_collecting_prev = time_collecting;
    DEBUG("%s", s);
 #ifdef ENABLE_SYSLOG
    syslog(SYSLOG_PRI, "%s", s);