~ipitech/jett/benchmark-framework

« back to all changes in this revision

Viewing changes to benchmark/runner.py

  • Committer: Vadim Fint
  • Date: 2008-08-13 23:37:19 UTC
  • Revision ID: mocksoul@gmail.com-20080813233719-4dtjg6kk65654lzg
Handling exceptions in benchmarks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    
26
26
    return options, args
27
27
 
 
28
STATE_NORMAL = 0
 
29
STATE_DONE = 1
 
30
STATE_ERROR = 2
28
31
 
29
32
def run_benchmark_sandboxed(benchmark):
30
33
    host_pipe, fork_pipe = os.pipe()
36
39
        length = int(os.read(host_pipe, 32))
37
40
        datastr = os.read(host_pipe, length)
38
41
        data = pickle.loads(datastr)
39
 
        print '    Min: %0.6fs, Max: %0.6fs' % (min(data), max(data))
 
42
        if data['state'] == STATE_DONE:
 
43
            print '    Min: %0.6fs, Max: %0.6fs' % (min(data['times']), max(data['times']))
40
44
    else:
41
45
        # we are in fork (pid == 0)
 
46
        state = STATE_NORMAL
42
47
        times = []
 
48
        
43
49
        for i in xrange(10):
44
50
            st = time()
45
 
            benchmark()
46
 
            times.append(time()-st)
47
 
        
48
 
        data = pickle.dumps(times)
 
51
            try:
 
52
                benchmark()
 
53
            except:
 
54
                import traceback
 
55
                print '\n   ', '\n    '.join(traceback.format_exc().split('\n'))
 
56
                state = STATE_ERROR
 
57
                break
 
58
            else:
 
59
                times.append(time()-st)
 
60
        
 
61
        if state == STATE_NORMAL:
 
62
            state = STATE_DONE
 
63
        
 
64
        data = pickle.dumps({'state': state, 'times': times})
49
65
        os.write(fork_pipe, '%-32d' % len(data))
50
66
        os.write(fork_pipe, data)
51
67
        sys.exit(0)