Skip to content

Commit

Permalink
test accessrecorder with leaky code, fixes #45
Browse files Browse the repository at this point in the history
  • Loading branch information
ahueck committed Dec 30, 2020
1 parent 785b67e commit a4c0405
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/runtime/AccessCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class AccessRecorder {

inline void incHeapAlloc(int typeId, size_t count) {
++curHeapAllocs;

// Always check here for max
// A program without free would otherwise never update maxHeap (see test 20_softcounter_max)
if (curHeapAllocs > maxHeapAllocs) {
maxHeapAllocs = curHeapAllocs;
}

++heapAllocs;
if (count > 1) {
++heapArray;
Expand Down Expand Up @@ -72,9 +79,10 @@ class AccessRecorder {
}

inline void decHeapAlloc() {
if (curHeapAllocs > maxHeapAllocs) {
maxHeapAllocs = curHeapAllocs;
}
// Removed, since we already increment maxHeapAllocs just in time:
// if (curHeapAllocs > maxHeapAllocs) {
// maxHeapAllocs = curHeapAllocs;
// }
--curHeapAllocs;
}

Expand Down
38 changes: 38 additions & 0 deletions test/runtime/19_softcounter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: %run %s -o -O3 2>&1 | FileCheck %s
// REQUIRED: softcounter

#include <stdlib.h>

int main(void) {
for (int i = 1; i <= 5; ++i) {
// 5 heap alloc and free: one single double, and then arrays
// max heap (concurrently) 1
double* d = (double*)malloc(i * sizeof(double));
free(d);
}
return 0;
}

// CHECK: Alloc Stats from softcounters
// CHECK-NEXT: Total heap : 5 , 4 , -
// CHECK-NEXT: Total stack : 0 , 0 , -
// CHECK-NEXT: Total global : 0 , 0 , -
// CHECK-NEXT: Max. Heap Allocs : 1 , - , -
// CHECK-NEXT: Max. Stack Allocs : 0 , - , -
// CHECK-NEXT: Addresses checked : 0 , - , -
// CHECK-NEXT: Distinct Addresses checked : 0 , - , -
// CHECK-NEXT: Addresses re-used : 0 , - , -
// CHECK-NEXT: Addresses missed : 0 , - , -
// CHECK-NEXT: Distinct Addresses missed : 0 , - , -
// CHECK-NEXT: Total free heap : 5 , 4 , -
// CHECK-NEXT: Total free stack : 0 , 0 , -
// CHECK-NEXT: Null/Zero/NullZero Addr : 0 , 0 , 0
// CHECK-NEXT: User-def. types : 0 , - , -
// CHECK-NEXT: Estimated memory use (KiB) : 4 , - , -
// CHECK-NEXT: Bytes per node map/stack : 96 , 8 , -
// CHECK-NEXT: {{(#|-)+}}
// CHECK-NEXT: Allocation type detail (heap, stack, global)
// CHECK-NEXT: 6 : 5 , 0 , 0 , double
// CHECK-NEXT: {{(#|-)+}}
// CHECK-NEXT: Free allocation type detail (heap, stack)
// CHECK-NEXT: 6 : 5 , 0 , double
38 changes: 38 additions & 0 deletions test/runtime/20_softcounter_max.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: %run %s -o -O1 2>&1 | FileCheck %s
// REQUIRED: softcounter

#include <stdlib.h>

int main(void) {
for (int i = 1; i <= 6; ++i) {
// 6 heap alloc
// max heap (concurrently) 6
double* d = (double*)malloc(sizeof(double));
}

return 0;
}

// CHECK: Alloc Stats from softcounters
// CHECK-NEXT: Total heap : 6 , 0 , -
// CHECK-NEXT: Total stack : 0 , 0 , -
// CHECK-NEXT: Total global : 0 , 0 , -
// CHECK-NEXT: Max. Heap Allocs : 6 , - , -
// CHECK-NEXT: Max. Stack Allocs : 0 , - , -
// CHECK-NEXT: Addresses checked : 0 , - , -
// CHECK-NEXT: Distinct Addresses checked : 0 , - , -
// CHECK-NEXT: Addresses re-used : 0 , - , -
// CHECK-NEXT: Addresses missed : 0 , - , -
// CHECK-NEXT: Distinct Addresses missed : 0 , - , -
// CHECK-NEXT: Total free heap : 0 , 0 , -
// CHECK-NEXT: Total free stack : 0 , 0 , -
// CHECK-NEXT: Null/Zero/NullZero Addr : 0 , 0 , 0
// CHECK-NEXT: User-def. types : 0 , - , -
// CHECK-NEXT: Estimated memory use (KiB) : {{[4-9]}} , - , -
// CHECK-NEXT: Bytes per node map/stack : 96 , 8 , -
// CHECK-NEXT: {{(#|-)+}}
// CHECK-NEXT: Allocation type detail (heap, stack, global)
// CHECK-NEXT: 6 : 6 , 0 , 0 , double
// CHECK-NEXT: {{(#|-)+}}
// CHECK-NEXT: Free allocation type detail (heap, stack)
// CHECK-NEXT: 6 : 0 , 0 , double

0 comments on commit a4c0405

Please sign in to comment.