Index

lognestmonster / 099d627

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
20222 Jul 2020 20:27616a224Bring repository up to dateJosh Stockin183G

Blob @ lognestmonster / tests / header_memory.c

text/plain1652 bytesdownload raw
1/* lognestmonster Copyright (c) 2020 Joshua 'joshuas3' Stockin
2 * <https://joshstock.in>
3 * <https://github.com/JoshuaS3/lognestmonster>
4 *
5 * This software is licensed and distributed under the terms of the MIT License.
6 * See the MIT License in the LICENSE file of this project's root folder.
7 *
8 * This comment block and its contents, including this disclaimer, MUST be
9 * preserved in all copies or distributions of this software's source.
10 */
11
12// header_memory.c
13// Test memory usage on lognestmonster library to prevent leaks
14
15#include <stdio.h>
16
17#define LNM_INIT
18#define LNM_ALL
19#define LNM_DEBUG
20#include "lognestmonster.h"
21
22int main() {
23 long t1 = lnm_getus();
24 lnmQueue queue = lnmQueueInit("memtest", "/dev/null");
25
26 lnmItem lastEvent = NULL;
27 for (int iter = 0; iter < 50000; iter++) {
28 uint64_t time = lnm_getus();
29 int type = time % 5 == 0 ? LNM_EVENT : LNM_STATEMENT;
30 if (type == LNM_STATEMENT) {
31 char message[25];
32 snprintf(message, 25, "New statement #%i", iter);
33 if (lastEvent == NULL) {
34 lnmItem statement = lnmStatement(lnmInfo, message);
35 lnmQueuePush(queue, statement);
36 } else {
37 lnmEventPushS(lastEvent, lnmInfo, message);
38 }
39 } else if (type == LNM_EVENT) {
40 char tag[20];
41 snprintf(tag, 20, "New event #%i", iter);
42 if (lastEvent == NULL || time % 7 == 0) {
43 lastEvent = lnmEvent(tag);
44 lnmQueuePush(queue, lastEvent);
45 } else {
46 lnmItem new_event = lnmEvent(tag);
47 lnmEventPush(lastEvent, new_event);
48 lastEvent = new_event;
49 }
50 }
51 }
52 lnm_registry_free();
53 lnm_free_queue(queue);
54 long elapsed = lnm_getus() - t1;
55 printf("time elapsed (us): %lu\n", elapsed);
56 return 0;
57}
58