From 49505b4849e74a4f8cb00a131ccf5d97879434f8 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sat, 27 Jun 2015 20:43:43 +0900 Subject: [PATCH] adding count to gc timer --- benchmarks/gabriel/chibi-prelude.scm | 4 +++- gc.c | 1 + include/chibi/sexp.h | 11 ++++++++++- lib/chibi/ast.c | 5 +++++ lib/chibi/ast.sld | 3 ++- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/benchmarks/gabriel/chibi-prelude.scm b/benchmarks/gabriel/chibi-prelude.scm index d7b75a41..7a733768 100644 --- a/benchmarks/gabriel/chibi-prelude.scm +++ b/benchmarks/gabriel/chibi-prelude.scm @@ -23,7 +23,9 @@ (display msecs) (display " gc: ") (display gc-msecs) - (newline) + (display " (") + (display (gc-count)) + (display " times)\n") (display "result: ") (write result) (newline) diff --git a/gc.c b/gc.c index 43a675c6..4ae28042 100644 --- a/gc.c +++ b/gc.c @@ -483,6 +483,7 @@ sexp sexp_gc (sexp ctx, size_t *sum_freed) { getrusage(RUSAGE_SELF, &end); gc_usecs = (end.ru_utime.tv_sec - start.ru_utime.tv_sec) * 1000000 + end.ru_utime.tv_usec - start.ru_utime.tv_usec; + ++sexp_context_gc_count(ctx); sexp_context_gc_usecs(ctx) += gc_usecs; sexp_debug_printf("%p (freed: %lu max_freed: %lu finalized: %lu time: %luus)", ctx, (sum_freed ? *sum_freed : 0), sexp_unbox_fixnum(res), diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index c8919e94..40eca031 100755 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -469,7 +469,10 @@ struct sexp_struct { struct timeval tval; #endif char tailp, tracep, timeoutp, waitp, errorp; - sexp_uint_t last_fp, gc_usecs; + sexp_uint_t last_fp; +#if SEXP_USE_TIME_GC + sexp_uint_t gc_count, gc_usecs; +#endif sexp stack, env, parent, child, globals, dk, params, proc, name, specific, event, result; #if SEXP_USE_DL @@ -1102,7 +1105,13 @@ SEXP_API sexp sexp_make_unsigned_integer(sexp ctx, sexp_luint_t x); #define sexp_context_dk(x) (sexp_field(x, context, SEXP_CONTEXT, dk)) #define sexp_context_params(x) (sexp_field(x, context, SEXP_CONTEXT, params)) #define sexp_context_last_fp(x) (sexp_field(x, context, SEXP_CONTEXT, last_fp)) +#if SEXP_USE_TIME_GC +#define sexp_context_gc_count(x) (sexp_field(x, context, SEXP_CONTEXT, gc_count)) #define sexp_context_gc_usecs(x) (sexp_field(x, context, SEXP_CONTEXT, gc_usecs)) +#else +#define sexp_context_gc_count(x) 0 +#define sexp_context_gc_usecs(x) 0 +#endif #define sexp_context_refuel(x) (sexp_field(x, context, SEXP_CONTEXT, refuel)) #define sexp_context_ip(x) (sexp_field(x, context, SEXP_CONTEXT, ip)) #define sexp_context_proc(x) (sexp_field(x, context, SEXP_CONTEXT, proc)) diff --git a/lib/chibi/ast.c b/lib/chibi/ast.c index b4f1283d..3b878092 100644 --- a/lib/chibi/ast.c +++ b/lib/chibi/ast.c @@ -408,6 +408,10 @@ static sexp sexp_gc_op (sexp ctx, sexp self, sexp_sint_t n) { return sexp_make_unsigned_integer(ctx, sum_freed); } +static sexp sexp_gc_count_op (sexp ctx, sexp self, sexp_sint_t n) { + return sexp_make_unsigned_integer(ctx, sexp_context_gc_count(ctx)); +} + static sexp sexp_gc_usecs_op (sexp ctx, sexp self, sexp_sint_t n) { return sexp_make_unsigned_integer(ctx, sexp_context_gc_usecs(ctx)); } @@ -651,6 +655,7 @@ sexp sexp_init_library (sexp ctx, sexp self, sexp_sint_t n, sexp env, const char sexp_define_foreign(ctx, env, "object-size", 1, sexp_object_size); sexp_define_foreign_opt(ctx, env, "integer->immediate", 2, sexp_integer_to_immediate, SEXP_FALSE); sexp_define_foreign(ctx, env, "gc", 0, sexp_gc_op); + sexp_define_foreign(ctx, env, "gc-count", 0, sexp_gc_count_op); sexp_define_foreign(ctx, env, "gc-usecs", 0, sexp_gc_usecs_op); #if SEXP_USE_GREEN_THREADS sexp_define_foreign(ctx, env, "%set-atomic!", 1, sexp_set_atomic); diff --git a/lib/chibi/ast.sld b/lib/chibi/ast.sld index 2cc7df15..76a16f23 100644 --- a/lib/chibi/ast.sld +++ b/lib/chibi/ast.sld @@ -34,7 +34,8 @@ extend-env env-parent env-parent-set! env-lambda env-lambda-set! env-define! env-push! env-syntactic? env-syntactic?-set! core-code type-name type-cpl type-parent type-slots type-num-slots type-printer - object-size integer->immediate gc gc-usecs atomically thread-list abort + object-size integer->immediate gc gc-usecs gc-count + atomically thread-list abort string-contains string-cursor-copy! errno integer->error-string flatten-dot update-free-vars! setenv unsetenv safe-setenv) (import (chibi))