All pastes #621633 Raw Edit

Unbenannt

public python v1 · immutable
·published 2007-07-16 09:27 UTC
rendered paste body
import mathimport optparseimport osimport reimport sysimport cairoFONT_NAME = "Bitstream Vera Sans"FONT_SIZE = 8# how many pixels for a second on the timelinepixels_per_second = 1000# how many pixels for one line of logpixels_per_line = 10PLOT_WIDTH = 1400TIME_SCALE_WIDTH = 20SYSCALL_MARKER_WIDTH = 20LOG_TEXT_XPOS = 400LOG_MARKER_WIDTH = 20BACKGROUND_COLOR = (0, 0, 0)# ... snip ....class SyscallParser:# ... snip ....def compute_syscall_metrics(syscalls):    num_syscalls = len(syscalls)    metrics = Metrics()    metrics.width = PLOT_WIDTH    last_timestamp = syscalls[num_syscalls - 1].timestamp    num_seconds = int(math.ceil(last_timestamp))    # this works    #    metrics.height = max(num_seconds * pixels_per_second,                         num_syscalls * pixels_per_line)        # this gives:    # UnboundLocalError: local variable 'pixels_per_second' referenced before assignment"    #    time_height = num_seconds * pixels_per_second    line_height = num_syscalls * pixels_per_line    if time_height > line_height:        metrics.height = time_height        pixels_per_line = metrics.height / num_syscalls    else:        metrics.height = line_height        pixels_per_second = metrics.height / num_seconds