1 | #!/usr/bin/env python |
2 |
|
3 | import sys |
4 | import os |
5 | import time |
6 | import ctypes |
7 | import random |
8 |
|
9 | def exists(f): |
10 | return os.path.isfile(f) or os.path.isdir(f) |
11 |
|
12 | def milli(): |
13 | return int(round(time.time() * 1000)) |
14 |
|
15 | def enc(string): |
16 | return string.encode("latin-1") |
17 |
|
18 | def ushort(n): |
19 | return ctypes.c_ushort(n) |
20 |
|
21 | def uchar(n): |
22 | return ctypes.c_ubyte(n) |
23 |
|
24 | def ulonglong(n): |
25 | return ctypes.c_ulonglong(n) |
26 |
|
27 | def s(n=20): |
28 | l = int(random.random()*n) |
29 | st = "" |
30 | for i in range(0, l): |
31 | c = 97+int(random.random()*26) |
32 | st += chr(c) |
33 | return st |
34 |
|
35 | if __name__ == "__main__": |
36 | try: |
37 | out = sys.argv[1] |
38 | except: |
39 | print("must provide an out location") |
40 | exit(1) |
41 |
|
42 | version = uchar(1) |
43 | queue_time = ulonglong(milli()) |
44 | open_statement = uchar(0) |
45 | close_statement = uchar(1) |
46 | open_event = uchar(2) |
47 | close_event = uchar(3) |
48 |
|
49 | verbosity = uchar(0) |
50 |
|
51 | start = milli() |
52 |
|
53 | try: |
54 | f = open(out, "wb") |
55 |
|
56 | f.write(version) |
57 | f.write(queue_time) |
58 | f.write(open_event) |
59 | for i in range(0, 50000): |
60 | ts = ulonglong(milli()) |
61 |
|
62 | tag = enc("hello")#enc(s(10)) |
63 | tag_len = uchar(len(tag)) |
64 |
|
65 | message = enc(s(100)) |
66 | message_len = ushort(len(message)) |
67 | f.write(open_statement) |
68 | f.write(ts) |
69 | f.write(verbosity) |
70 | f.write(tag_len) |
71 | f.write(tag) |
72 | f.write(message_len) |
73 | f.write(message) |
74 | f.write(close_statement) |
75 | f.write(close_event) |
76 |
|
77 | finally: |
78 | f.close() |
79 | print("file written with size {0} in {1} seconds".format(os.stat(out).st_size, (milli()-start)/1000)) |
80 |
|
81 |
|
82 |
|