Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
cf47f4fc
Commit
cf47f4fc
authored
Jun 12, 2015
by
Christian Hesse
Browse files
use dynamic units for text display
Signed-off-by:
Christian Hesse
<
mail@eworm.de
>
parent
6f58fbc5
Changes
3
Hide whitespace changes
Inline
Side-by-side
MemoryMeter.c
View file @
cf47f4fc
...
...
@@ -40,22 +40,17 @@ static void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
static
void
MemoryMeter_display
(
Object
*
cast
,
RichString
*
out
)
{
char
buffer
[
50
];
Meter
*
this
=
(
Meter
*
)
cast
;
int
k
=
1024
;
const
char
*
format
=
"%ldM "
;
long
int
totalMem
=
this
->
total
/
k
;
long
int
usedMem
=
this
->
values
[
0
]
/
k
;
long
int
buffersMem
=
this
->
values
[
1
]
/
k
;
long
int
cachedMem
=
this
->
values
[
2
]
/
k
;
RichString_write
(
out
,
CRT_colors
[
METER_TEXT
],
":"
);
sprintf
(
buffer
,
format
,
total
Mem
);
Meter_humanUnit
(
buffer
,
this
->
total
,
50
);
RichString_append
(
out
,
CRT_colors
[
METER_VALUE
],
buffer
);
sprintf
(
buffer
,
format
,
usedMem
);
RichString_append
(
out
,
CRT_colors
[
METER_TEXT
],
"used:"
);
Meter_humanUnit
(
buffer
,
this
->
values
[
0
],
50
);
RichString_append
(
out
,
CRT_colors
[
METER_TEXT
],
"
used:"
);
RichString_append
(
out
,
CRT_colors
[
MEMORY_USED
],
buffer
);
sprintf
(
buffer
,
format
,
buffersMem
);
RichString_append
(
out
,
CRT_colors
[
METER_TEXT
],
"buffers:"
);
Meter_humanUnit
(
buffer
,
this
->
values
[
1
],
50
);
RichString_append
(
out
,
CRT_colors
[
METER_TEXT
],
"
buffers:"
);
RichString_append
(
out
,
CRT_colors
[
MEMORY_BUFFERS_TEXT
],
buffer
);
sprintf
(
buffer
,
format
,
cachedMem
);
RichString_append
(
out
,
CRT_colors
[
METER_TEXT
],
"cache:"
);
Meter_humanUnit
(
buffer
,
this
->
values
[
2
],
50
);
RichString_append
(
out
,
CRT_colors
[
METER_TEXT
],
"
cache:"
);
RichString_append
(
out
,
CRT_colors
[
MEMORY_CACHE
],
buffer
);
}
...
...
SwapMeter.c
View file @
cf47f4fc
...
...
@@ -20,19 +20,10 @@ in the source distribution for its full text.
#include "Meter.h"
}*/
#define KILOBYTE 1
#define MEGABYTE 1024
#define GIGABYTE 1048576
int
SwapMeter_attributes
[]
=
{
SWAP
};
/* NOTE: Value is in kilobytes */
static
void
SwapMeter_humanNumber
(
char
*
buffer
,
const
long
int
*
value
)
{
sprintf
(
buffer
,
"%ldM "
,
*
value
/
MEGABYTE
);
}
static
void
SwapMeter_setValues
(
Meter
*
this
,
char
*
buffer
,
int
size
)
{
int
written
;
Platform_setSwapValues
(
this
);
...
...
@@ -49,13 +40,11 @@ static void SwapMeter_setValues(Meter* this, char* buffer, int size) {
static
void
SwapMeter_display
(
Object
*
cast
,
RichString
*
out
)
{
char
buffer
[
50
];
Meter
*
this
=
(
Meter
*
)
cast
;
long
int
swap
=
(
long
int
)
this
->
values
[
0
];
long
int
total
=
(
long
int
)
this
->
total
;
RichString_write
(
out
,
CRT_colors
[
METER_TEXT
],
":"
);
Swap
Meter_human
Number
(
buffer
,
&
total
);
Meter_human
Unit
(
buffer
,
this
->
total
,
50
);
RichString_append
(
out
,
CRT_colors
[
METER_VALUE
],
buffer
);
Swap
Meter_human
Number
(
buffer
,
&
swap
);
RichString_append
(
out
,
CRT_colors
[
METER_TEXT
],
"used:"
);
Meter_human
Unit
(
buffer
,
this
->
values
[
0
],
50
);
RichString_append
(
out
,
CRT_colors
[
METER_TEXT
],
"
used:"
);
RichString_append
(
out
,
CRT_colors
[
METER_VALUE
],
buffer
);
}
...
...
SwapMeter.h
View file @
cf47f4fc
...
...
@@ -11,13 +11,8 @@ in the source distribution for its full text.
#include "Meter.h"
#define KILOBYTE 1
#define MEGABYTE 1024
#define GIGABYTE 1048576
extern
int
SwapMeter_attributes
[];
/* NOTE: Value is in kilobytes */
extern
MeterClass
SwapMeter_class
;
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment