on master help sign in
Merge pull request #1755 from mattias-lundell/master

Make tests work with sandboxes and fix GC statistics overflow

commit6f032cc1b5078e4a46ffcfcde699af7d246b7887 authorEdwin Brady <edwin.brady@gmail.com> dateThu 4 Dec 2014, 19:17 (12 years ago) parente45284564cf120
4 files changed+45−27
rts/idris_gc.c+7−7 rts/idris_stats.c+11−11 rts/idris_stats.h+10−8 test/runtest.pl+17−1
rts/idris_gc.c+7−7
@@ -69,7 +69,7 @@ void cheney(VM *vm) {
6969 int i;
7070 int ar;
7171 char* scan = vm->heap.heap;
72−
72+
7373 while(scan < vm->heap.next) {
7474 size_t inc = *((size_t*)scan);
7575 VAL heap_item = (VAL)(scan+sizeof(size_t));
@@ -85,7 +85,7 @@ void cheney(VM *vm) {
8585 }
8686 break;
8787 case STROFFSET:
88− heap_item->info.str_offset->str
88+ heap_item->info.str_offset->str
8989 = copy(vm, heap_item->info.str_offset->str);
9090 break;
9191 default: // Nothing to copy
@@ -103,7 +103,7 @@ void idris_gc(VM* vm) {
103103
104104 char* newheap = malloc(vm->heap.size);
105105 char* oldheap = vm->heap.heap;
106− if (vm->heap.old != NULL)
106+ if (vm->heap.old != NULL)
107107 free(vm->heap.old);
108108
109109 vm->heap.heap = newheap;
@@ -138,21 +138,21 @@ void idris_gc(VM* vm) {
138138
139139 if ((vm->heap.next - vm->heap.heap) > vm->heap.size >> 1) {
140140 vm->heap.size += vm->heap.growth;
141− }
141+ }
142142 vm->heap.old = oldheap;
143−
143+
144144 STATS_LEAVE_GC(vm->stats, vm->heap.size, vm->heap.next - vm->heap.heap)
145145 HEAP_CHECK(vm)
146146}
147147
148148void idris_gcInfo(VM* vm, int doGC) {
149− printf("Stack: <BOT %p> <TOP %p>\n", vm->valstack, vm->valstack_top);
149+ printf("Stack: <BOT %p> <TOP %p>\n", vm->valstack, vm->valstack_top);
150150 printf("Final heap size %d\n", (int)(vm->heap.size));
151151 printf("Final heap use %d\n", (int)(vm->heap.next - vm->heap.heap));
152152 if (doGC) { idris_gc(vm); }
153153 printf("Final heap use after GC %d\n", (int)(vm->heap.next - vm->heap.heap));
154154#ifdef IDRIS_ENABLE_STATS
155− printf("Total allocations %d\n", vm->stats.allocations);
155+ printf("Total allocations %" PRIu64 "\n", vm->stats.allocations);
156156#endif
157157 printf("Number of collections %d\n", vm->stats.collections);
158158
rts/idris_stats.c+11−11
@@ -10,16 +10,16 @@ void print_stats(const Stats * stats) {
1010 clock_t mut = total - stats->init_time - stats->gc_time - stats->exit_time;
1111 double mut_sec = (double)mut / CLOCKS_PER_SEC;
1212
13− int avg_chunk = 0;
13+ uint64_t avg_chunk = 0;
1414 if (stats->alloc_count > 0) {
15− avg_chunk = (int)((double)stats->allocations / (double)stats->alloc_count);
15+ avg_chunk = (uint64_t)((double)stats->allocations / (double)stats->alloc_count);
1616 }
1717
18− int alloc_rate = 0;
18+ uint64_t alloc_rate = 0;
1919 if (mut > 0) {
20− alloc_rate = (int)((double)(stats->allocations) / mut_sec);
20+ alloc_rate = (uint64_t)((double)(stats->allocations) / mut_sec);
2121 }
22−
22+
2323 double gc_percent = 0.0;
2424 double productivity = 0.0;
2525 if (total > 0) {
@@ -29,11 +29,11 @@ void print_stats(const Stats * stats) {
2929
3030 setlocale(LC_NUMERIC, "");
3131 printf("\n");
32− printf("%'20d bytes allocated in the heap\n", stats->allocations);
33− printf("%'20d bytes copied during GC\n", stats->copied);
34− printf("%'20d maximum heap size\n", stats->max_heap_size);
35− printf("%'20d chunks allocated in the heap\n", stats->alloc_count);
36− printf("%'20d average chunk size\n\n", avg_chunk);
32+ printf("%'20" PRIu64 " bytes allocated in the heap\n", stats->allocations);
33+ printf("%'20" PRIu64 " bytes copied during GC\n", stats->copied);
34+ printf("%'20" PRIu32 " maximum heap size\n", stats->max_heap_size);
35+ printf("%'20" PRIu32 " chunks allocated in the heap\n", stats->alloc_count);
36+ printf("%'20" PRIu64 " average chunk size\n\n", avg_chunk);
3737
3838 printf("GC called %d times\n\n", stats->collections);
3939
@@ -45,7 +45,7 @@ void print_stats(const Stats * stats) {
4545
4646 printf("%%GC time: %.2f%%\n\n", gc_percent);
4747
48− printf("Alloc rate %'d bytes per MUT sec\n\n", alloc_rate);
48+ printf("Alloc rate %'" PRIu64 " bytes per MUT sec\n\n", alloc_rate);
4949
5050 printf("Productivity %.2f%%\n", productivity);
5151}
rts/idris_stats.h+10−8
@@ -3,16 +3,18 @@
33
44#ifdef IDRIS_ENABLE_STATS
55#include <time.h>
6+#include <inttypes.h>
7+#include <stdint.h>
68#endif
79
810
911// TODO: measure user time, exclusive/inclusive stats
1012typedef struct {
1113#ifdef IDRIS_ENABLE_STATS
12− int allocations; // Size of allocated space in bytes for all execution time.
13− int alloc_count; // How many times alloc is called.
14− int copied; // Size of space copied during GC.
15− int max_heap_size; // Maximum heap size achieved.
14+ uint64_t allocations; // Size of allocated space in bytes for all execution time.
15+ uint32_t alloc_count; // How many times alloc is called.
16+ uint64_t copied; // Size of space copied during GC.
17+ uint32_t max_heap_size; // Maximum heap size achieved.
1618
1719 clock_t init_time; // Time spent for vm initialization.
1820 clock_t exit_time; // Time spent for vm termination.
@@ -20,7 +22,7 @@ typedef struct {
2022 clock_t max_gc_pause; // Time spent for longest gc.
2123 clock_t start_time; // Time of rts entry point.
2224#endif // IDRIS_ENABLE_STATS
23− int collections; // How many times gc called.
25+ uint32_t collections; // How many times gc called.
2426} Stats; // without start time it's a monoid, can we remove start_time it somehow?
2527
2628void print_stats(const Stats * stats);
@@ -35,7 +37,7 @@ void aggregate_stats(Stats * stats1, const Stats * stats2);
3537
3638#define STATS_INIT_STATS(stats) \
3739 memset(&stats, 0, sizeof(Stats)); \
38− stats.start_time = clock();
40+ stats.start_time = clock();
3941
4042#define STATS_ALLOC(stats, size) \
4143 stats.allocations += size; \
@@ -60,8 +62,8 @@ void aggregate_stats(Stats * stats1, const Stats * stats2);
6062
6163#else
6264#define STATS_INIT_STATS(stats) memset(&stats, 0, sizeof(Stats));
63−#define STATS_ENTER_INIT(stats)
64−#define STATS_LEAVE_INIT(stats)
65+#define STATS_ENTER_INIT(stats)
66+#define STATS_LEAVE_INIT(stats)
6567#define STATS_ENTER_EXIT(stats)
6668#define STATS_LEAVE_EXIT(stats)
6769#define STATS_ALLOC(stats, size)
test/runtest.pl+17−1
@@ -2,17 +2,32 @@
22
33use strict;
44use Cwd;
5+use Cwd 'abs_path';
6+use Env;
57
68my $exitstatus = 0;
79my @idrOpts = ();
810
11+sub sandbox_path {
12+ my ($test_dir,) = @_;
13+ my $sandbox = abs_path("$test_dir/../../.cabal-sandbox/bin");
14+
15+ if ( -d $sandbox ) {
16+ return "PATH=$sandbox:$PATH";
17+ } else {
18+ return "";
19+ }
20+}
21+
922sub runtest {
1023 my ($test, $update) = @_;
1124
25+ my $sandbox = sandbox_path($test);
26+
1227 chdir($test);
1328
1429 print "Running $test...\n";
15− my $got = `./run @idrOpts`;
30+ my $got = `$sandbox ./run @idrOpts`;
1631 my $exp = `cat expected`;
1732
1833 open my $out, '>', 'output';
@@ -62,6 +77,7 @@ if ($#ARGV>=0) {
6277 }
6378 }
6479 @tests = sort @tests;
80+
6581 } elsif ($test eq "without") {
6682 @args = @ARGV;
6783 foreach my $file (@args) {