Skip to content

Commit

Permalink
Add decoding time function
Browse files Browse the repository at this point in the history
Signed-off-by: Arnaud Rebillout <arnaud.rebillout@collabora.com>
  • Loading branch information
elboulangero committed Feb 26, 2019
1 parent 8807a8b commit 18aba01
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/casync.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ struct CaSync {
uint64_t chunk_size_max;

CaCompressionType compression_type;

uint64_t first_chunk_request_nsec;
uint64_t last_chunk_request_nsec;
};

static CaSync *ca_sync_new(void) {
Expand Down Expand Up @@ -2325,6 +2328,9 @@ static int ca_sync_process_decoder_request(CaSync *s) {
if (r < 0)
return log_debug_errno(r, "Failed to put decoder EOF: %m");

if (s->last_chunk_request_nsec == 0)
s->last_chunk_request_nsec = now(CLOCK_MONOTONIC);

return CA_SYNC_STEP;
}

Expand All @@ -2343,6 +2349,9 @@ static int ca_sync_process_decoder_request(CaSync *s) {
if (!ca_sync_seed_ready(s))
return CA_SYNC_POLL;

if (s->first_chunk_request_nsec == 0)
s->first_chunk_request_nsec = now(CLOCK_MONOTONIC);

r = ca_sync_get(s, &s->next_chunk, CA_CHUNK_UNCOMPRESSED, &p, &chunk_size, NULL, &origin);
if (r == -EAGAIN) /* Don't have this right now, but requested it now */
return CA_SYNC_STEP;
Expand Down Expand Up @@ -4399,6 +4408,21 @@ int ca_sync_get_remote_request_bytes(CaSync *s, uint64_t *ret) {
return 0;
}

int ca_sync_get_decoding_time_nsec(CaSync *s, uint64_t *ret) {
if (!s)
return -EINVAL;
if (!ret)
return -EINVAL;

if (s->first_chunk_request_nsec == 0 || s->last_chunk_request_nsec == 0)
return -ENODATA;
if (s->first_chunk_request_nsec > s->last_chunk_request_nsec)
return -ENODATA;

*ret = s->last_chunk_request_nsec - s->first_chunk_request_nsec;
return 0;
}

int ca_sync_set_compression_type(CaSync *s, CaCompressionType compression) {
if (!s)
return -EINVAL;
Expand Down
2 changes: 2 additions & 0 deletions src/casync.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ int ca_sync_get_local_request_bytes(CaSync *s, uint64_t *ret);
int ca_sync_get_remote_requests(CaSync *s, uint64_t *ret);
int ca_sync_get_remote_request_bytes(CaSync *s, uint64_t *ret);

int ca_sync_get_decoding_time_nsec(CaSync *s, uint64_t *ret);

int ca_sync_current_cache_hits(CaSync *s, uint64_t *ret);
int ca_sync_current_cache_misses(CaSync *s, uint64_t *ret);
int ca_sync_current_cache_invalidated(CaSync *s, uint64_t *ret);
Expand Down

0 comments on commit 18aba01

Please sign in to comment.