Branch: Tag:

2012-07-06

2012-07-06 14:50:07 by Martin Stjernholm <mast@lysator.liu.se>

Added debug to help track down strange gc interval calculations.

Enabled by GC_INTERVAL_DEBUG in gc.c.

94:   /* #define GC_VERBOSE */   /* #define GC_CYCLE_DEBUG */   /* #define GC_STACK_DEBUG */ + /* #define GC_INTERVAL_DEBUG */      #if defined(GC_VERBOSE) && !defined(PIKE_DEBUG)   #undef GC_VERBOSE
3437:    if (gc_enabled <= 0 && (gc_enabled < 0 || !explicit_call)) {    num_allocs = 0;    alloc_threshold = GC_MAX_ALLOC_THRESHOLD; + #ifdef GC_INTERVAL_DEBUG +  fprintf (stderr, "GC disabled: num_allocs 0, alloc_threshold max\n"); + #endif    if (gc_evaluator_callback) {    remove_callback (gc_evaluator_callback);    gc_evaluator_callback = NULL;
3883:    {    double multiplier, new_threshold;    cpu_time_t last_non_gc_time, last_gc_time; + #ifdef GC_INTERVAL_DEBUG +  double tmp_dbl1, tmp_dbl2; + #endif       /* If we're at an automatic and timely gc then start_allocs ==    * alloc_threshold and we're using gc_average_slowness in the
3894:    multiplier=pow(gc_average_slowness,    (double) start_allocs / (double) alloc_threshold);    + #ifdef GC_INTERVAL_DEBUG +  if (GC_VERBOSE_DO(1 ||) gc_trace) fputc ('\n', stderr); +  fprintf (stderr, "IN: GC start @ %"PRINT_CPU_TIME" "CPU_TIME_UNIT"\n" +  " avg slow %g, start_allocs %"PRINT_ALLOC_COUNT_TYPE", " +  "alloc_threshold %"PRINT_ALLOC_COUNT_TYPE" -> mult %g\n", +  gc_start_real_time, +  gc_average_slowness, start_allocs, alloc_threshold, multiplier); +  tmp_dbl1 = non_gc_time; +  tmp_dbl2 = gc_time; + #endif +     /* Comparisons to avoid that overflows mess up the statistics. */    if (last_gc_end_real_time != -1 &&    gc_start_real_time > last_gc_end_real_time) {
3907:    gc_time = gc_time * multiplier +    (last_gc_end_real_time - gc_start_real_time) * (1.0 - multiplier);    } +  + #ifdef GC_INTERVAL_DEBUG +  fprintf (stderr, +  " non_gc_time: %13"PRINT_CPU_TIME" "CPU_TIME_UNIT", " +  "%.12g -> %.12g\n" +  " gc_time: %13"PRINT_CPU_TIME" "CPU_TIME_UNIT", " +  "%.12g -> %.12g\n", +  last_non_gc_time, tmp_dbl1, non_gc_time, +  last_gc_end_real_time > gc_start_real_time ? +  last_gc_end_real_time - gc_start_real_time : (cpu_time_t) -1, +  tmp_dbl2, gc_time); +  tmp_dbl1 = objects_alloced; +  tmp_dbl2 = objects_freed; + #endif +     {    cpu_time_t gc_end_time = get_cpu_time();    if (gc_end_time > gc_start_time)
3929:    objects_freed = objects_freed * multiplier +    unreferenced * (1.0 - multiplier);    + #ifdef GC_INTERVAL_DEBUG +  fprintf (stderr, +  " objects_alloced: %9"PRINT_ALLOC_COUNT_TYPE" allocs, " +  "%.12g -> %.12g\n" +  " objects_freed: %9"PRINT_ALLOC_COUNT_TYPE" unrefd, " +  "%.12g -> %.12g\n", +  start_allocs, tmp_dbl1, objects_alloced, +  unreferenced, tmp_dbl2, objects_freed); + #endif +     if (last_non_gc_time == (cpu_time_t) -1 ||    gc_time / non_gc_time <= gc_time_ratio) {    /* Calculate the new threshold by adjusting the average
3940:    new_threshold = (objects_alloced+1.0) *    (gc_garbage_ratio_low * start_num_objs) / (objects_freed+1.0);    last_garbage_strategy = GARBAGE_RATIO_LOW; + #ifdef GC_INTERVAL_DEBUG +  fprintf (stderr, " strategy: low ratio %g, objs %"PRINTSIZET"u, " +  "new threshold -> %.12g\n", +  gc_garbage_ratio_low, start_num_objs, new_threshold); + #endif    }    else {    new_threshold = (objects_alloced+1.0) *    (gc_garbage_ratio_high * start_num_objs) / (objects_freed+1.0);    last_garbage_strategy = GARBAGE_RATIO_HIGH; -  + #ifdef GC_INTERVAL_DEBUG +  fprintf (stderr, " strategy: high ratio %g, objs %"PRINTSIZET"u, " +  "new threshold -> %.12g\n", +  gc_garbage_ratio_high, start_num_objs, new_threshold); + #endif    }       if (non_gc_time > 0.0 && gc_min_time_ratio > 0.0) {
3955:    new_threshold = max_threshold;    last_garbage_strategy = GARBAGE_MAX_INTERVAL;    } + #ifdef GC_INTERVAL_DEBUG +  fprintf (stderr, " max interval? min time ratio %g, " +  "max threshold %.12g -> %s\n", +  gc_min_time_ratio, max_threshold, +  max_threshold < new_threshold ? "yes" : "no"); + #endif    }      #if 0
3974:    else    alloc_threshold = (ALLOC_COUNT_TYPE) new_threshold;    + #ifdef GC_INTERVAL_DEBUG +  fprintf (stderr, "OUT: GC end @ %"PRINT_CPU_TIME" "CPU_TIME_UNIT", " +  "new capped threshold %"PRINT_ALLOC_COUNT_TYPE"\n", +  last_gc_end_real_time, alloc_threshold); + #endif +     if (!explicit_call) {    auto_gc_real_time += get_real_time() - gc_start_real_time;