Skip to content

Commit

Permalink
fix bp stats call
Browse files Browse the repository at this point in the history
  • Loading branch information
vazois committed Sep 12, 2024
1 parent 87c575a commit d34f522
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
15 changes: 13 additions & 2 deletions libs/common/Format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,20 @@ public static string GetHostName(ILogger? logger = null)
return "";
}

public static string MegaBytes(long size) => (((size - 1) >> 20) + 1).ToString();
public static string MemoryBytes(long size)
{
if( size < (1 << 20))
return KiloBytes(size);
else if (size < (1 << 30))
return MegaBytes(size);
else return GigaBytes(size);
}

public static string GigaBytes(long size) => (((size - 1) >> 30) + 1).ToString("n0") + "GB";

public static string MegaBytes(long size) => (((size - 1) >> 20) + 1).ToString("n0") + "MB";

public static string KiloBytes(long size) =>(((size - 1) >> 10) + 1).ToString();
public static string KiloBytes(long size) =>(((size - 1) >> 10) + 1).ToString("n0") + "KB";
}
#pragma warning restore format
}
9 changes: 1 addition & 8 deletions libs/common/Memory/LimitedFixedBufferPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,7 @@ public string GetStats()
if (count == 0) continue;

totalBufferCount += count;
bufferStats += $"<{count},{Format.KiloBytes(minAllocationSize * (i + 1))}KB>";

// Keep trying Dequeuing until no items left to free
while (pool[i].items.TryDequeue(out var entry))
{
entry = null;
Interlocked.Decrement(ref pool[i].size);
}
bufferStats += $"<{count}:{Format.MemoryBytes(minAllocationSize << i)}>";
}

if (totalBufferCount > 0)
Expand Down

0 comments on commit d34f522

Please sign in to comment.