-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.py
134 lines (120 loc) · 4.08 KB
/
target.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import sys, os, time
from sqpyte.interpreter import Sqlite3DB, Sqlite3Query, SQPyteException
from rpython.rlib import jit
from sqpyte.capi import CConfig
from rpython.rtyper.lltypesystem import rffi
jitdriver = jit.JitDriver(
greens=['printRes', 'query', 'queryRes'],
reds=['rc'],
)
# get_printable_location=get_printable_location)
def run(query, queryRes, printRes):
try:
query.reset_query()
if queryRes != "" and printRes:
print 'Query result:'
rc = query.mainloop()
while rc == CConfig.SQLITE_ROW:
jitdriver.jit_merge_point(query=query, queryRes=queryRes, printRes=printRes, rc=rc)
if printRes:
print "|".join([
rffi.charpsize2str(rffi.cast(rffi.CCHARP, query.column_text(i)), query.column_bytes(i))
for i in range(query.data_count())])
rc = query.mainloop()
if queryRes != "" and printRes:
print '\nExpected result:\n%s' % queryRes
except SQPyteException:
raise
def entry_point(argv):
usageMsg = """\n
Usage:
For testing: ./target-c -t db_file query_file [query_results_file]
For benchmarking: ./target-c -b [warm_up] db_file query_file
"""
disabled_opcodes = ""
try:
flag = argv[1]
if flag == '--jit':
jit.set_user_param(None, argv[2])
flag = argv[3]
argv = [argv[0]] + argv[3:]
if flag == '--disable-opcodes':
disabled_opcodes = argv[2]
flag = argv[3]
argv = [argv[0]] + argv[3:]
if flag == '-t':
testingFlag = True
warmup = 0
testdb = argv[2]
queryPath = argv[3]
elif flag == '-b':
testingFlag = False
warmup = 3
if len(argv) > 4:
try:
warmup = int(argv[2])
except ValueError:
print "Error: '%s' is not a valid number for warm_up argument.%s" % (argv[2], usageMsg)
return 1
testdb = argv[3]
queryPath = argv[4]
else:
testdb = argv[2]
queryPath = argv[3]
else:
print "Error: Unknown flag '%s'.%s" % (flag, usageMsg)
return 1
except IndexError:
print "Error: Not enough arguments.%s" % usageMsg
return 1
if testdb != ':memory:':
try:
fp = os.open(testdb, os.O_RDONLY, 0777)
os.close(fp)
except OSError:
print "Error: Can't open '%s' file provided for db_file argument.%s" % (testdb, usageMsg)
return 1
try:
fp = os.open(queryPath, os.O_RDONLY, 0777)
queryStr = ""
while True:
read = os.read(fp, 4096)
if len(read) == 0:
break
queryStr += read
os.close(fp)
except OSError:
print "Error: Can't open '%s' file provided for query_file argument.%s" % (queryPath, usageMsg)
return 1
queryRes = ""
if flag == '-t' and len(argv) > 4:
queryResPath = argv[4]
try:
fp = os.open(queryResPath, os.O_RDONLY, 0777)
while True:
read = os.read(fp, 4096)
if len(read) == 0:
break
queryRes += read
os.close(fp)
except OSError:
print "Error: Can't open '%s' file provided for query_results_file argument.%s" % (queryResPath, usageMsg)
return 1
db = Sqlite3DB(testdb)
query = db.execute(queryStr, use_flag_cache=not disabled_opcodes)
if disabled_opcodes:
query.use_translated.disable_from_cmdline(disabled_opcodes)
if testingFlag:
run(query, queryRes, True)
else:
for i in range(warmup):
run(query, "", False)
t1 = time.time()
run(query, queryRes, False)
t2 = time.time()
print "%s" % (t2 - t1)
return 0
def target(*args):
return entry_point, None
if __name__ == "__main__":
entry_point(sys.argv)