4 * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 * @desc Contains API to get information about event and processes statistics.
24 #ifndef _LOGD_LOGD_DATA_H_
25 #define _LOGD_LOGD_DATA_H_
34 enum logd_socket_req_type {
42 struct logd_device_stat {
43 /** Device identifier */
44 enum logd_object type;
45 /** total power consumed by device in uAh */
47 /** current power consumption in mA */
51 struct logd_event_info {
52 /** Object - 1st parameter in <CODE>logd_event</CODE> function*/
53 enum logd_object object;
54 /** Action - 2nd parameter in <CODE>logd_event</CODE> function*/
55 enum logd_action action;
56 /** Time when event was created */
58 /** Full path to application that created event */
60 /** Message of event. 3rd parameter in <CODE>logd_event</CODE> function */
64 struct logd_proc_stat {
66 * Full path to application. If it starts from '[' then it's
70 uint64_t utime; /** User CPU time in msec */
71 uint64_t stime; /** System CPU time in msec */
72 float utime_power_cons, stime_power_cons;
73 int is_active; /* application is running now */
75 * Persentage from CPU time of all applications.
76 * persentage = (utime + stime) / (all_app_utime + all_app_stime)
82 struct logd_events_filter {
83 /** Start process events from that time in unixtime format */
85 /** Process events till that time in unixtime format */
88 * Mask that describes what events process. If you want to load only
89 * event whete action is <CODE>LOGD_WIFI</CODE> or
90 * <CODE>LOGD_DISPLAY</CODE> you must assign:
92 * filter.actions_mask[LOGD_WIFI] = 1;
93 * filter.actions_mask[LOGD_DISPLAY] = 1;
96 int actions_mask[LOGD_ACTION_MAX];
97 /** Is's like <CODE>actions_mask</CODE> but for object */
98 int objects_mask[LOGD_OBJECT_MAX];
103 LOGD_DB_QUERY_CONTINUE,
107 * Through events that database contains.
109 * @param filter give ability to clarify parameters of events that you want
110 * to process. If NULL then process all event from database.
111 * @param cb pointer to function that will call for each event.
112 * @param user_data any data that must be given to <CODE>cb</CODE>. May be NULL.
114 * @return On succes, 0. On error, negative value.
118 * enum logd_db_query cb(const struct logd_event_info *event, void *user_data)
124 * time_sec = event->time;
125 * localtime_r(&time_sec, &st);
126 * strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", &st);
127 * printf("%s %s %s\n", event->application, timestr, event->message);
129 * return LOGD_DB_QUERY_CONTINUE;
132 * logd_foreach_events(&filter, &cb, NULL);
135 int logd_foreach_events(const struct logd_events_filter *filter,
136 enum logd_db_query (*cb)(const struct logd_event_info *, void *), void *user_data);
139 * Through precess statistics. Statistics counted start from logd_grabber
140 * started (usually starts from target's switch on).
142 * @param cb pointer to function that will call for each process.
143 * @param user_data any data that must be given to <CODE>cb</CODE>. May be NULL.
145 * @return On succes, 0. On error, negative value.
147 * Example usage like <CODE>logd_foreach_events</CODE>.
149 int logd_foreach_proc_stat(enum logd_db_query (*cb) (const struct logd_proc_stat *, void *),
153 * Through devices statistics.
155 * @param cb pointer to function that will call for each device.
156 * (Now implemented only for backlight - display.
157 * @param user_data any data that must be given to <CODE>cb</CODE>. May be NULL.
159 * @return On succes, 0. On error, negative value.
161 * Example usage like <CODE>logd_foreach_events</CODE>.
163 int logd_foreach_devices_stat(enum logd_db_query (*cb)
164 (const struct logd_device_stat *, void *), void *user_data);
167 struct logd_battery_level {
170 float k; /** Speed of charging (may be negative) */
173 struct logd_battery_info {
174 struct logd_battery_level *levels;
179 * Return information about battery level. Returned object can be provided in
180 * logd_battery_level_at to get battery level at exact time.
182 * @return On success <CODE>struct logd_battery_info</CODE> object. On error, NULL.
183 * Returned object must be released by <CODE>logd_free_battery_info</CODE>.
185 struct logd_battery_info* logd_get_battery_info(void);
188 * Release memory used by <CODE>info</CODE>.
190 * @param info relased object.
192 void logd_free_battery_info(struct logd_battery_info *info);
195 * Return index when info->levels[index].level == level.
197 * @param info object returned by <CODE>logd_get_battery_info</CODE>.
198 * @param level the battery level index of what you want to find.
200 * @return index of info->levels. Great then 0 if the level was found,
201 * 0 if not found, less then 0 in error case. Max level is 10000 - 100%.
203 int logd_seek_battery_level(struct logd_battery_info *info, int level);
206 * Provide battery level at certain time. Max level is 10000 - 100%.
208 * @param info object returned by <CODE>logd_get_battery_info</CODE>.
209 * @param date battery level at that time will be returned.
211 * @return battery level in percentage.
213 float logd_battery_level_at(const struct logd_battery_info *info, time_t date);
216 * Provide battery charging/discharging speed at certain time.
218 * @param info object returned by <CODE>logd_get_battery_info</CODE>.
219 * @param date battery charging speed at that time will be returned.
221 * @return battery charging/discharging (if value is negative) in persents/sec.
223 float logd_battery_charging_speed_at(const struct logd_battery_info *info, time_t date);
226 * Provide info about estimate remaining battery lifetime for each
227 * available power mode from <CODE>logd_power_mode</CODE>.
229 * @param estimate_times pointer to int pointer that will cantains
230 * estimate time for all power modes. It has to be released by
231 * <CODE>free</CODE> if functions terminated successfully.
233 * @return On succes, 0. On error, negative value.
237 * int *estimate_times = NULL;
238 * if (logd_get_estimate_battery_lifetime(&estimate_times) < 0) {
242 * for (int i = 0; i < LOGD_POWER_MODE_MAX; ++i)
243 * printf("%d\n", estimate_times[i]);
244 * free(estimate_times);
247 int logd_get_estimate_battery_lifetime(int **estimate_times);
250 * Provide information about energy efficiency for all launched applications.
251 * power_efficiency = power_cons / time * 3600 (how much energy will used
252 * in a hour by that application. More is worse.
254 * @param cb a callback that will called for all applications. It receive
255 * three parameters: path to the binary, energy efficiency for that binary
256 * and any user data (see next parameter). Power efficiency can be computed
257 * only when the application has running long enough (more then 2 hour in
258 * the current realization). If it's less then 2 hours then efficiency will
261 * @param user_data any data that will be given to <CODE>cb</CODE>. May be NULL.
263 * @return On succes, 0. On error, negative value.
265 int logd_foreach_apps_energy_efficiency(enum logd_db_query (*cb)
266 (const char *application, float efficiency, void *user_data), void *user_data);
271 #endif /* _LOGD_LOGD_DATA_H_ */