mirror of
https://github.com/ilyakooo0/Idris-dev.git
synced 2024-09-11 08:55:23 +03:00
Fix GC statistics overflow
This commit is contained in:
parent
3078c0bc47
commit
64cf1205b4
@ -69,7 +69,7 @@ void cheney(VM *vm) {
|
||||
int i;
|
||||
int ar;
|
||||
char* scan = vm->heap.heap;
|
||||
|
||||
|
||||
while(scan < vm->heap.next) {
|
||||
size_t inc = *((size_t*)scan);
|
||||
VAL heap_item = (VAL)(scan+sizeof(size_t));
|
||||
@ -85,7 +85,7 @@ void cheney(VM *vm) {
|
||||
}
|
||||
break;
|
||||
case STROFFSET:
|
||||
heap_item->info.str_offset->str
|
||||
heap_item->info.str_offset->str
|
||||
= copy(vm, heap_item->info.str_offset->str);
|
||||
break;
|
||||
default: // Nothing to copy
|
||||
@ -103,7 +103,7 @@ void idris_gc(VM* vm) {
|
||||
|
||||
char* newheap = malloc(vm->heap.size);
|
||||
char* oldheap = vm->heap.heap;
|
||||
if (vm->heap.old != NULL)
|
||||
if (vm->heap.old != NULL)
|
||||
free(vm->heap.old);
|
||||
|
||||
vm->heap.heap = newheap;
|
||||
@ -138,21 +138,21 @@ void idris_gc(VM* vm) {
|
||||
|
||||
if ((vm->heap.next - vm->heap.heap) > vm->heap.size >> 1) {
|
||||
vm->heap.size += vm->heap.growth;
|
||||
}
|
||||
}
|
||||
vm->heap.old = oldheap;
|
||||
|
||||
|
||||
STATS_LEAVE_GC(vm->stats, vm->heap.size, vm->heap.next - vm->heap.heap)
|
||||
HEAP_CHECK(vm)
|
||||
}
|
||||
|
||||
void idris_gcInfo(VM* vm, int doGC) {
|
||||
printf("Stack: <BOT %p> <TOP %p>\n", vm->valstack, vm->valstack_top);
|
||||
printf("Stack: <BOT %p> <TOP %p>\n", vm->valstack, vm->valstack_top);
|
||||
printf("Final heap size %d\n", (int)(vm->heap.size));
|
||||
printf("Final heap use %d\n", (int)(vm->heap.next - vm->heap.heap));
|
||||
if (doGC) { idris_gc(vm); }
|
||||
printf("Final heap use after GC %d\n", (int)(vm->heap.next - vm->heap.heap));
|
||||
#ifdef IDRIS_ENABLE_STATS
|
||||
printf("Total allocations %d\n", vm->stats.allocations);
|
||||
printf("Total allocations %" PRIu64 "\n", vm->stats.allocations);
|
||||
#endif
|
||||
printf("Number of collections %d\n", vm->stats.collections);
|
||||
|
||||
|
@ -10,16 +10,16 @@ void print_stats(const Stats * stats) {
|
||||
clock_t mut = total - stats->init_time - stats->gc_time - stats->exit_time;
|
||||
double mut_sec = (double)mut / CLOCKS_PER_SEC;
|
||||
|
||||
int avg_chunk = 0;
|
||||
uint64_t avg_chunk = 0;
|
||||
if (stats->alloc_count > 0) {
|
||||
avg_chunk = (int)((double)stats->allocations / (double)stats->alloc_count);
|
||||
avg_chunk = (uint64_t)((double)stats->allocations / (double)stats->alloc_count);
|
||||
}
|
||||
|
||||
int alloc_rate = 0;
|
||||
uint64_t alloc_rate = 0;
|
||||
if (mut > 0) {
|
||||
alloc_rate = (int)((double)(stats->allocations) / mut_sec);
|
||||
alloc_rate = (uint64_t)((double)(stats->allocations) / mut_sec);
|
||||
}
|
||||
|
||||
|
||||
double gc_percent = 0.0;
|
||||
double productivity = 0.0;
|
||||
if (total > 0) {
|
||||
@ -29,11 +29,11 @@ void print_stats(const Stats * stats) {
|
||||
|
||||
setlocale(LC_NUMERIC, "");
|
||||
printf("\n");
|
||||
printf("%'20d bytes allocated in the heap\n", stats->allocations);
|
||||
printf("%'20d bytes copied during GC\n", stats->copied);
|
||||
printf("%'20d maximum heap size\n", stats->max_heap_size);
|
||||
printf("%'20d chunks allocated in the heap\n", stats->alloc_count);
|
||||
printf("%'20d average chunk size\n\n", avg_chunk);
|
||||
printf("%'20" PRIu64 " bytes allocated in the heap\n", stats->allocations);
|
||||
printf("%'20" PRIu64 " bytes copied during GC\n", stats->copied);
|
||||
printf("%'20" PRIu32 " maximum heap size\n", stats->max_heap_size);
|
||||
printf("%'20" PRIu32 " chunks allocated in the heap\n", stats->alloc_count);
|
||||
printf("%'20" PRIu64 " average chunk size\n\n", avg_chunk);
|
||||
|
||||
printf("GC called %d times\n\n", stats->collections);
|
||||
|
||||
@ -45,7 +45,7 @@ void print_stats(const Stats * stats) {
|
||||
|
||||
printf("%%GC time: %.2f%%\n\n", gc_percent);
|
||||
|
||||
printf("Alloc rate %'d bytes per MUT sec\n\n", alloc_rate);
|
||||
printf("Alloc rate %'" PRIu64 " bytes per MUT sec\n\n", alloc_rate);
|
||||
|
||||
printf("Productivity %.2f%%\n", productivity);
|
||||
}
|
||||
|
@ -3,16 +3,18 @@
|
||||
|
||||
#ifdef IDRIS_ENABLE_STATS
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
|
||||
// TODO: measure user time, exclusive/inclusive stats
|
||||
typedef struct {
|
||||
#ifdef IDRIS_ENABLE_STATS
|
||||
int allocations; // Size of allocated space in bytes for all execution time.
|
||||
int alloc_count; // How many times alloc is called.
|
||||
int copied; // Size of space copied during GC.
|
||||
int max_heap_size; // Maximum heap size achieved.
|
||||
uint64_t allocations; // Size of allocated space in bytes for all execution time.
|
||||
uint32_t alloc_count; // How many times alloc is called.
|
||||
uint64_t copied; // Size of space copied during GC.
|
||||
uint32_t max_heap_size; // Maximum heap size achieved.
|
||||
|
||||
clock_t init_time; // Time spent for vm initialization.
|
||||
clock_t exit_time; // Time spent for vm termination.
|
||||
@ -20,7 +22,7 @@ typedef struct {
|
||||
clock_t max_gc_pause; // Time spent for longest gc.
|
||||
clock_t start_time; // Time of rts entry point.
|
||||
#endif // IDRIS_ENABLE_STATS
|
||||
int collections; // How many times gc called.
|
||||
uint32_t collections; // How many times gc called.
|
||||
} Stats; // without start time it's a monoid, can we remove start_time it somehow?
|
||||
|
||||
void print_stats(const Stats * stats);
|
||||
@ -35,7 +37,7 @@ void aggregate_stats(Stats * stats1, const Stats * stats2);
|
||||
|
||||
#define STATS_INIT_STATS(stats) \
|
||||
memset(&stats, 0, sizeof(Stats)); \
|
||||
stats.start_time = clock();
|
||||
stats.start_time = clock();
|
||||
|
||||
#define STATS_ALLOC(stats, size) \
|
||||
stats.allocations += size; \
|
||||
@ -60,8 +62,8 @@ void aggregate_stats(Stats * stats1, const Stats * stats2);
|
||||
|
||||
#else
|
||||
#define STATS_INIT_STATS(stats) memset(&stats, 0, sizeof(Stats));
|
||||
#define STATS_ENTER_INIT(stats)
|
||||
#define STATS_LEAVE_INIT(stats)
|
||||
#define STATS_ENTER_INIT(stats)
|
||||
#define STATS_LEAVE_INIT(stats)
|
||||
#define STATS_ENTER_EXIT(stats)
|
||||
#define STATS_LEAVE_EXIT(stats)
|
||||
#define STATS_ALLOC(stats, size)
|
||||
|
Loading…
Reference in New Issue
Block a user