report-json-serializer: app and top serializers
[apps/native/ttsd-worker-task.git] / src / stats.h
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 #ifndef _STATS_H_
18 #define _STATS_H_
19
20 /**
21  * @brief System's statistics snapshot
22  */
23 struct stats_system
24 {
25         unsigned long long busy_ticks;
26         unsigned long long total_ticks;
27 };
28
29 /**
30  * @brief Process's statistics snapshot
31  */
32 struct stats_process
33 {
34         unsigned long long system_ticks;
35         unsigned long long process_ticks;
36 };
37
38 /**
39  * @brief Initializes stats module.
40  *
41  * @return: 0 on success, other value on error.
42  *
43  * @note function should be called before any other function call from this
44  * module.
45  */
46 int stats_init();
47
48 /**
49  * @brief Calculates average cpu usage between two stats snapshots.
50  *
51  * @param[in] previous the stats snapshots taken before current
52  * @param[in] current the stats snapshots taken after previous
53  * @param[out] usage the cpu usage as percent.
54  *
55  * @return: 0 on success, other value on error
56  */
57 int stats_get_system_cpu_usage_average(struct stats_system *previous, struct stats_system *current, float *usage);
58
59 /**
60  * @brief Takes system statistics snapshot.
61  *
62  * @param[out] stats System's statistics snapshot.
63  *
64  * @return: 0 on success, other value on error
65  */
66 int stats_update_system_stats(struct stats_system *stats);
67
68 /**
69  * @brief Calculates system memory usage.
70  *
71  * @param[out] usage the memory usage as percent.
72  *
73  * @return: 0 on success, other value on error
74  */
75 int stats_get_system_memory_usage(float *usage);
76
77 /**
78  * @brief Takes process statistics snapshot.
79  *
80  * @param[in] pid the process id.
81  * @param[out] stats process statistcs.
82  *
83  * @return: 0 on success, other value on error
84  */
85 int stats_update_process_stats(int pid, struct stats_process *stats);
86
87 /**
88  * @brief Calculates average process cpu usage between two stats snapshots.
89  *
90  * @param[in] previous the stats snapshots taken before current
91  * @param[in] current the stats snapshots taken after previous
92  * @param[out] usage the cpu usage as percent. It may be greater then 100% in
93  * case of multithreaded applications.
94  *
95  * @note in case when process has 2 threads which runs tight loop, the function
96  * will report 200% usage.
97  *
98  * @return: 0 on success, other value on error
99  */
100 int stats_get_process_cpu_usage_average(struct stats_process *previous, struct stats_process *current, float *usage);
101
102 /**
103  * @brief Calculates process memory usage.
104  *
105  * @param[in] pid the process id.
106  * @param[out] usage process memory usage.
107  *
108  * @return: 0 on success, other value on error
109  */
110 int stats_get_process_memory_usage(int pid, float *usage);
111
112 /**
113  * @brief Gets system load averages stats.
114  *
115  * @param[out] a1 one minute average.
116  * @param[out] a5 five minute average.
117  * @param[out] a15 fifteen minute average.
118  *
119  * @return: 0 on success, other value on error
120  */
121 int stats_get_load_averages(float *a1, float *a5, float *a15);
122
123 #endif
124
125