File tree Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Original file line number Diff line number Diff 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
5356CaSeed * 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+ }
Original file line number Diff line number Diff line change @@ -47,5 +47,6 @@ int ca_seed_get_file_root(CaSeed *s, CaFileRoot **ret);
4747
4848int ca_seed_get_requests (CaSeed * s , uint64_t * ret );
4949int 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
Original file line number Diff line number Diff 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+
42534278int ca_sync_get_local_requests (CaSync * s , uint64_t * ret ) {
42544279 uint64_t sum ;
42554280 size_t i ;
Original file line number Diff line number Diff line change @@ -152,6 +152,7 @@ int ca_sync_get_hardlink_digest(CaSync *s, CaChunkID *ret);
152152
153153int ca_sync_get_seed_requests (CaSync * s , uint64_t * ret );
154154int 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 );
155156int ca_sync_get_local_requests (CaSync * s , uint64_t * ret );
156157int ca_sync_get_local_request_bytes (CaSync * s , uint64_t * ret );
157158int ca_sync_get_remote_requests (CaSync * s , uint64_t * ret );
You can’t perform that action at this time.
0 commit comments