~jimis/+junk/callgrind_parser

« back to all changes in this revision

Viewing changes to callgrind_svg.cgi

  • Committer: Dimitrios Apostolou
  • Date: 2012-07-26 20:45:09 UTC
  • Revision ID: jimis@gmx.net-20120726204509-dxpx3uk3ocx3o5wa
Removed the "r" query string variable, replaced it with "snap" and "test", so that filename depends on both snapshot version and test id.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
# Read data files from this pattern.
8
8
# They are pickle files produced with "callgrind_parser.py -c"
9
 
DATA_FILE_TEMPLATE = "/path/to/results/{R_VAR}/reload-O0-g.cg.pickle"
 
9
DATA_FILE_TEMPLATE = "/path/to/results/{SNAP_VAR}/{TEST_VAR}.cg.pickle"
10
10
 
11
11
# Where the python source located, better don't serve this path with CGI exec
12
12
# allowed, or even don't serve it at all.
71
71
 
72
72
form = cgi.FieldStorage ()
73
73
args = FakeArgs()
74
 
r_var = form.getfirst ("r")
 
74
snap_var = form.getfirst ("snap")
 
75
test_var = form.getfirst ("test")
75
76
args.funcName = form.getfirst ("f")
76
77
f0 = form.getfirst ("F")
77
78
if (f0 is not None):
78
79
        args.funcNo = int (f0)
79
80
args.typ = form.getfirst ("t", "pos")
80
 
if (r_var == None):
81
 
        print ("You must specify input file!", file=sys.stderr)
 
81
if (snap_var == None or test_var == None):
 
82
        # TODO err function printing HTML instead of SVG
 
83
        print ("You must specify snapshot name and test name!",
 
84
               file=sys.stderr)
82
85
        exit (1)
83
86
 
84
87
# Disallow all relative paths in r_var before actually creating filename
85
88
# with DATA_FILE_TEMPLATE.
86
89
# For simplicity don't allow anything other than [a-zA-Z0-9_\-\.]
87
 
good_chars = string.ascii_letters + string.digits + "_-."
88
 
if (r_var.lstrip (good_chars) != "") or (".." in r_var):
89
 
        print ("Bad characters in filename:", var_r, file=sys.stderr)
 
90
def variable_clean (v):
 
91
        good_chars = string.ascii_letters + string.digits + "_-."
 
92
        if (v.lstrip (good_chars) != "") or (".." in v):
 
93
                return False
 
94
        else:
 
95
                return True
 
96
 
 
97
if (not variable_clean (snap_var) or not variable_clean (test_var)):
 
98
        print ("Bad characters in snap or test variable!", file=sys.stderr)
90
99
        exit (1)
91
100
 
92
 
args.infile = DATA_FILE_TEMPLATE.format (R_VAR=r_var)
 
101
args.infile = DATA_FILE_TEMPLATE.format (SNAP_VAR=snap_var,
 
102
                                         TEST_VAR=test_var)
93
103
 
94
104
# This will always be the base of our query string
95
 
args.query_string = "?r=" + r_var
 
105
args.query_string = "?snap=" + snap_var + "&test=" + test_var
96
106
 
97
107
print ("Content-Type: image/svg+xml")
98
108
print ()