Skip to content

Commit 8807a8b

Browse files
committed
Add seeding time functions
Signed-off-by: Arnaud Rebillout <[email protected]>
1 parent 5738346 commit 8807a8b

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

src/caseed.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ struct CaSeed {
4848

4949
uint64_t n_requests;
5050
uint64_t n_request_bytes;
51+
52+
uint64_t first_step_nsec;
53+
uint64_t last_step_nsec;
5154
};
5255

5356
CaSeed *ca_seed_new(void) {
@@ -471,10 +474,16 @@ int ca_seed_step(CaSeed *s) {
471474
return -EALREADY;
472475

473476
if (!s->cache_chunks && !s->cache_hardlink) {
477+
if (s->last_step_nsec == 0)
478+
s->last_step_nsec = now(CLOCK_MONOTONIC);
479+
474480
s->ready = true;
475481
return CA_SEED_READY;
476482
}
477483

484+
if (s->first_step_nsec == 0)
485+
s->first_step_nsec = now(CLOCK_MONOTONIC);
486+
478487
r = ca_seed_open(s);
479488
if (r < 0)
480489
return r;
@@ -494,6 +503,9 @@ int ca_seed_step(CaSeed *s) {
494503
if (r < 0)
495504
return r;
496505

506+
if (s->last_step_nsec == 0)
507+
s->last_step_nsec = now(CLOCK_MONOTONIC);
508+
497509
s->ready = true;
498510
return CA_SEED_READY;
499511

@@ -925,3 +937,21 @@ int ca_seed_get_request_bytes(CaSeed *s, uint64_t *ret) {
925937
*ret = s->n_request_bytes;
926938
return 0;
927939
}
940+
941+
int ca_seed_get_seeding_time_nsec(CaSeed *s, uint64_t *ret) {
942+
if (!s)
943+
return -EINVAL;
944+
if (!ret)
945+
return -EINVAL;
946+
947+
if (!s->cache_chunks)
948+
return -ENOTTY;
949+
950+
if (s->first_step_nsec == 0 || s->last_step_nsec == 0)
951+
return -ENODATA;
952+
if (s->first_step_nsec > s->last_step_nsec)
953+
return -ENODATA;
954+
955+
*ret = s->last_step_nsec - s->first_step_nsec;
956+
return 0;
957+
}

src/caseed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ int ca_seed_get_file_root(CaSeed *s, CaFileRoot **ret);
4747

4848
int ca_seed_get_requests(CaSeed *s, uint64_t *ret);
4949
int ca_seed_get_request_bytes(CaSeed *s, uint64_t *ret);
50+
int ca_seed_get_seeding_time_nsec(CaSeed *s, uint64_t *ret);
5051

5152
#endif

src/casync.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,6 +4250,31 @@ int ca_sync_get_seed_request_bytes(CaSync *s, uint64_t *ret) {
42504250
return 0;
42514251
}
42524252

4253+
int ca_sync_get_seed_seeding_time_nsec(CaSync *s, uint64_t *ret) {
4254+
uint64_t sum = 0;
4255+
size_t i;
4256+
int r;
4257+
4258+
if (!s)
4259+
return -EINVAL;
4260+
if (!ret)
4261+
return -EINVAL;
4262+
4263+
/* We can sum seeding times since seeds are processed one after another */
4264+
for (i = 0; i < s->n_seeds; i++) {
4265+
uint64_t x;
4266+
4267+
r = ca_seed_get_seeding_time_nsec(s->seeds[i], &x);
4268+
if (r < 0)
4269+
return r;
4270+
4271+
sum += x;
4272+
}
4273+
4274+
*ret = sum;
4275+
return 0;
4276+
}
4277+
42534278
int ca_sync_get_local_requests(CaSync *s, uint64_t *ret) {
42544279
uint64_t sum;
42554280
size_t i;

src/casync.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ int ca_sync_get_hardlink_digest(CaSync *s, CaChunkID *ret);
152152

153153
int ca_sync_get_seed_requests(CaSync *s, uint64_t *ret);
154154
int ca_sync_get_seed_request_bytes(CaSync *s, uint64_t *ret);
155+
int ca_sync_get_seed_seeding_time_nsec(CaSync *s, uint64_t *ret);
155156
int ca_sync_get_local_requests(CaSync *s, uint64_t *ret);
156157
int ca_sync_get_local_request_bytes(CaSync *s, uint64_t *ret);
157158
int ca_sync_get_remote_requests(CaSync *s, uint64_t *ret);

0 commit comments

Comments
 (0)