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
96e03739
Commit
96e03739
authored
Nov 27, 2014
by
Hisham Muhammad
Browse files
Merge branch 'master' into freebsd
parents
3ba3d6fa
5578a316
Changes
3
Show whitespace changes
Inline
Side-by-side
LoadAverageMeter.c
View file @
96e03739
...
@@ -8,8 +8,7 @@ in the source distribution for its full text.
...
@@ -8,8 +8,7 @@ in the source distribution for its full text.
#include "LoadAverageMeter.h"
#include "LoadAverageMeter.h"
#include "CRT.h"
#include "CRT.h"
#include "Platform.h"
#include <assert.h>
/*{
/*{
#include "Meter.h"
#include "Meter.h"
...
@@ -21,21 +20,8 @@ int LoadAverageMeter_attributes[] = {
...
@@ -21,21 +20,8 @@ int LoadAverageMeter_attributes[] = {
int
LoadMeter_attributes
[]
=
{
LOAD
};
int
LoadMeter_attributes
[]
=
{
LOAD
};
static
inline
void
LoadAverageMeter_scan
(
double
*
one
,
double
*
five
,
double
*
fifteen
)
{
int
activeProcs
,
totalProcs
,
lastProc
;
*
one
=
0
;
*
five
=
0
;
*
fifteen
=
0
;
FILE
*
fd
=
fopen
(
PROCDIR
"/loadavg"
,
"r"
);
if
(
fd
)
{
int
total
=
fscanf
(
fd
,
"%32lf %32lf %32lf %32d/%32d %32d"
,
one
,
five
,
fifteen
,
&
activeProcs
,
&
totalProcs
,
&
lastProc
);
(
void
)
total
;
assert
(
total
==
6
);
fclose
(
fd
);
}
}
static
void
LoadAverageMeter_setValues
(
Meter
*
this
,
char
*
buffer
,
int
size
)
{
static
void
LoadAverageMeter_setValues
(
Meter
*
this
,
char
*
buffer
,
int
size
)
{
LoadAverage
Meter_scan
(
&
this
->
values
[
2
],
&
this
->
values
[
1
],
&
this
->
values
[
0
]);
Platform_get
LoadAverage
(
&
this
->
values
[
2
],
&
this
->
values
[
1
],
&
this
->
values
[
0
]);
snprintf
(
buffer
,
size
,
"%.2f/%.2f/%.2f"
,
this
->
values
[
2
],
this
->
values
[
1
],
this
->
values
[
0
]);
snprintf
(
buffer
,
size
,
"%.2f/%.2f/%.2f"
,
this
->
values
[
2
],
this
->
values
[
1
],
this
->
values
[
0
]);
}
}
...
@@ -52,7 +38,7 @@ static void LoadAverageMeter_display(Object* cast, RichString* out) {
...
@@ -52,7 +38,7 @@ static void LoadAverageMeter_display(Object* cast, RichString* out) {
static
void
LoadMeter_setValues
(
Meter
*
this
,
char
*
buffer
,
int
size
)
{
static
void
LoadMeter_setValues
(
Meter
*
this
,
char
*
buffer
,
int
size
)
{
double
five
,
fifteen
;
double
five
,
fifteen
;
LoadAverage
Meter_scan
(
&
this
->
values
[
0
],
&
five
,
&
fifteen
);
Platform_get
LoadAverage
(
&
this
->
values
[
0
],
&
five
,
&
fifteen
);
if
(
this
->
values
[
0
]
>
this
->
total
)
{
if
(
this
->
values
[
0
]
>
this
->
total
)
{
this
->
total
=
this
->
values
[
0
];
this
->
total
=
this
->
values
[
0
];
}
}
...
...
linux/Platform.c
View file @
96e03739
...
@@ -21,6 +21,7 @@ in the source distribution for its full text.
...
@@ -21,6 +21,7 @@ in the source distribution for its full text.
#include "HostnameMeter.h"
#include "HostnameMeter.h"
#include <math.h>
#include <math.h>
#include <assert.h>
/*{
/*{
#include "Action.h"
#include "Action.h"
...
@@ -76,5 +77,19 @@ int Platform_getUptime() {
...
@@ -76,5 +77,19 @@ int Platform_getUptime() {
fscanf
(
fd
,
"%64lf"
,
&
uptime
);
fscanf
(
fd
,
"%64lf"
,
&
uptime
);
fclose
(
fd
);
fclose
(
fd
);
}
}
int
totalseconds
=
(
int
)
floor
(
uptime
);
return
(
int
)
floor
(
uptime
);
}
}
void
Platform_getLoadAverage
(
double
*
one
,
double
*
five
,
double
*
fifteen
)
{
int
activeProcs
,
totalProcs
,
lastProc
;
*
one
=
0
;
*
five
=
0
;
*
fifteen
=
0
;
FILE
*
fd
=
fopen
(
PROCDIR
"/loadavg"
,
"r"
);
if
(
fd
)
{
int
total
=
fscanf
(
fd
,
"%32lf %32lf %32lf %32d/%32d %32d"
,
one
,
five
,
fifteen
,
&
activeProcs
,
&
totalProcs
,
&
lastProc
);
(
void
)
total
;
assert
(
total
==
6
);
fclose
(
fd
);
}
}
unsupported/Platform.c
View file @
96e03739
...
@@ -48,3 +48,9 @@ MeterClass* Platform_meterTypes[] = {
...
@@ -48,3 +48,9 @@ MeterClass* Platform_meterTypes[] = {
int
Platform_getUptime
()
{
int
Platform_getUptime
()
{
return
-
1
;
return
-
1
;
}
}
void
Platform_getLoadAverage
(
double
*
one
,
double
*
five
,
double
*
fifteen
)
{
*
one
=
0
;
*
five
=
0
;
*
fifteen
=
0
;
}
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