From 6b3fbb9c89a49f1ae936cc7db666f9ee09069463 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Wed, 27 Jan 2016 05:03:26 +0100
Subject: taskmgr: Use different units depending on memory usage.

---
 programs/taskmgr/graph.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/programs/taskmgr/graph.c b/programs/taskmgr/graph.c
index df4f922..7f1d09c 100644
--- a/programs/taskmgr/graph.c
+++ b/programs/taskmgr/graph.c
@@ -240,8 +240,10 @@ static void Graph_DrawMemUsageGraph(HDC hDC, HWND hWnd)
 /* Top bars that are "unused", i.e. are dark green, representing free memory */
     int                i;
 
-    static const WCHAR    wszFormat[] = {'%','d','K',0};
-    
+    static const WCHAR    wszFormatKB[] = {'%','u',' ','K','B',0};
+    static const WCHAR    wszFormatMB[] = {'%','u',' ','M','B',0};
+    static const WCHAR    wszFormatGB[] = {'%','.','1','f',' ','G','B',0};
+
     /*
      * Get the client area rectangle
      */
@@ -258,8 +260,13 @@ static void Graph_DrawMemUsageGraph(HDC hDC, HWND hWnd)
     CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK();
     CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK();
 
-    sprintfW(Text, wszFormat, (int)CommitChargeTotal);
-    
+    if (CommitChargeTotal > 1048576)
+        sprintfW(Text, wszFormatGB, (float)CommitChargeTotal / 1048576);
+    else if (CommitChargeTotal > 1024)
+        sprintfW(Text, wszFormatMB, (DWORD)CommitChargeTotal / 1024);
+    else
+        sprintfW(Text, wszFormatKB, (DWORD)CommitChargeTotal);
+
     /*
      * Draw the font text onto the graph
      * The bottom 20 pixels are reserved for the text
-- 
2.6.4

