import math import optparse import os import re import sys import cairo FONT_NAME = "Bitstream Vera Sans" FONT_SIZE = 8 # how many pixels for a second on the timeline pixels_per_second = 1000 # how many pixels for one line of log pixels_per_line = 10 PLOT_WIDTH = 1400 TIME_SCALE_WIDTH = 20 SYSCALL_MARKER_WIDTH = 20 LOG_TEXT_XPOS = 400 LOG_MARKER_WIDTH = 20 BACKGROUND_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