summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukasz Stanislawski <l.stanislaws@samsung.com>2018-05-14 08:51:06 +0200
committerLukasz Stanislawski <l.stanislaws@samsung.com>2018-06-12 08:55:25 +0000
commitccfc169cd89d7d31f4a6c3138ce8810013493592 (patch)
tree17bd597b9de9128688042574c3b813cbe91944d2
parent680a49e6aedbe1b24373ba3a90fe074c2fa7cb57 (diff)
downloadttsd-worker-task-ccfc169cd89d7d31f4a6c3138ce8810013493592.tar.gz
ttsd-worker-task-ccfc169cd89d7d31f4a6c3138ce8810013493592.tar.bz2
ttsd-worker-task-ccfc169cd89d7d31f4a6c3138ce8810013493592.zip
procfs: Implement reading load averages
Change-Id: I138e545c1adca80ad34bffd41dcde78e077503c8
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/procfs.c29
2 files changed, 28 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ecbf1cf..738674f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,6 +13,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
SET(SRCS
task-worker.c
+ procfs.c
)
ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
diff --git a/src/procfs.c b/src/procfs.c
index 3a285e4..4c906db 100644
--- a/src/procfs.c
+++ b/src/procfs.c
@@ -14,11 +14,36 @@
* limitations under the License.
*/
+#include <stdio.h>
+
#include "procfs.h"
+#include "log.h"
+
+#define LOADAVG_FILEPATH "/proc/loadavg"
-int procfs_read_system_load_average(struct procfs_load_average_info *avg)
+int procfs_read_system_load_average(struct procfs_load_average_info *info)
{
- return -1;
+ float a1, a5, a15;
+
+ FILE *loadavg_fp = fopen(LOADAVG_FILEPATH, "r");
+ if (!loadavg_fp) {
+ ERR("failed to open " LOADAVG_FILEPATH);
+ return -1;
+ }
+
+ if (fscanf(loadavg_fp, "%f %f %f", &a1, &a5, &a15) != 3) {
+ ERR("failed to read " LOADAVG_FILEPATH);
+ fclose(loadavg_fp);
+ return -1;
+ }
+
+ info->one_min_avg = a1;
+ info->five_min_avg = a5;
+ info->fifteen_min_avg = a15;
+
+ fclose(loadavg_fp);
+
+ return 0;
}
int profcs_read_system_cpu_usage(struct procfs_system_cpu_usage_info *usage)