summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--capture.c2
-rw-r--r--encode.c4
-rw-r--r--gpu.c3
-rw-r--r--main.c23
-rw-r--r--makefile3
-rw-r--r--perf.c48
-rw-r--r--perf.h35
-rw-r--r--util.h30
8 files changed, 21 insertions, 127 deletions
diff --git a/capture.c b/capture.c
index c1b64b6..b5ae8fc 100644
--- a/capture.c
+++ b/capture.c
@@ -27,7 +27,7 @@
#include <xf86drmMode.h>
#include "gpu.h"
-#include "util.h"
+#include "toolbox/utils.h"
struct CaptureContext {
struct GpuContext* gpu_context;
diff --git a/encode.c b/encode.c
index 16842a6..d9307ce 100644
--- a/encode.c
+++ b/encode.c
@@ -31,8 +31,8 @@
#include <va/va_drmcommon.h>
#include "gpu.h"
-#include "perf.h"
-#include "util.h"
+#include "toolbox/perf.h"
+#include "toolbox/utils.h"
struct EncodeContext {
struct GpuContext* gpu_context;
diff --git a/gpu.c b/gpu.c
index 4d32f76..6aa07b0 100644
--- a/gpu.c
+++ b/gpu.c
@@ -36,8 +36,9 @@
#include <gbm.h>
#endif // USE_EGL_MESA_PLATFORM_SURFACELESS
-#include "util.h"
+#include "toolbox/utils.h"
+#define _(...) __VA_ARGS__
#define LOOKUP_FUNCTION(a, b) \
gpu_context->b = (a)eglGetProcAddress(#b); \
if (!gpu_context->b) { \
diff --git a/main.c b/main.c
index f8c07c6..d258be2 100644
--- a/main.c
+++ b/main.c
@@ -26,8 +26,8 @@
#include "colorspace.h"
#include "encode.h"
#include "gpu.h"
-#include "perf.h"
-#include "util.h"
+#include "toolbox/perf.h"
+#include "toolbox/utils.h"
// TODO(mburakov): Currently zwp_linux_dmabuf_v1 has no way to provide
// colorspace and range information to the compositor. Maybe this would change
@@ -57,6 +57,12 @@ static void EncodeContextDtor(struct EncodeContext** encode_context) {
*encode_context = NULL;
}
+static void TimingStatsLog(const struct TimingStats* timing_stats,
+ const char* name) {
+ LOG("%s min/avg/max: %llu/%llu/%llu", name, timing_stats->min,
+ timing_stats->sum / timing_stats->counter, timing_stats->max);
+}
+
int main(int argc, char* argv[]) {
(void)argc;
(void)argv;
@@ -96,7 +102,6 @@ int main(int argc, char* argv[]) {
TimingStatsReset(&encode);
TimingStatsReset(&drain);
TimingStatsReset(&total);
- unsigned long long num_frames = 0;
unsigned long long recording_started = MicrosNow();
static const unsigned long long delta = 1000000ull / 60ull;
@@ -151,24 +156,22 @@ int main(int argc, char* argv[]) {
static const unsigned long long second = 1000000;
if (period > 10 * second) {
LOG("---->8-------->8-------->8----");
- TimingStatsLog(&capture, "Capture", num_frames);
- TimingStatsLog(&convert, "Convert", num_frames);
- TimingStatsLog(&encode, "Encode", num_frames);
- TimingStatsLog(&drain, "Drain", num_frames);
- TimingStatsLog(&total, "Total", num_frames);
+ TimingStatsLog(&capture, "Capture");
+ TimingStatsLog(&convert, "Convert");
+ TimingStatsLog(&encode, "Encode");
+ TimingStatsLog(&drain, "Drain");
+ TimingStatsLog(&total, "Total");
TimingStatsReset(&capture);
TimingStatsReset(&convert);
TimingStatsReset(&encode);
TimingStatsReset(&drain);
TimingStatsReset(&total);
recording_started = now;
- num_frames = 0;
}
now = MicrosNow();
unsigned long long micros = now < next ? next - now : 0;
if (micros) usleep((unsigned)micros);
- num_frames++;
}
if (!EncodeContextEncodeFrame(encode_context, STDOUT_FILENO, NULL, NULL)) {
diff --git a/makefile b/makefile
index 5c5dd12..b861bc1 100644
--- a/makefile
+++ b/makefile
@@ -2,6 +2,9 @@ bin:=$(notdir $(shell pwd))
src:=$(shell ls *.c)
obj:=$(src:.c=.o)
+obj+=\
+ toolbox/perf.o
+
libs:=\
egl \
gbm \
diff --git a/perf.c b/perf.c
deleted file mode 100644
index 8ed1d42..0000000
--- a/perf.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2023 Mikhail Burakov. This file is part of streamer.
- *
- * streamer is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * streamer is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with streamer. If not, see <https://www.gnu.org/licenses/>.
- */
-
-#include "perf.h"
-
-#include <limits.h>
-#include <stdio.h>
-#include <time.h>
-
-#include "util.h"
-
-unsigned long long MicrosNow(void) {
- struct timespec ts = {.tv_sec = 0, .tv_nsec = 0};
- clock_gettime(CLOCK_MONOTONIC, &ts);
- return (unsigned long long)ts.tv_sec * 1000000ull +
- (unsigned long long)ts.tv_nsec / 1000ull;
-}
-
-void TimingStatsReset(struct TimingStats* timing_stats) {
- *timing_stats = (struct TimingStats){.min = ULLONG_MAX};
-}
-
-void TimingStatsRecord(struct TimingStats* timing_stats,
- unsigned long long value) {
- timing_stats->min = MIN(timing_stats->min, value);
- timing_stats->max = MAX(timing_stats->max, value);
- timing_stats->sum += value;
-}
-
-void TimingStatsLog(const struct TimingStats* timing_stats, const char* name,
- unsigned long long counter) {
- LOG("%s min/avg/max: %llu/%llu/%llu", name, timing_stats->min,
- timing_stats->sum / counter, timing_stats->max);
-}
diff --git a/perf.h b/perf.h
deleted file mode 100644
index 24c50c7..0000000
--- a/perf.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2023 Mikhail Burakov. This file is part of streamer.
- *
- * streamer is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * streamer is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with streamer. If not, see <https://www.gnu.org/licenses/>.
- */
-
-#ifndef STREAMER_PERF_H_
-#define STREAMER_PERF_H_
-
-struct TimingStats {
- unsigned long long min;
- unsigned long long max;
- unsigned long long sum;
-};
-
-unsigned long long MicrosNow(void);
-
-void TimingStatsReset(struct TimingStats* timing_stats);
-void TimingStatsRecord(struct TimingStats* timing_stats,
- unsigned long long value);
-void TimingStatsLog(const struct TimingStats* timing_stats, const char* name,
- unsigned long long counter);
-
-#endif // STREAMER_PERF_H_
diff --git a/util.h b/util.h
deleted file mode 100644
index fe5fa56..0000000
--- a/util.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2023 Mikhail Burakov. This file is part of streamer.
- *
- * streamer is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * streamer is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with streamer. If not, see <https://www.gnu.org/licenses/>.
- */
-
-#ifndef STREAMER_UTIL_H_
-#define STREAMER_UTIL_H_
-
-#define STR_IMPL(x) #x
-#define STR(x) STR_IMPL(x)
-#define LOG(fmt, ...) \
- fprintf(stderr, __FILE__ ":" STR(__LINE__) " " fmt "\n", ##__VA_ARGS__)
-#define LENGTH(x) (sizeof(x) / sizeof *(x))
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#define _(...) __VA_ARGS__
-
-#endif // STREAMER_UTIL_H_