[systemd-devel] [PATCH 3/3] journal-feeder: trivial test program to flood journald
Karol Lewandowski
k.lewandowsk at samsung.com
Thu Dec 12 05:12:56 PST 2013
This is not a systemd patch but simple test program I have used
for measurements.
---
journal-feeder.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
create mode 100644 journal-feeder.c
diff --git a/journal-feeder.c b/journal-feeder.c
new file mode 100644
index 0000000..df7a7e4
--- /dev/null
+++ b/journal-feeder.c
@@ -0,0 +1,64 @@
+/* journal-feeder M N: send N-sized messages M-times a second
+ *
+ * Compile: $CC -o journal-feeder journal-feeder.c $(pkg-config --cflags --libs libsystemd-journal)
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+#include <stdint.h>
+
+#include <sys/types.h>
+#include <time.h>
+#include <systemd/sd-journal.h>
+
+#define NELEMS(arr) (sizeof(arr)/sizeof(arr[0]))
+
+#define SEC_TO_MSEC(n) (1000*(n))
+#define SEC_TO_USEC(n) (1000*(SEC_TO_MSEC(n)))
+#define SEC_TO_NSEC(n) (1000*(SEC_TO_USEC(n)))
+
+
+int main(int argc, char *argv[])
+{
+ int m_per_sec = 0;
+ int sz = 0;
+ int n;
+ char message[4096] = "Oh my, this should make some sense to reader on the other side...";
+ struct timespec tv;
+
+
+ if (argc != 3) {
+ fprintf(stderr, "usage: %s MSG_PER_SEC MSG_SIZE\n", argv[0]);
+ exit(1);
+ }
+ m_per_sec = atoi(argv[1]);
+ sz = atoi(argv[2]);
+
+ assert(m_per_sec);
+ assert(sz > 0 && sz < NELEMS(message));
+
+ n = strlen(message);
+ if (sz > n)
+ memset(message + n, 'X', sz - n);
+ message[sz] = 0;
+
+ tv.tv_sec = 0;
+ tv.tv_nsec = SEC_TO_NSEC(1) / m_per_sec;
+
+ if (tv.tv_nsec == SEC_TO_NSEC(1))
+ tv.tv_nsec -= 1;
+
+ printf("will wait %d ns\n", tv.tv_nsec);
+
+ for (;;) {
+ sd_journal_send("MESSAGE=%s", message, "PRIORITY=%i", LOG_INFO, NULL);
+
+ while (nanosleep(&tv, NULL) == -1 && errno == -EAGAIN)
+ ;
+
+ }
+
+ return 0;
+}
--
1.8.4.rc3
More information about the systemd-devel
mailing list