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
670a2de6
Commit
670a2de6
authored
Nov 30, 2015
by
Hisham Muhammad
Browse files
Merge pull request #313 from hishamhm/sreclaimable
Update calculation of used vs. free memory.
parents
96c929f8
a84aa2e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
linux/LinuxProcessList.c
View file @
670a2de6
...
...
@@ -621,6 +621,8 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
static
inline
void
LinuxProcessList_scanMemoryInfo
(
ProcessList
*
this
)
{
unsigned
long
long
int
swapFree
=
0
;
unsigned
long
long
int
shmem
=
0
;
unsigned
long
long
int
sreclaimable
=
0
;
FILE
*
file
=
fopen
(
PROCMEMINFOFILE
,
"r"
);
if
(
file
==
NULL
)
{
...
...
@@ -629,33 +631,39 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
char
buffer
[
128
];
while
(
fgets
(
buffer
,
128
,
file
))
{
#define tryRead(label, variable) (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %32llu kB", variable))
switch
(
buffer
[
0
])
{
case
'M'
:
if
(
String_startsWith
(
buffer
,
"MemTotal:"
))
sscanf
(
buffer
,
"MemTotal: %32llu kB"
,
&
this
->
totalMem
);
else
if
(
String_startsWith
(
buffer
,
"MemFree:"
))
sscanf
(
buffer
,
"MemFree: %32llu kB"
,
&
this
->
freeMem
);
else
if
(
String_startsWith
(
buffer
,
"MemShared:"
))
sscanf
(
buffer
,
"MemShared: %32llu kB"
,
&
this
->
sharedMem
);
if
(
tryRead
(
"MemTotal:"
,
&
this
->
totalMem
))
{}
else
if
(
tryRead
(
"MemFree:"
,
&
this
->
freeMem
))
{}
else
if
(
tryRead
(
"MemShared:"
,
&
this
->
sharedMem
))
{}
break
;
case
'B'
:
if
(
String_startsWith
(
buffer
,
"Buffers:"
))
sscanf
(
buffer
,
"Buffers: %32llu kB"
,
&
this
->
buffersMem
);
if
(
tryRead
(
"Buffers:"
,
&
this
->
buffersMem
))
{}
break
;
case
'C'
:
if
(
String_startsWith
(
buffer
,
"Cached:"
))
sscanf
(
buffer
,
"Cached: %32llu kB"
,
&
this
->
cachedMem
);
if
(
tryRead
(
"Cached:"
,
&
this
->
cachedMem
))
{}
break
;
case
'S'
:
if
(
String_startsWith
(
buffer
,
"SwapTotal:"
))
sscanf
(
buffer
,
"SwapTotal: %32llu kB"
,
&
this
->
totalSwap
);
if
(
String_startsWith
(
buffer
,
"SwapFree:"
))
sscanf
(
buffer
,
"SwapFree: %32llu kB"
,
&
swapFree
);
switch
(
buffer
[
1
])
{
case
'w'
:
if
(
tryRead
(
"SwapTotal:"
,
&
this
->
totalSwap
))
{}
else
if
(
tryRead
(
"SwapFree:"
,
&
swapFree
))
{}
break
;
case
'h'
:
if
(
tryRead
(
"Shmem:"
,
&
shmem
))
{}
break
;
case
'R'
:
if
(
tryRead
(
"SReclaimable:"
,
&
sreclaimable
))
{}
break
;
}
break
;
}
#undef tryRead
}
this
->
usedMem
=
this
->
totalMem
-
this
->
freeMem
;
this
->
cachedMem
=
this
->
cachedMem
+
sreclaimable
-
shmem
;
this
->
usedSwap
=
this
->
totalSwap
-
swapFree
;
fclose
(
file
);
}
...
...
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