mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
pulse-server: implement stats
This commit is contained in:
parent
d82066e49f
commit
7e5441fbb3
2 changed files with 33 additions and 14 deletions
|
|
@ -118,6 +118,7 @@ enum {
|
|||
|
||||
struct message {
|
||||
struct spa_list link;
|
||||
struct stats *stat;
|
||||
uint32_t extra[4];
|
||||
uint32_t channel;
|
||||
uint32_t allocated;
|
||||
|
|
@ -441,13 +442,19 @@ static int message_get(struct message *m, ...)
|
|||
|
||||
static int ensure_size(struct message *m, uint32_t size)
|
||||
{
|
||||
uint32_t alloc;
|
||||
uint32_t alloc, diff;
|
||||
void *data;
|
||||
|
||||
if (m->length + size <= m->allocated)
|
||||
return size;
|
||||
|
||||
alloc = SPA_ROUND_UP_N(SPA_MAX(m->allocated + size, 4096u), 4096u);
|
||||
if ((m->data = realloc(m->data, alloc)) == NULL)
|
||||
diff = alloc - m->allocated;
|
||||
if ((data = realloc(m->data, alloc)) == NULL)
|
||||
return -errno;
|
||||
m->stat->allocated += diff;
|
||||
m->stat->accumulated += diff;
|
||||
m->data = data;
|
||||
m->allocated = alloc;
|
||||
return size;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,14 @@
|
|||
#include "defs.h"
|
||||
#include "json.h"
|
||||
|
||||
struct stats {
|
||||
uint32_t n_allocated;
|
||||
uint32_t allocated;
|
||||
uint32_t n_accumulated;
|
||||
uint32_t accumulated;
|
||||
uint32_t sample_cache;
|
||||
};
|
||||
|
||||
#include "format.c"
|
||||
#include "volume.c"
|
||||
#include "message.c"
|
||||
|
|
@ -86,13 +94,6 @@ struct client;
|
|||
|
||||
#include "sample.c"
|
||||
|
||||
struct operation {
|
||||
struct spa_list link;
|
||||
struct client *client;
|
||||
uint32_t tag;
|
||||
void (*callback) (struct operation *op);
|
||||
};
|
||||
|
||||
struct client {
|
||||
struct spa_list link;
|
||||
struct impl *impl;
|
||||
|
|
@ -229,6 +230,8 @@ struct impl {
|
|||
struct spa_list servers;
|
||||
|
||||
struct pw_map samples;
|
||||
|
||||
struct stats stat;
|
||||
};
|
||||
|
||||
#include "collect.c"
|
||||
|
|
@ -240,6 +243,8 @@ static void sample_free(struct sample *sample)
|
|||
|
||||
pw_log_info("free sample id:%u name:%s", sample->index, sample->name);
|
||||
|
||||
impl->stat.sample_cache -= sample->length;
|
||||
|
||||
if (sample->index != SPA_ID_INVALID)
|
||||
pw_map_remove(&impl->samples, sample->index);
|
||||
if (sample->props)
|
||||
|
|
@ -276,6 +281,8 @@ static void message_free(struct client *client, struct message *msg, bool dequeu
|
|||
spa_list_remove(&msg->link);
|
||||
if (destroy) {
|
||||
pw_log_trace("destroy message %p", msg);
|
||||
msg->stat->n_allocated--;
|
||||
msg->stat->allocated -= msg->allocated;
|
||||
free(msg->data);
|
||||
free(msg);
|
||||
} else {
|
||||
|
|
@ -296,6 +303,9 @@ static struct message *message_alloc(struct client *client, uint32_t channel, ui
|
|||
if (msg == NULL) {
|
||||
msg = calloc(1, sizeof(struct message));
|
||||
pw_log_trace("new message %p", msg);
|
||||
msg->stat = &client->impl->stat;
|
||||
msg->stat->n_allocated++;
|
||||
msg->stat->n_accumulated++;
|
||||
}
|
||||
if (msg == NULL)
|
||||
return NULL;
|
||||
|
|
@ -2278,6 +2288,8 @@ static int do_finish_upload_stream(struct client *client, uint32_t command, uint
|
|||
sample->buffer = stream->buffer;
|
||||
sample->length = stream->attr.maxlength;
|
||||
|
||||
impl->stat.sample_cache += sample->length;
|
||||
|
||||
stream->props = NULL;
|
||||
stream->buffer = NULL;
|
||||
stream_free(stream);
|
||||
|
|
@ -3206,11 +3218,11 @@ static int do_stat(struct client *client, uint32_t command, uint32_t tag, struct
|
|||
|
||||
reply = reply_new(client, tag);
|
||||
message_put(reply,
|
||||
TAG_U32, 0, /* n_allocated */
|
||||
TAG_U32, 0, /* allocated size */
|
||||
TAG_U32, 0, /* n_accumulated */
|
||||
TAG_U32, 0, /* accumulated_size */
|
||||
TAG_U32, 0, /* sample cache size */
|
||||
TAG_U32, impl->stat.n_allocated, /* n_allocated */
|
||||
TAG_U32, impl->stat.allocated, /* allocated size */
|
||||
TAG_U32, impl->stat.n_accumulated, /* n_accumulated */
|
||||
TAG_U32, impl->stat.accumulated, /* accumulated_size */
|
||||
TAG_U32, impl->stat.sample_cache, /* sample cache size */
|
||||
TAG_INVALID);
|
||||
|
||||
return send_message(client, reply);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue