summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-07-07 22:26:16 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-07-07 22:26:16 -0700
commit6f87bb7f9302ba82caf721ce901c69baf6ffc886 (patch)
treec184a0097fa31794202a56474d7361b644896774 /src
parent011d4df35a480aac9af4d13fc050064af2b2d050 (diff)
til: introduce til_ticks_now()
Thin wrapper around gettimeofday(), prolly change the main ticks stuff over to this too.
Diffstat (limited to 'src')
-rw-r--r--src/til.c19
-rw-r--r--src/til.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/src/til.c b/src/til.c
index 7ee4744..dec18bf 100644
--- a/src/til.c
+++ b/src/til.c
@@ -26,6 +26,7 @@
#define TIL_DEFAULT_NESTED_MODULE "compose"
static til_threads_t *til_threads;
+static struct timeval til_start_tv;
extern til_module_t blinds_module;
extern til_module_t checkers_module;
@@ -92,6 +93,8 @@ int til_init(void)
if (!(til_threads = til_threads_create()))
return -errno;
+ gettimeofday(&til_start_tv, NULL);
+
return 0;
}
@@ -109,6 +112,22 @@ void til_shutdown(void)
}
+/* returns number of "ticks" since til_init(), which are currently milliseconds */
+unsigned til_ticks_now(void)
+{
+ struct timeval now, diff;
+
+ /* for profiling purposes in particular, it'd be nice to bump up to microseconds...
+ * but then it'll prolly need uint64_t
+ */
+
+ gettimeofday(&now, NULL);
+ timersub(&now, &til_start_tv, &diff);
+
+ return diff.tv_sec * 1000 + diff.tv_usec / 1000;
+}
+
+
/* "blank" built-in module */
static void _blank_prepare_frame(til_module_context_t *context, til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr, til_frame_plan_t *res_frame_plan)
{
diff --git a/src/til.h b/src/til.h
index 318f1b6..6ec43e6 100644
--- a/src/til.h
+++ b/src/til.h
@@ -40,6 +40,7 @@ struct til_module_t {
int til_init(void);
void til_quiesce(void);
void til_shutdown(void);
+unsigned til_ticks_now(void);
const til_module_t * til_lookup_module(const char *name);
void til_get_modules(const til_module_t ***res_modules, size_t *res_n_modules);
char * til_get_module_names(unsigned flags_excluded, const char **exclusions);
© All Rights Reserved