0f7558bdafb6b89087005a93a8463f1ec4f76359
[apps/native/ttsd-worker-task.git] / src / process.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 __PROCESS_H
18 #define __PROCESS_H
19
20 #include <json-glib/json-glib.h>
21
22 /**
23  * @brief The process structure.
24  *
25  * @note Do not read fields directly, the struct
26  * is only available publicly to allow easy copy semantic
27  */
28 struct process
29 {
30         int pid;
31         char *appid;
32         char *exe;
33         unsigned long long total_ticks_used;
34         unsigned long long frame_ticks_used;
35         int memory_used;
36         float update_time;
37         float frame_time_inverted;
38 };
39
40 /**
41  * @brief Initialize process module.
42  */
43 int process_init();
44
45 /**
46  * @brief Gets last read process memory usage
47  *
48  * @param[in]: proc process
49  * @param[out]: used the memory usage in KiB
50  *
51  * @return 0 on success, other value on error.
52  */
53 int process_get_memory_usage(struct process *proc, int *used);
54
55 /**
56  * @brief Gets last read process CPU usage
57  *
58  * @param[in]: proc process
59  * @param[out]: usage CPU usage in clock ticks
60  *
61  * @return 0 on success, other value on error.
62  */
63 int process_get_cpu_usage(struct process *proc, unsigned long long *usage);
64
65 /**
66  * @brief Updates process memory & CPU usage data.
67  *
68  * @param[in]: proc process
69  *
70  * @return 0 on success, other value on error.
71  */
72 int process_update(struct process *proc);
73
74 /**
75  * @brief Initializes process structure
76  *
77  * @param[in]: pid
78  * @param[in]: proc process
79  *
80  * @return 0 on success, other value on error.
81  */
82 void process_init_process(int pid, struct process *proc);
83
84 /**
85  * @brief Shutdown process structure
86  *
87  * @param[in]: proc process
88  *
89  * @return 0 on success, other value on error.
90  *
91  * @note the structure should be initialized with @process_init, @process_move
92  */
93 void process_shutdown(struct process *proc);
94
95 /**
96  * @brief Get process pid
97  *
98  * @param[in]: proc process
99  *
100  * @return: pid
101  */
102 int process_get_pid(const struct process *proc);
103
104 /**
105  * @brief Get process application id.
106  *
107  * @param[in]: proc process
108  *
109  * @return: appid or NULL if process is not an Tizen Application.
110  */
111 const char *process_get_appid(struct process *proc);
112
113 /**
114  * @brief Pathname of executed command.
115  *
116  * @param[in]: proc process
117  *
118  * @return: exe file path or NULL in case of error.
119  */
120 const char *process_get_exe(struct process *proc);
121
122 /**
123  * @brief Moves process data from one struct to another.
124  *
125  * @param[in]: dst destination process
126  * @param[in]: src source process
127  */
128 void process_move(struct process *dst, struct process *src);
129
130 /**
131  * @brief Gets average CPU usage percentage since last update.
132  *
133  * @param[in]: proc process
134  * @param[out]: usage the cpu usage percentage
135  *
136  * @return 0 on success, other value on error.
137  */
138 int process_get_cpu_usage_percentage(struct process *proc, float *usage);
139
140 /**
141  * @brief Gets average memory usage percentage on last update.
142  *
143  * @param[in]: proc process
144  * @param[out]: usage the memory usage percentage
145  *
146  * @return 0 on success, other value on error.
147  */
148 int process_get_memory_usage_percentage(struct process *dst, float *usage);
149
150 /**
151  * @brief Serializes process object as json
152  *
153  * @param[in]: proc process
154  * @param[in/out]: the json builder object.
155  */
156 void process_serialize(struct process *dst, JsonBuilder *builer);
157
158 #endif