Index

lognestmonster / df63a69

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
9202 Sep 2019 13:20df63a69update file reading for speedJosh Stockin12810N

Blob @ lognestmonster / tests / write.py

application/x-python2269 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
54if __name__ == "__main__":
55 try:
56 out = sys.argv[1]
57 except:
58 print("must provide an out location")
59 exit(1)
60
61 version = uchar(1)
62 queue_time = ulonglong(milli())
63 open_statement = uchar(0)
64 close_statement = uchar(1)
65 open_event = uchar(2)
66 close_event = uchar(3)
67
68 verbosity = uchar(0)
69
70 start = milli()
71
72 try:
73 f = open(out, "wb")
74
75 f.write(version)
76 f.write(queue_time)
77
78 count = 250000
79 for i in range(0, count):
80 print("{0}%".format(round((i/count)*1000)/10), end="\r")
81 ts = ulonglong(milli())
82
83 tag = enc("TAG_NAME_TO_FILTER")
84 tag_len = uchar(len(tag))
85
86 message = enc(s(200))
87 message_len = ushort(len(message))
88 f.write(open_statement)
89 f.write(ts)
90 f.write(verbosity)
91 f.write(tag_len)
92 f.write(tag)
93 f.write(message_len)
94 f.write(message)
95 f.write(close_statement)
96
97 finally:
98 f.close()
99 print("file written with size {0}MB in {1} seconds".format(round(os.stat(out).st_size/1000)/1000, (milli()-start)/1000))
100
101
102