@@ -20,13 +20,8 @@ in the source distribution for its full text.
2020#include "RichString.h"
2121
2222
23- static const int MemoryMeter_attributes [] = {
24- MEMORY_USED ,
25- MEMORY_SHARED ,
26- MEMORY_COMPRESSED ,
27- MEMORY_BUFFERS ,
28- MEMORY_CACHE
29- };
23+ extern const int Platform_memoryMeter_attributes []; // OS-specific
24+
3025
3126static void MemoryMeter_updateValues (Meter * this ) {
3227 char * buffer = this -> txtBuffer ;
@@ -35,26 +30,30 @@ static void MemoryMeter_updateValues(Meter* this) {
3530
3631 Settings * settings = this -> host -> settings ;
3732
38- /* shared, compressed and available memory are not supported on all platforms */
39- this -> values [MEMORY_METER_SHARED ] = NAN ;
40- this -> values [MEMORY_METER_COMPRESSED ] = NAN ;
41- this -> values [MEMORY_METER_AVAILABLE ] = NAN ;
33+ /* not all memory classes are supported on all platforms */
34+ for (unsigned int memoryClassIdx = 0 ; memoryClassIdx < Platform_numberOfMemoryClasses ; memoryClassIdx ++ ) {
35+ this -> values [memoryClassIdx ] = NAN ;
36+ }
37+
4238 Platform_setMemoryValues (this );
39+ this -> curItems = (uint8_t ) Platform_numberOfMemoryClasses ;
40+
41+ /* compute the used memory */
42+ double used = 0.0 ;
43+ for (unsigned int memoryClassIdx = 0 ; memoryClassIdx < Platform_numberOfMemoryClasses ; memoryClassIdx ++ ) {
44+ if (Platform_memoryClasses [memoryClassIdx ].countsAsUsed ) {
45+ used += this -> values [memoryClassIdx ];
46+ }
47+ }
48+
49+ /* clear the values we don't want to see */
4350 if ((this -> mode == GRAPH_METERMODE || this -> mode == BAR_METERMODE ) && !settings -> showCachedMemory ) {
44- this -> values [MEMORY_METER_BUFFERS ] = 0 ;
45- this -> values [MEMORY_METER_CACHE ] = 0 ;
51+ for (unsigned int memoryClassIdx = 0 ; memoryClassIdx < Platform_numberOfMemoryClasses ; memoryClassIdx ++ ) {
52+ if (Platform_memoryClasses [memoryClassIdx ].countsAsCache ) {
53+ this -> values [memoryClassIdx ] = NAN ;
54+ }
55+ }
4656 }
47- /* Do not print available memory in bar mode */
48- static_assert (MEMORY_METER_AVAILABLE + 1 == MEMORY_METER_ITEMCOUNT ,
49- "MEMORY_METER_AVAILABLE is not the last item in MemoryMeterValues" );
50- this -> curItems = MEMORY_METER_AVAILABLE ;
51-
52- /* we actually want to show "used + shared + compressed" */
53- double used = this -> values [MEMORY_METER_USED ];
54- if (isPositive (this -> values [MEMORY_METER_SHARED ]))
55- used += this -> values [MEMORY_METER_SHARED ];
56- if (isPositive (this -> values [MEMORY_METER_COMPRESSED ]))
57- used += this -> values [MEMORY_METER_COMPRESSED ];
5857
5958 written = Meter_humanUnit (buffer , used , size );
6059 METER_BUFFER_CHECK (buffer , size , written );
@@ -73,37 +72,16 @@ static void MemoryMeter_display(const Object* cast, RichString* out) {
7372 Meter_humanUnit (buffer , this -> total , sizeof (buffer ));
7473 RichString_appendAscii (out , CRT_colors [METER_VALUE ], buffer );
7574
76- Meter_humanUnit (buffer , this -> values [MEMORY_METER_USED ], sizeof (buffer ));
77- RichString_appendAscii (out , CRT_colors [METER_TEXT ], " used:" );
78- RichString_appendAscii (out , CRT_colors [MEMORY_USED ], buffer );
79-
80- /* shared memory is not supported on all platforms */
81- if (isNonnegative (this -> values [MEMORY_METER_SHARED ])) {
82- Meter_humanUnit (buffer , this -> values [MEMORY_METER_SHARED ], sizeof (buffer ));
83- RichString_appendAscii (out , CRT_colors [METER_TEXT ], " shared:" );
84- RichString_appendAscii (out , CRT_colors [MEMORY_SHARED ], buffer );
85- }
86-
87- /* compressed memory is not supported on all platforms */
88- if (isNonnegative (this -> values [MEMORY_METER_COMPRESSED ])) {
89- Meter_humanUnit (buffer , this -> values [MEMORY_METER_COMPRESSED ], sizeof (buffer ));
90- RichString_appendAscii (out , CRT_colors [METER_TEXT ], " compressed:" );
91- RichString_appendAscii (out , CRT_colors [MEMORY_COMPRESSED ], buffer );
92- }
93-
94- Meter_humanUnit (buffer , this -> values [MEMORY_METER_BUFFERS ], sizeof (buffer ));
95- RichString_appendAscii (out , settings -> showCachedMemory ? CRT_colors [METER_TEXT ] : CRT_colors [METER_SHADOW ], " buffers:" );
96- RichString_appendAscii (out , settings -> showCachedMemory ? CRT_colors [MEMORY_BUFFERS_TEXT ] : CRT_colors [METER_SHADOW ], buffer );
97-
98- Meter_humanUnit (buffer , this -> values [MEMORY_METER_CACHE ], sizeof (buffer ));
99- RichString_appendAscii (out , settings -> showCachedMemory ? CRT_colors [METER_TEXT ] : CRT_colors [METER_SHADOW ], " cache:" );
100- RichString_appendAscii (out , settings -> showCachedMemory ? CRT_colors [MEMORY_CACHE ] : CRT_colors [METER_SHADOW ], buffer );
75+ /* print the OS-specific memory classes in the order supplied by their implementation */
76+ for (unsigned int memoryClassIdx = 0 ; memoryClassIdx < Platform_numberOfMemoryClasses ; memoryClassIdx ++ ) {
77+ if (!settings -> showCachedMemory && Platform_memoryClasses [memoryClassIdx ].countsAsCache )
78+ continue ; // skip reclaimable cache memory classes if "show cached memory" is not ticked
10179
102- /* available memory is not supported on all platforms */
103- if ( isNonnegative ( this -> values [ MEMORY_METER_AVAILABLE ])) {
104- Meter_humanUnit ( buffer , this -> values [ MEMORY_METER_AVAILABLE ], sizeof ( buffer ) );
105- RichString_appendAscii (out , CRT_colors [METER_TEXT ], " available :" );
106- RichString_appendAscii (out , CRT_colors [METER_VALUE ], buffer );
80+ Meter_humanUnit ( buffer , this -> values [ memoryClassIdx ], sizeof ( buffer ));
81+ RichString_appendAscii ( out , CRT_colors [ METER_TEXT ], " " );
82+ RichString_appendAscii ( out , CRT_colors [ METER_TEXT ], Platform_memoryClasses [ memoryClassIdx ]. label );
83+ RichString_appendAscii (out , CRT_colors [METER_TEXT ], ":" );
84+ RichString_appendAscii (out , CRT_colors [Platform_memoryClasses [ memoryClassIdx ]. color ], buffer );
10785 }
10886}
10987
@@ -116,10 +94,10 @@ const MeterClass MemoryMeter_class = {
11694 .updateValues = MemoryMeter_updateValues ,
11795 .defaultMode = BAR_METERMODE ,
11896 .supportedModes = METERMODE_DEFAULT_SUPPORTED ,
119- .maxItems = MEMORY_METER_ITEMCOUNT ,
97+ .maxItems = NUMBER_OF_DYNAMIC_COLORS , // all the range of DYNAMIC_xxxx colors are allowed
12098 .isPercentChart = true,
12199 .total = 100.0 ,
122- .attributes = MemoryMeter_attributes ,
100+ .attributes = Platform_memoryMeter_attributes , // OS-specific
123101 .name = "Memory" ,
124102 .uiName = "Memory" ,
125103 .caption = "Mem"
0 commit comments