Compare commits

..

No commits in common. '3339e3c6d80feb821cd4cac0bba89fd04fe24d0c' and '444af0b257749bef8404f34691d2d0b388c6794c' have entirely different histories.

  1. 23
      CMakeLists.txt
  2. 31
      src/main.c

23
CMakeLists.txt

@ -1,23 +0,0 @@
cmake_minimum_required(VERSION 3.10)
project(eventlog-daemon)
set(eventlog_daemon_src
src/main.c)
find_library(EVENTLOG_LIB
NAMES eventlog
PATHS ${EVENTLOG_PATH} ${CMAKE_LIBRARY_PATH}
NO_DEFAULT_PATH)
find_path(EVENTLOG_INCLUDE
NAMES eventlog.h
PATHS ${EVENTLOG_INCLUDE_PATH} ${CMAKE_INCLUDE_PATH}
NO_DEFAULT_PATH)
add_executable(eventlog-daemon ${eventlog_daemon_src})
target_include_directories(eventlog-daemon PUBLIC ${EVENTLOG_INCLUDE} ${EVENTLOG_EXTRA_INCLUDE_PATH})
target_link_libraries(eventlog-daemon ${EVENTLOG_LIB})

31
src/main.c

@ -1,3 +1,4 @@
#include "eventlog.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
@ -6,10 +7,6 @@
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#define EVENTLOG_DAEMON 1
#include "eventlog.h"
#include "events.h"
static uint64_t gs_head = 0; static uint64_t gs_head = 0;
static void tracer_format_timestamp(uint64_t ns, char* buffer, size_t buffer_size) static void tracer_format_timestamp(uint64_t ns, char* buffer, size_t buffer_size)
@ -29,24 +26,6 @@ static void tracer_format_timestamp(uint64_t ns, char* buffer, size_t buffer_siz
ms); ms);
} }
void print_event(const struct eventlog_entry* e, char* buf, size_t buf_size)
{
for (size_t i = 0; i < g_event_registry_size; ++i) {
if (g_event_registry[i].id == e->type_id) {
char ts_buf[32];
tracer_format_timestamp(e->timestamp, ts_buf, sizeof(ts_buf));
int chars = snprintf(buf, buf_size, "[%s] ", ts_buf);
if (chars <= 0)
{
return;
}
g_event_registry[i].printer(e->data, buf + chars, buf_size - chars);
return;
}
}
printf("Unknown event ID: %u\n", e->type_id);
}
static void dump_events_to_file(const char* filepath) static void dump_events_to_file(const char* filepath)
{ {
FILE* fp = fopen(filepath, "w+"); FILE* fp = fopen(filepath, "w+");
@ -54,21 +33,15 @@ static void dump_events_to_file(const char* filepath)
struct eventlog_entry entries[64]; struct eventlog_entry entries[64];
do do
{ {
char timestamp_buffer[256];
eventlog_get_snapshot(&gs_head, entries, 64, &actual_size); eventlog_get_snapshot(&gs_head, entries, 64, &actual_size);
for (size_t i = 0; i < actual_size; i++) for (size_t i = 0; i < actual_size; i++)
{ {
if (entries[i].type_id == EVENTLOG_TYPE_STRING) if (entries[i].type_id == EVENTLOG_TYPE_STRING)
{ {
char timestamp_buffer[32];
tracer_format_timestamp(entries[i].timestamp, timestamp_buffer, sizeof(timestamp_buffer)); tracer_format_timestamp(entries[i].timestamp, timestamp_buffer, sizeof(timestamp_buffer));
fprintf(fp, "[%s] %s\n", timestamp_buffer, entries[i].data); fprintf(fp, "[%s] %s\n", timestamp_buffer, entries[i].data);
} }
else
{
char buf[256];
print_event(&entries[i], buf, sizeof(buf));
fprintf(fp, "%s\n", buf);
}
} }
} while(actual_size != 0); } while(actual_size != 0);

Loading…
Cancel
Save