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