perf_libdlog_SOURCES = \
tests/performance_test.c
+
+usrlibexeclibdlog_PROGRAMS += dlog_stdout_benchmark
+dlog_stdout_benchmark_CFLAGS = \
+ $(AM_CFLAGS) \
+ -fPIE
+
+dlog_stdout_benchmark_LDFLAGS = \
+ $(AM_LDFLAGS) \
+ -pie
+
+dlog_stdout_benchmark_DEPENDENCIES = \
+ libdlog.la
+
+dlog_stdout_benchmark_LDADD = \
+ libdlog.la
+
+dlog_stdout_benchmark_SOURCES = \
+ tests/stdout_benchmark.c
+
+
usrlibexeclibdlog_PROGRAMS += test_libdlogutil
test_libdlogutil_CFLAGS = \
$(AM_CFLAGS) \
--- /dev/null
+/* DLOG
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <stdbool.h>
+
+#define LOG_TAG "DLOG_BENCHMARK"
+#include <dlog.h>
+
+int main (int argc, char **argv)
+{
+ if (argc != 4 && argc != 5) {
+ fprintf(stderr, "argc = %d\n", argc);
+ return EXIT_FAILURE;
+ }
+
+ bool buffered = atoi(argv[1]) != 0;
+ setvbuf(stdout, NULL, buffered ? _IOLBF : _IONBF, 0);
+
+ int const N = atoi(argv[2]);
+ char const *MSG = argv[3];
+ char const *where = argc == 4 ? "" : argv[4];
+
+ struct timespec start, end;
+ inline void print_diff (char const *name) {
+ double elapsed_s = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1E9;
+ fprintf(stderr, "%s: %lfus per log (%lfs total per %d logs)\n"
+ , name
+ , 1000000 * elapsed_s / N
+ , elapsed_s
+ , N
+ );
+ }
+
+ if (strcmp(where, "stdout") == 0 || strcmp(where, "") == 0) {
+ for (int i = 0; i < 10000; ++i)
+ printf("stdout warm-up\n");
+
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ for (int i = 0; i < N; ++i)
+ printf("%s\n", MSG);
+ clock_gettime(CLOCK_MONOTONIC, &end);
+ print_diff(buffered ? "stdout (buffered)" : "stdout (not buffered)");
+ }
+
+ if (strcmp(where, "libdlog") == 0 || strcmp(where, "") == 0) {
+ for (int i = 0; i < 10000; ++i)
+ LOGE("libdlog warm-up\n");
+
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ for (int i = 0; i < N; ++i)
+ LOGE("%s\n", MSG);
+ clock_gettime(CLOCK_MONOTONIC, &end);
+ print_diff("libdlog");
+ }
+
+ return EXIT_SUCCESS;
+}