4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
8 * Cherepanov Vitaliy <v.cherepanov@samsung.com>
9 * Nikita Kalyazin <n.kalyazin@samsung.com>
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
24 * - Samsung RnD Institute Russia
36 #include <linux/input.h>
39 NMSG_KEEP_ALIVE =0x0001,
43 NMSG_BINARY_INFO =0x0005,
44 NMSG_GET_TARGET_INFO =0x0007,
45 NMSG_SWAP_INST_ADD =0x0008,
46 NMSG_SWAP_INST_REMOVE =0x0009,
47 NMSG_GET_SCREENSHOT =0x0010,
49 NMSG_KEEP_ALIVE_ACK =0x1001,
50 NMSG_START_ACK =0x1002,
51 NMSG_STOP_ACK =0x1003,
52 NMSG_CONFIG_ACK =0x1004,
53 NMSG_BINARY_INFO_ACK =0x1005,
54 NMSG_SWAP_INST_ACK =0x1006,
55 NMSG_GET_TARGET_INFO_ACK =0x1007,
56 NMSG_SWAP_INST_ADD_ACK =0x1008,
57 NMSG_SWAP_INST_REMOVE_ACK =0x1009,
59 NMSG_PROCESS_INFO =0x0001, // target process info
60 NMSG_TERMINATE =0x0002, //terminate
61 NMSG_ERROR =0x0003, //error message
62 NMSG_SAMPLE =0x0004, //N 10ms
63 NMSG_SYSTEM =0x0005, //N 10~1000ms DaData, start sending immediately after start message from host, first system message time is tracing start time
64 NMSG_IMAGE =0x0006, //N irregular image
65 NMSG_RECORD =0x0007, //N irregular replay event
66 NMSG_FUNCTION_ENTRY =0x0008, //N irregular swap instrumentation, Instrumented functions by AppInst and LibInst
67 NMSG_FUNCTION_EXIT =0x0009, //N irregular swap instrumentation, Instrumented functions by AppInst and LibInst
68 NMSG_CONTEXT_SWITCH_ENTRY =0x0010, //N irregular swap instrumentation for kernel
69 NMSG_CONTEXT_SWITCH_EXIT =0x0011, //N irregular swap instrumentation for kernel
71 #define MSG_MAX_NUM NMSG_SWAP_INST_REMOVE
75 ERR_LOCKFILE_CREATE_FAILED =-101, //lock file create failed
76 ERR_ALREADY_RUNNING =-102, //already running
77 ERR_INITIALIZE_SYSTEM_INFO_FAILED =-103, //initialize system info failed
78 ERR_HOST_SERVER_SOCKET_CREATE_FAILED =-104, //host server socket create failed
79 ERR_TARGET_SERVER_SOCKET_CREATE_FAILED =-105, //target server socket create failed
81 ERR_SIGNAL_MASK_SETTING_FAILED =-106, //TODO del (old parametr)
83 ERR_WRONG_MESSAGE_FORMAT =-201, //wrong message format
84 ERR_WRONG_MESSAGE_TYPE =-202, //wrong message type
85 ERR_WRONG_MESSAGE_DATA =-203, //wrong message data
86 ERR_CANNOT_START_PROFILING =-204, //cannot start profiling
87 ERR_SERV_SOCK_CREATE =-900, //server socket creation failed (written in /tmp/da.port file)
88 ERR_SERV_SOCK_BIND =-901, //server socket bind failed (written in /tmp/da.port file)
89 ERR_SERV_SOCK_LISTEN =-902, //server socket listen failed (written in /tmp/da.port file)
90 ERR_UNKNOWN =-999 //unknown error
94 FL_RESERVED1 = 0x00000001,
95 FL_RESERVED2 = 0x00000002,
96 FL_FUNCTION_PROFILING = 0x00000004, //On/Off the UserSpaceInst
97 FL_MEMORY_ALLCATION_PROBING = 0x00000008, //memory allocation API (glibc)
98 FL_FILE_API_PROBING = 0x00000010, //file API (glibc, OSP)
99 FL_THREAD_API_PROBING = 0x00000020, //thread API (glibc, OSP)
100 FL_OSP_UI_API_PROBING = 0x00000040, //UI API (OSP)
101 FL_SCREENSHOT = 0x00000080, //Screenshot
102 FL_USER_EVENT = 0x00000100, //events of Touch, Gesture, Orientation, Key
103 FL_RECORDING = 0x00000200, //recording the user event
104 FL_SYSTCALL_FILE = 0x00000400, //File operation syscalls tracing
105 FL_SYSTCALL_IPC = 0x00000800, //IPC syscall tracing
106 FL_SYSTCALL_PROCESS = 0x00001000, //Process syscalls tracing
107 FL_SYSTCALL_SIGNAL = 0x00002000, //Signal syscalls tracing
108 FL_SYSTCALL_NETWORK = 0x00004000, //Network syscalls tracing
109 FL_SYSTCALL_DESC = 0x00008000, //Descriptor syscalls tracing
110 FL_CONTEXT_SWITCH = 0x00010000, //Context switch tracing
111 FL_NETWORK_API_PROBING = 0x00020000, //network API (glibc, OSP, libsoap, openssl)
112 FL_OPENGL_API_PROBING = 0x00040000, //openGL API
113 FL_FUNCTION_SAMPLING = 0x00080000, //Function sampling
114 FL_CPU = 0x00100000, //CPU core load, frequency
115 FL_PROCESSES = 0x00200000, //Process load
116 FL_MEMORY = 0x00400000, //Process size(VSS, PSS. RSS), heap usage(application, library), physical memory in use
117 FL_DISK = 0x00800000,
118 FL_NETWORK = 0x01000000,
119 FL_DEVICE = 0x02000000,
120 FL_ENERGY = 0x04000000,
121 FL_RESERVED3 = 0x08000000,
123 FL_ALL_FEATURES = 0xFFFFFFFF &
129 #define IS_OPT_SET_IN(OPT, reg) (reg & (OPT))
130 #define IS_OPT_SET(OPT) IS_OPT_SET_IN((OPT), prof_session.conf.use_features0)
137 enum supported_device {
141 static const char *supported_devices_strings[] = {
145 #define array_size(x) (sizeof(x)/sizeof((x)[0]))
146 enum { supported_devices_count = array_size(supported_devices_strings) };
148 #define MAX_FILENAME 128
150 #define MSG_DATA_HDR_LEN 20
160 #define MSG_CMD_HDR_LEN 8
177 uint64_t use_features0;
178 uint64_t use_features1;
179 uint32_t system_trace_period;
180 uint32_t data_message_period;
183 typedef uint32_t log_interval_t;
188 APP_TYPE_RUNNING = 2,
200 struct us_func_inst_plane_t {
202 //name | type | len | info
203 //------------------------------------------
204 //func_addr | uint64 | 8 |
205 //args | string | len(args) |end with '\0'
206 //ret_type | char | 1 |
211 struct us_lib_inst_t {
215 struct user_space_inst_t {
217 struct app_list_t *app_inst_list;
219 struct lib_list_t *lib_inst_list;
223 struct replay_event_t {
225 struct input_event ev;
228 struct replay_event_seq_t {
232 struct replay_event_t *events;
235 struct prof_session_t {
237 struct user_space_inst_t user_space_inst;
238 struct replay_event_seq_t replay_event_seq;
239 unsigned running_status:1; // to stop properly (1 - it is running, 0 - no)
242 int parseHostMessage(struct msg_t *log, char *msg);
243 int host_message_handler(struct msg_t *msg);
245 char *msg_ID_str(enum HostMessageT ID);
248 #include <sys/stat.h>
253 struct thread_info_t {
258 struct process_info_t {
263 struct system_info_t {
266 float *cpu_frequency;
268 uint32_t count_of_threads;
269 struct thread_info_t *thread_load;
272 uint32_t count_of_processes;
273 struct process_info_t *process_load;
276 uint32_t virtual_memory;
277 uint32_t resident_memory;
278 uint32_t shared_memory;
280 uint32_t total_alloc_size;
281 uint64_t system_memory_total;
282 uint64_t system_memory_used;
285 uint32_t total_used_drive;
287 uint32_t disk_sectors_read;
288 uint32_t disk_writes;
289 uint32_t disk_sectors_write;
292 uint32_t network_send_size;
293 uint32_t network_receive_size;
296 uint32_t wifi_status;
299 uint32_t brightness_status;
300 uint32_t camera_status;
301 uint32_t sound_status;
302 uint32_t audio_status;
303 uint32_t vibration_status;
304 uint32_t voltage_status;
305 uint32_t rssi_status;
306 uint32_t video_status;
307 uint32_t call_status;
308 uint32_t dnet_status;
312 uint32_t energy_per_device[supported_devices_count];
313 uint32_t app_energy_per_device[supported_devices_count];
316 struct recorded_event_t {
322 #define static_assert(cond) \
323 char __attribute__((unused)) __static_assert[(cond) ? 1 : -1];
325 #define pack_int64(to, n) do { \
326 static_assert(sizeof(n) == 8); \
327 *(uint64_t *)to = n; \
328 to += sizeof(uint64_t); \
331 #define pack_int32(to, n) do { \
332 static_assert(sizeof(n) == 4); \
333 *(uint32_t *)to = n; \
334 to += sizeof(uint32_t); \
337 #define pack_time(to, n) \
339 pack_int32(to, n.tv_sec); \
340 pack_int32(to, n.tv_usec); \
343 #define pack_float(to, n) \
346 to += sizeof(float); \
349 #define pack_str(to, n) \
351 memcpy(to, n, strlen(n) + 1); \
352 to += strlen(n) + 1; \
355 static inline void* pack_str_array(void *buffer, const char **strings,
359 for (index = 0; index != count; ++index)
360 pack_str(buffer, strings[index]);
364 struct msg_data_t *pack_system_info(struct system_info_t *sys_info);
365 int write_to_buf(struct msg_data_t *msg);
366 void free_msg_data(struct msg_data_t *msg);
367 void free_msg_payload(struct msg_t *msg);
368 void free_sys_info(struct system_info_t *sys_info);
369 int start_replay(void);
370 void stop_replay(void);
372 enum ErrorCode stop_all(void);
373 enum ErrorCode stop_all_no_lock(void);
374 int stop_all_in_process(void);
375 void stop_all_done(void);
377 void reset_msg(struct msg_t *msg);
378 void reset_replay_event_seq(struct replay_event_seq_t *res);
379 void reset_system_info(struct system_info_t *sys);
380 int check_running_status(struct prof_session_t *prof_session);
382 extern struct prof_session_t prof_session;
385 void print_replay_event(struct replay_event_t *ev, uint32_t num, char *tab);
387 int sendACKToHost(enum HostMessageT resp, enum ErrorCode err_code,
388 char *payload, int payload_size);
390 int parse_int8(struct msg_buf_t *msg, uint8_t *val);
391 int parse_int32(struct msg_buf_t *msg, uint32_t *val);
392 int parse_int64(struct msg_buf_t *msg, uint64_t *val);
393 int parse_string(struct msg_buf_t *msg, char **str);
394 int parse_string_no_alloc(struct msg_buf_t *msg, char *str);
395 int parse_replay_event_seq(struct msg_buf_t *msg, struct replay_event_seq_t *res);
397 void init_prof_session(struct prof_session_t *prof_session);
398 #endif /* _DA_PROTOCOL_ */