LCOV - code coverage report
Current view: top level - cmdline - bw.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 14 14 100.0 %
Date: 2026-04-29 15:04:44 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-3.0-or-later
       2             : // Copyright (C) 2016 Andrea Mazzoleni
       3             : 
       4             : #include "portable.h"
       5             : 
       6             : #include "bw.h"
       7             : 
       8         247 : void bw_init(struct snapraid_bw* bw, uint64_t limit)
       9             : {
      10         247 :         bw->limit = limit;
      11         247 :         bw->total = 0;
      12         247 :         bw->start = os_tick_ms();
      13         247 : }
      14             : 
      15    10174376 : void bw_limit(struct snapraid_bw* bw, uint64_t bytes)
      16             : {
      17    10174376 :         if (!bw || bw->limit == 0)
      18    10174320 :                 return;
      19             : 
      20          56 :         uint64_t elapsed = os_tick_ms() - bw->start;
      21             :         uint64_t done;
      22             :         uint64_t eta;
      23             : 
      24          56 :         done = __atomic_fetch_add(&bw->total, bytes, __ATOMIC_SEQ_CST);
      25             : 
      26          56 :         eta = done * 1000 / bw->limit;
      27             : 
      28          56 :         if (eta > elapsed) {
      29          52 :                 eta -= elapsed;
      30          52 :                 usleep(eta * 1000);
      31             :         }
      32             : }
      33             : 

Generated by: LCOV version 1.0