~mdcallag/sysbench/0.4-dev

« back to all changes in this revision

Viewing changes to sysbench/sysbench.c

  • Committer: kaamos
  • Date: 2009-03-19 16:03:09 UTC
  • Revision ID: vcs-imports@canonical.com-20090319160309-udfe4gbuwohke2ej
Made forced shutdown optional via the --forced-shutdown switch and off by default. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
  {"num-threads", "number of threads to use", SB_ARG_TYPE_INT, "1"},
99
99
  {"max-requests", "limit for total number of requests", SB_ARG_TYPE_INT, "10000"},
100
100
  {"max-time", "limit for total execution time in seconds", SB_ARG_TYPE_INT, "0"},
 
101
  {"forced-shutdown", "amount of time to wait after --max-time before forcing shutdown",
 
102
   SB_ARG_TYPE_STRING, "off"},
101
103
  {"thread-stack-size", "size of stack per thread", SB_ARG_TYPE_SIZE, "64K"},
102
104
  {"test", "test to run", SB_ARG_TYPE_STRING, NULL},
103
105
  {"debug", "print more debugging info", SB_ARG_TYPE_FLAG, "off"},
140
142
  if (sig == SIGALRM)
141
143
  {
142
144
    sb_timer_stop(&sb_globals.exec_timer);
143
 
    log_text(LOG_WARNING,
 
145
    log_text(LOG_FATAL,
144
146
             "The --max-time limit has expired, forcing shutdown...");
145
147
    if (current_test && current_test->ops.print_stats)
146
148
      current_test->ops.print_stats();
147
149
    log_done();
148
 
    exit(1);
 
150
    exit(2);
149
151
  }
150
152
}
151
153
#endif
360
362
  {
361
363
    log_text(LOG_NOTICE, "Initializing random number generator from timer.\n");
362
364
    sb_srnd(time(NULL));
363
 
  }   
 
365
  }
 
366
 
 
367
  if (sb_globals.force_shutdown)
 
368
    log_text(LOG_NOTICE, "Forcing shutdown in %u seconds",
 
369
             sb_globals.max_time + sb_globals.timeout);
364
370
  
365
371
  log_text(LOG_NOTICE, "");
366
372
 
490
496
    }
491
497
  }
492
498
 
493
 
  /* Set the alarm to force exit */
 
499
  /* Set the alarm to force shutdown */
494
500
#ifdef HAVE_ALARM
495
 
  unsigned int grace = sb_globals.max_time / 20;
496
 
 
497
 
  if (!grace)
498
 
    grace = 1;
499
 
  alarm(sb_globals.max_time + grace);
 
501
  if (sb_globals.force_shutdown)
 
502
    alarm(sb_globals.max_time + sb_globals.timeout);
500
503
#endif
501
504
  
502
505
  pthread_mutex_unlock(&thread_start_mutex);
557
560
{
558
561
  option_t *opt;
559
562
  char     *s;
 
563
  char     *tmp;
560
564
  
561
565
  sb_globals.num_threads = sb_get_value_int("num-threads");
562
566
  if (sb_globals.num_threads <= 0)
568
572
  sb_globals.max_time = sb_get_value_int("max-time");
569
573
  if (!sb_globals.max_requests && !sb_globals.max_time)
570
574
    log_text(LOG_WARNING, "WARNING: Both max-requests and max-time are 0, running endless test");
 
575
 
 
576
  if (sb_globals.max_time > 0)
 
577
  {
 
578
    /* Parse the --forced-shutdown value */
 
579
    tmp = sb_get_value_string("forced-shutdown");
 
580
    if (tmp == NULL)
 
581
    {
 
582
      sb_globals.force_shutdown = 1;
 
583
      sb_globals.timeout = sb_globals.max_time / 20;
 
584
    }
 
585
    else if (strcasecmp(tmp, "off"))
 
586
    {
 
587
      char *endptr;
 
588
    
 
589
      sb_globals.force_shutdown = 1;
 
590
      sb_globals.timeout = (unsigned int)strtol(tmp, &endptr, 10);
 
591
      if (*endptr == '%')
 
592
        sb_globals.timeout = (unsigned int)(sb_globals.timeout *
 
593
                                            (double)sb_globals.max_time / 100);
 
594
      else if (*tmp == '\0' || *endptr != '\0')
 
595
      {
 
596
        log_text(LOG_FATAL, "Invalid value for --forced-shutdown: '%s'", tmp);
 
597
        return 1;
 
598
      }
 
599
    }
 
600
    else
 
601
      sb_globals.force_shutdown = 0;
 
602
  }
571
603
  
572
604
  sb_globals.op_timers = (sb_timer_t *)malloc(sb_globals.num_threads * 
573
605
                                              sizeof(sb_timer_t));