procfs: Implement reading load averages
[apps/native/ttsd-worker-task.git] / src / procfs.c
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18
19 #include "procfs.h"
20 #include "log.h"
21
22 #define LOADAVG_FILEPATH "/proc/loadavg"
23
24 int procfs_read_system_load_average(struct procfs_load_average_info *info)
25 {
26         float a1, a5, a15;
27
28         FILE *loadavg_fp = fopen(LOADAVG_FILEPATH, "r");
29         if (!loadavg_fp) {
30                 ERR("failed to open " LOADAVG_FILEPATH);
31                 return -1;
32         }
33
34         if (fscanf(loadavg_fp, "%f %f %f", &a1, &a5, &a15) != 3) {
35                 ERR("failed to read " LOADAVG_FILEPATH);
36                 fclose(loadavg_fp);
37                 return -1;
38         }
39
40         info->one_min_avg = a1;
41         info->five_min_avg = a5;
42         info->fifteen_min_avg = a15;
43
44         fclose(loadavg_fp);
45
46         return 0;
47 }
48
49 int profcs_read_system_cpu_usage(struct procfs_system_cpu_usage_info *usage)
50 {
51         return -1;
52 }
53
54 int profcs_read_system_percpu_usage(struct procfs_system_percpu_usage_info **usage)
55 {
56         return -1;
57 }
58
59 int procfs_read_system_memory_usage(struct procfs_system_memory_usage_info *usage)
60 {
61         return -1;
62 }
63
64 int procfs_read_process_memory_usage(int pid, struct procfs_process_memory_usage_info *usage)
65 {
66         return -1;
67 }
68
69 int procfs_read_process_cpu_usage(int pid, struct procfs_process_cpu_usage_info *usage)
70 {
71         return -1;
72 }
73
74 int procfs_read_uptime(int *uptime)
75 {
76         return -1;
77 }
78
79 int procfs_read_cpu_count(int *cpu_count)
80 {
81         return -1;
82 }