diff options
author | Mikhail Burakov <mburakov@mailbox.org> | 2023-04-08 14:05:46 +0200 |
---|---|---|
committer | Mikhail Burakov <mburakov@mailbox.org> | 2023-04-09 10:26:23 +0200 |
commit | d0c6311e9c9547a9ee10310edf0c47230e15ccbb (patch) | |
tree | 3877815a7ba8460325a65f6e4411628ec8b3ceda | |
parent | e2cb86dd9b565bbbd61a4ed369f2c31960979755 (diff) |
Replace util and perf with toolbox counterparts
-rw-r--r-- | capture.c | 2 | ||||
-rw-r--r-- | encode.c | 4 | ||||
-rw-r--r-- | gpu.c | 3 | ||||
-rw-r--r-- | main.c | 23 | ||||
-rw-r--r-- | makefile | 3 | ||||
-rw-r--r-- | perf.c | 48 | ||||
-rw-r--r-- | perf.h | 35 | ||||
-rw-r--r-- | util.h | 30 |
8 files changed, 21 insertions, 127 deletions
@@ -27,7 +27,7 @@ #include <xf86drmMode.h> #include "gpu.h" -#include "util.h" +#include "toolbox/utils.h" struct CaptureContext { struct GpuContext* gpu_context; @@ -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; @@ -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) { \ @@ -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)) { @@ -2,6 +2,9 @@ bin:=$(notdir $(shell pwd)) src:=$(shell ls *.c) obj:=$(src:.c=.o) +obj+=\ + toolbox/perf.o + libs:=\ egl \ gbm \ @@ -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); -} @@ -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_ @@ -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_ |