Index

lognestmonster / 203af63

A general-purpose single-header C logging library and parser for event-based logs. (Incomplete)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
9508 Sep 2019 15:57c896833block parsing optimization, argument feedback updatesJosh Stockin14325N

Blob @ lognestmonster / tests / write_many.py

application/x-python2706 bytesdownload raw
1#!/usr/bin/env python3
2
3# lognestmonster Copyright (c) 2019 Joshua 'joshuas3' Stockin
4# <https://github.com/JoshuaS3/lognestmonster/>.
5
6
7# This file is part of lognestmonster.
8
9# lognestmonster is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13
14# lognestmonster is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18
19# You should have received a copy of the GNU General Public License
20# along with lognestmonster. If not, see <https://www.gnu.org/licenses/>.
21
22import sys
23import os
24import time
25import ctypes
26import random
27
28def exists(f):
29 return os.path.isfile(f) or os.path.isdir(f)
30
31def milli():
32 return int(round(time.time() * 1000))
33
34def enc(string):
35 return string.encode("utf-8")
36
37def ushort(n):
38 return ctypes.c_ushort(n)
39
40def uchar(n):
41 return ctypes.c_ubyte(n)
42
43def ulonglong(n):
44 return ctypes.c_ulonglong(n)
45
46def s(n=20):
47 l = int(random.random()*n)
48 st = ""
49 for i in range(0, l):
50 c = 97+int(random.random()*25)
51 st += chr(c)
52 return st
53
54open_statement = uchar(0)
55close_statement = uchar(1)
56open_event = uchar(2)
57close_event = uchar(3)
58
59def output_statement(f):
60 t = milli()
61 ts = ulonglong(t)
62
63 verbosity = uchar(round(random.random()*5))
64
65 tag = enc(s(10))
66 tag_len = uchar(len(tag))
67
68 message = enc(s(20))
69 message_len = ushort(len(message))
70 f.write(open_statement)
71 f.write(ts)
72 f.write(verbosity)
73 f.write(tag_len)
74 f.write(tag)
75 f.write(message_len)
76 f.write(message)
77 f.write(close_statement)
78
79 raw = str(t) + " - INFO - " + tag.decode("utf-8") + " - " + message.decode("utf-8") + "\n"
80 return len(raw)
81
82def block(f):
83 s_count = round(random.random()*8)
84 for i in range(0, s_count):
85 output_statement(f)
86 event_chance = (random.random()*8) > 6
87 if event_chance:
88 f.write(open_event)
89 block(f)
90 f.write(close_event)
91
92if __name__ == "__main__":
93 try:
94 out = sys.argv[1]
95 except:
96 print("must provide an out location")
97 exit(1)
98
99 try:
100 count = int(sys.argv[2])
101 except:
102 print("must provide a loop count")
103 exit(1)
104
105 version = uchar(1)
106 queue_time = ulonglong(milli())
107
108 start = milli()
109
110 try:
111 f = open(out, "wb")
112
113 f.write(version)
114 f.write(queue_time)
115
116 for i in range(0, count):
117 print("{0}%".format(round((i/count)*1000)/10), end="\r")
118 block(f)
119
120
121 finally:
122 f.close()
123 size = os.stat(out).st_size
124 print("file written with size {0}MB in {1} seconds".format(round(size/1000)/1000, (milli()-start)/1000))
125
126
127