Skip to content

Commit 18aba01

Browse files
committed
Add decoding time function
Signed-off-by: Arnaud Rebillout <[email protected]>
1 parent 8807a8b commit 18aba01

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/casync.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ struct CaSync {
148148
uint64_t chunk_size_max;
149149

150150
CaCompressionType compression_type;
151+
152+
uint64_t first_chunk_request_nsec;
153+
uint64_t last_chunk_request_nsec;
151154
};
152155

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

2331+
if (s->last_chunk_request_nsec == 0)
2332+
s->last_chunk_request_nsec = now(CLOCK_MONOTONIC);
2333+
23282334
return CA_SYNC_STEP;
23292335
}
23302336

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

2352+
if (s->first_chunk_request_nsec == 0)
2353+
s->first_chunk_request_nsec = now(CLOCK_MONOTONIC);
2354+
23462355
r = ca_sync_get(s, &s->next_chunk, CA_CHUNK_UNCOMPRESSED, &p, &chunk_size, NULL, &origin);
23472356
if (r == -EAGAIN) /* Don't have this right now, but requested it now */
23482357
return CA_SYNC_STEP;
@@ -4399,6 +4408,21 @@ int ca_sync_get_remote_request_bytes(CaSync *s, uint64_t *ret) {
43994408
return 0;
44004409
}
44014410

4411+
int ca_sync_get_decoding_time_nsec(CaSync *s, uint64_t *ret) {
4412+
if (!s)
4413+
return -EINVAL;
4414+
if (!ret)
4415+
return -EINVAL;
4416+
4417+
if (s->first_chunk_request_nsec == 0 || s->last_chunk_request_nsec == 0)
4418+
return -ENODATA;
4419+
if (s->first_chunk_request_nsec > s->last_chunk_request_nsec)
4420+
return -ENODATA;
4421+
4422+
*ret = s->last_chunk_request_nsec - s->first_chunk_request_nsec;
4423+
return 0;
4424+
}
4425+
44024426
int ca_sync_set_compression_type(CaSync *s, CaCompressionType compression) {
44034427
if (!s)
44044428
return -EINVAL;

src/casync.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ int ca_sync_get_local_request_bytes(CaSync *s, uint64_t *ret);
158158
int ca_sync_get_remote_requests(CaSync *s, uint64_t *ret);
159159
int ca_sync_get_remote_request_bytes(CaSync *s, uint64_t *ret);
160160

161+
int ca_sync_get_decoding_time_nsec(CaSync *s, uint64_t *ret);
162+
161163
int ca_sync_current_cache_hits(CaSync *s, uint64_t *ret);
162164
int ca_sync_current_cache_misses(CaSync *s, uint64_t *ret);
163165
int ca_sync_current_cache_invalidated(CaSync *s, uint64_t *ret);

0 commit comments

Comments
 (0)