summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2019-08-22 10:58:26 +0200
committerWim Taymans <wtaymans@redhat.com>2019-08-22 10:59:53 +0200
commitc9e177827b6312ffc7f822a293ab304655e83599 (patch)
treebe80285d3214a4c038102b92898d3520d993630c
parent3a43fac0c20057a622aae68e58d95e856f739c44 (diff)
node: calculate cpu time
m---------pipewire-jack12
-rw-r--r--src/pipewire/node.c31
-rw-r--r--src/pipewire/private.h5
3 files changed, 38 insertions, 10 deletions
diff --git a/pipewire-jack b/pipewire-jack
-Subproject 2c25b8c21652bf74cf23f0a862e80e717da69d1
+Subproject 33cac9932c0febb6c0219b30795b4c1bb01a416
diff --git a/src/pipewire/node.c b/src/pipewire/node.c
index 9d2fee3f..13765b81 100644
--- a/src/pipewire/node.c
+++ b/src/pipewire/node.c
@@ -783,6 +783,18 @@ static inline int resume_node(struct pw_node *this, int status)
return 0;
}
+static inline void calculate_stats(struct pw_node *this, struct pw_node_activation *a)
+{
+ if (a->signal_time > a->prev_signal_time) {
+ uint64_t process_time = a->finish_time - a->signal_time;
+ uint64_t period_time = a->signal_time - a->prev_signal_time;
+ float load = (float) process_time / (float) period_time;
+ a->cpu_load[0] = (a->cpu_load[0] * 7.0f + load) / 8.0f;
+ a->cpu_load[1] = (a->cpu_load[1] * 15.0f + load) / 16.0f;
+ a->cpu_load[2] = (a->cpu_load[2] * 31.0f + load) / 32.0f;
+ }
+}
+
static inline int process_node(void *data)
{
struct pw_node *this = data;
@@ -814,9 +826,17 @@ static inline int process_node(void *data)
a->status = FINISHED;
a->signal_time = a->finish_time;
a->finish_time = SPA_TIMESPEC_TO_NSEC(&ts);
- pw_log_trace_fp(NAME" %p: graph completed wait:%"PRIu64" run:%"PRIu64, this,
+
+ /* calculate CPU time */
+ calculate_stats(this, a);
+
+ pw_log_trace_fp(NAME" %p: graph completed wait:%"PRIu64" run:%"PRIu64
+ " period:%"PRIu64" cpu:%f:%f:%f", this,
a->awake_time - a->signal_time,
- a->finish_time - a->awake_time);
+ a->finish_time - a->awake_time,
+ a->signal_time - a->prev_signal_time,
+ a->cpu_load[0], a->cpu_load[1], a->cpu_load[2]);
+
} else if (status == SPA_STATUS_OK) {
pw_log_trace_fp(NAME" %p: async continue", this);
} else {
@@ -1143,15 +1163,18 @@ static int node_ready(void *data, int status)
node->driver, node->exported, driver, status);
if (node == driver) {
- if (node->rt.activation->state[0].pending != 0) {
+ struct pw_node_activation *a = node->rt.activation;
+
+ if (a->state[0].pending != 0) {
pw_log_warn(NAME" %p: graph not finished", node);
dump_states(node);
- node->rt.target.signal(node->rt.target.data);
+ node->rt.target.signal(node->rt.target.data);
}
spa_list_for_each(t, &driver->rt.target_list, link) {
pw_node_activation_state_reset(&t->activation->state[0]);
t->activation->status = NOT_TRIGGERED;
}
+ a->prev_signal_time = a->signal_time;
}
if (node->driver && !node->master)
return 0;
diff --git a/src/pipewire/private.h b/src/pipewire/private.h
index 282d183c..4370a982 100644
--- a/src/pipewire/private.h
+++ b/src/pipewire/private.h
@@ -358,9 +358,12 @@ struct pw_node_activation {
uint64_t signal_time;
uint64_t awake_time;
uint64_t finish_time;
+ uint64_t prev_signal_time;
struct spa_io_position position;
- struct pw_node_activation_state state[2]; /* one current state and one next state */
+ struct pw_node_activation_state state[2]; /* one current state and one next state,
+ * as low bit of version in position */
+ float cpu_load[3]; /* averaged over short, medium, long time */
};
#define pw_node_emit(o,m,v,...) spa_hook_list_call(&o->listener_list, struct pw_node_events, m, v, ##__VA_ARGS__)