[vlc-devel] [PATCH 2/2] cache_block: restore stat calculation

Ilkka Ollakka ileoo at videolan.org
Sat Apr 21 11:44:23 CEST 2018


Seems that someone missed this stat, restore feature.

Was removed in 9a725a039d8cfcf91aabad0101da1563a627493f
---
 modules/stream_filter/cache_block.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/modules/stream_filter/cache_block.c b/modules/stream_filter/cache_block.c
index f97bd8ea4b..df2b48f3f0 100644
--- a/modules/stream_filter/cache_block.c
+++ b/modules/stream_filter/cache_block.c
@@ -69,6 +69,12 @@ struct stream_sys_t
 {
     block_bytestream_t cache; /* bytestream chain for storing cache */
 
+    struct
+    {
+        /* Stats for calculating speed */
+        uint64_t read_bytes;
+        uint64_t read_time;
+    } stat;
 };
 
 static int AStreamRefillBlock(stream_t *s)
@@ -90,6 +96,7 @@ static int AStreamRefillBlock(stream_t *s)
     }
 
     /* Now read a new block */
+    const mtime_t start = mdate();
     block_t *b;
 
     for (;;)
@@ -103,6 +110,10 @@ static int AStreamRefillBlock(stream_t *s)
         if (vlc_stream_Eof(s->s))
             return VLC_EGENERIC;
     }
+    sys->stat.read_time += mdate() - start;
+    size_t added_bytes;
+    block_ChainProperties( b, NULL, &added_bytes, NULL );
+    sys->stat.read_bytes += added_bytes;
 
     block_BytestreamPush( &sys->cache, b );
     return VLC_SUCCESS;
@@ -117,13 +128,23 @@ static void AStreamPrebufferBlock(stream_t *s)
     msg_Dbg(s, "starting pre-buffering");
     for (;;)
     {
+        const mtime_t now = mdate();
         size_t cache_size = block_BytestreamRemaining( &sys->cache );
 
         if (vlc_killed() || cache_size > STREAM_CACHE_PREBUFFER_SIZE)
         {
-
-            msg_Dbg(s, "prebuffering done %zu bytes in",
-                     cache_size);
+            int64_t byterate;
+
+            /* Update stat */
+            sys->stat.read_bytes = cache_size;
+            sys->stat.read_time = now - start;
+            byterate = (CLOCK_FREQ * sys->stat.read_bytes ) /
+                        (sys->stat.read_time -1);
+
+            msg_Dbg(s, "prebuffering done %zu bytes in %zus - %zu KiB/s",
+                        cache_size,
+                        sys->stat.read_time / CLOCK_FREQ,
+                        byterate / 1024 );
             break;
         }
 
-- 
2.16.3



More information about the vlc-devel mailing list