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
37 #include <linux/input.h>
38 #include <linux/limits.h>
41 #define PROTOCOL_VERSION "4.2"
44 MAX_RAW_MESSAGE_SIZE = 8*1024,
48 #include "da_msg_ids.h"
53 #define X(id, val) id = val,
57 NMSG_WRT_LAUNCHER_PORT =0x8001,
58 NMSG_ACK_FLAG =0x1000,
61 #define X(id, val) id ## _ACK = val + NMSG_ACK_FLAG,
68 #define X(id, val) id = val,
73 #define MSG_MAX_NUM NMSG_SWAP_INST_REMOVE
76 ERR_NO = 0, /* success */
77 ERR_LOCKFILE_CREATE_FAILED = -101, /* lock file create failed */
78 ERR_ALREADY_RUNNING = -102, /* already running */
79 ERR_INITIALIZE_SYSTEM_INFO_FAILED = -103, /* initialize system info failed */
80 ERR_HOST_SERVER_SOCKET_CREATE_FAILED = -104, /* host server socket create failed */
81 ERR_TARGET_SERVER_SOCKET_CREATE_FAILED = -105, /* target server socket create failed */
82 ERR_UI_TARGET_SERVER_SOCKET_CREATE_FAILED = -107, /* ui target server socket create failed */
84 ERR_SIGNAL_MASK_SETTING_FAILED = -106, /* TODO del (old parametr) */
86 ERR_WRONG_MESSAGE_FORMAT = -201, /* wrong message format */
87 ERR_WRONG_MESSAGE_TYPE = -202, /* wrong message type */
88 ERR_WRONG_MESSAGE_DATA = -203, /* wrong message data */
89 ERR_CANNOT_START_PROFILING = -204, /* cannot start profiling */
90 ERR_TO_LONG_MESSAGE = -205, /* message is too long to process */
91 ERR_TARGET_NOT_FOUND = -206, /* some target in message not found like file or some else */
92 ERR_UI_OBJ_NOT_FOUND = -207, /* requested ui object is not found */
93 ERR_UI_OBJ_SCREENSHOT_FAILED = -208, /* taking ui screenshot failed because App is in background */
94 ERR_NOT_SUPPORTED = -800, /* request not supported by security reason */
95 ERR_SERV_SOCK_CREATE = -900, /* server socket creation failed (written in /tmp/da.port file) */
96 ERR_SERV_SOCK_BIND = -901, /* server socket bind failed (written in /tmp/da.port file) */
97 ERR_SERV_SOCK_LISTEN = -902, /* server socket listen failed (written in /tmp/da.port file) */
98 ERR_UNKNOWN = -999 /* unknown error */
101 #define FL_SYSTEM_ENERGY_OLD (1<<26)
103 enum feature_code_0 {
104 FL_RESERVED1 = 0x0000000000003ULL, // reserved 0011
106 FL_FUNCTION_PROFILING = 0x0000000000004ULL, // 0x4 * 0x10^00 On/Off the UserSpaceInst
107 FL_MEMORY_ALLOC_PROBING = 0x0000000000008ULL, // 0x8 * 0x10^00 memory allocation API (glibc)
108 FL_FILE_API_PROBING = 0x0000000000010ULL, // 0x1 * 0x10^01 file API (glibc, OSP)
109 FL_THREAD_API_PROBING = 0x0000000000020ULL, // 0x2 * 0x10^01 thread API (glibc, OSP)
110 FL_OSP_UI_API_PROBING = 0x0000000000040ULL, // 0x4 * 0x10^01 UI API (OSP)
111 FL_SCREENSHOT = 0x0000000000080ULL, // 0x8 * 0x10^01 Screenshot
112 FL_USER_EVENT = 0x0000000000100ULL, // 0x1 * 0x10^02 events of Touch, Gesture, Orientation, Key
113 FL_RECORDING = 0x0000000000200ULL, // 0x2 * 0x10^02 recording the user event
114 FL_SYSTCALL_FILE = 0x0000000000400ULL, // 0x4 * 0x10^02 File operation syscalls tracing
115 FL_SYSTCALL_IPC = 0x0000000000800ULL, // 0x8 * 0x10^02 IPC syscall tracing
116 FL_SYSTCALL_PROCESS = 0x0000000001000ULL, // 0x1 * 0x10^03 Process syscalls tracing
117 FL_SYSTCALL_SIGNAL = 0x0000000002000ULL, // 0x2 * 0x10^03 Signal syscalls tracing
118 FL_SYSTCALL_NETWORK = 0x0000000004000ULL, // 0x4 * 0x10^03 Network syscalls tracing
119 FL_SYSTCALL_DESC = 0x0000000008000ULL, // 0x8 * 0x10^03 Descriptor syscalls tracing
120 FL_CONTEXT_SWITCH = 0x0000000010000ULL, // 0x1 * 0x10^04 Context switch tracing
121 FL_NETWORK_API_PROBING = 0x0000000020000ULL, // 0x2 * 0x10^04 network API (glibc, OSP, libsoap, openssl)
122 FL_OPENGL_API_PROBING = 0x0000000040000ULL, // 0x4 * 0x10^04 openGL API
123 FL_FUNCTION_SAMPLING = 0x0000000080000ULL, // 0x8 * 0x10^04 Function sampling
125 FL_RESERVED2 = 0x000000FF00000ULL, // 0x1 * 0x10^00 reserved
127 FL_MEMORY_ALLOC_ALWAYS_PROBING = 0x0000010000000ULL, // 0x1 * 0x10^07 all (include external) memory allocation API (glibc) always
128 FL_FILE_API_ALWAYS_PROBING = 0x0000020000000ULL, // 0x2 * 0x10^07 all (include external) file API (glibc, OSP) always
129 FL_THREAD_API_ALWAYS_PROBING = 0x0000040000000ULL, // 0x4 * 0x10^07 all (include external) thread API (glibc, OSP) always
130 FL_OSP_UI_API_ALWAYS_PROBING = 0x0000080000000ULL, // 0x8 * 0x10^07 all (include external) UI API (OSP) always
131 FL_NETWORK_API_ALWAYS_PROBING = 0x0000100000000ULL, // 0x1 * 0x10^08 all (include external) network API (glibc, OSP, libsoap, openssl) always
132 FL_OPENGL_API_ALWAYS_PROBING = 0x0000200000000ULL, // 0x2 * 0x10^08 all (include external) openGL API always
134 FL_RESERVED3 = 0x0000c00000000ULL, // 0x1 * 0x10^00 reserved
136 FL_SYSTEM_CPU = 0x0001000000000ULL, // 0x1 * 0x10^09 CPU core load, frequency
137 FL_SYSTEM_MEMORY = 0x0002000000000ULL, // 0x2 * 0x10^09 System memory used
138 FL_SYSTEM_PROCESS = 0x0004000000000ULL, // 0x4 * 0x10^09 Info for profilling processes (VSS, PSS, RSS, etc)
139 FL_SYSTEM_THREAD_LOAD = 0x0008000000000ULL, // 0x8 * 0x10^09 Thread loading for profiling processes
140 FL_SYSTEM_PROCESSES_LOAD = 0x0010000000000ULL, // 0x1 * 0x10^10 Non instrumented process load
141 FL_SYSTEM_DISK = 0x0020000000000ULL, // 0x2 * 0x10^10 /proc/diskstats - reads, sectors read, writes, sectors written
142 FL_SYSTEM_NETWORK = 0x0040000000000ULL, // 0x4 * 0x10^10 network send/recv size
143 FL_SYSTEM_DEVICE = 0x0080000000000ULL, // 0x8 * 0x10^10
144 FL_SYSTEM_ENERGY = 0x0100000000000ULL, // 0x1 * 0x10^11
146 FL_APP_STARTUP = 0x0200000000000ULL, // 0x2 * 0x10^11 see MSG_APP_SETUP_STAGE in data channel
147 FL_WEB_PROFILING = 0x0400000000000ULL, // 0x4 * 0x10^11 Web profiling
148 FL_WEB_STARTUP_PROFILING = 0x0800000000000ULL, // 0x8 * 0x10^11 Web startup profiling
150 FL_SYSTEM_FILE_ACTIVITY = 0x1000000000000ULL, // 0x1 * 0x10^12 function entry/exit for probe type 04 (File syscall)
152 FL_UI_VIEWER_PROFILING = 0x2000000000000ULL, // 0x2 * 0x10^12 load ui viewer library
153 FL_LSAN_ENABLED = 0x4000000000000ULL, // 0x4 * 0x10^12 LSan enabled
155 FL_RESERVED4 = 0x8000000000000ULL, // reserved 1100
157 FL_ALL_FEATURES_0 = 0x7FFFFFFFFFFFFULL &
165 enum feature_code_1 {
166 FL_MEMORY_ALLOC_PROBING_PRELOAD = 0x0000000000001ULL, // 0x1 memory allocation API (glibc) based on preload
167 FL_FILE_API_PROBING_PRELOAD = 0x0000000000002ULL, // 0x2 file API (glibc, OSP) based on preload
168 FL_THREAD_API_PROBING_PRELOAD = 0x0000000000004ULL, // 0x4 thread API (glibc, OSP) based on preload
169 FL_NETWORK_API_PROBING_PRELOAD = 0x0000000000008ULL, // 0x8 network API (glibc, OSP, libsoap, openssl) based on preload
170 FL_OPENGL_API_PROBING_PRELOAD = 0x0000000000010ULL, // 0x10 openGL API based on preload
172 FL_MEMORY_ALLOC_ALWAYS_PROBING_PRELOAD = 0x0000000000020ULL, // 0x20 all (include external) memory allocation API (glibc) always based on preload
173 FL_FILE_API_ALWAYS_PROBING_PRELOAD = 0x0000000000040ULL, // 0x40 all (include external) file API (glibc, OSP) always based on preload
174 FL_THREAD_API_ALWAYS_PROBING_PRELOAD = 0x0000000000080ULL, // 0x80 all (include external) thread API (glibc, OSP) always based on preload
175 FL_NETWORK_API_ALWAYS_PROBING_PRELOAD = 0x0000000000100ULL, // 0x100 all (include external) network API (glibc, OSP, libsoap, openssl) always based on preload
176 FL_OPENGL_API_ALWAYS_PROBING_PRELOAD = 0x0000000000200ULL, // 0x200 all (include external) openGL API always based on preload
178 FL_ALL_FEATURES_1 = 0x00000000003FFULL, /* all */
182 SWAP_RETPROBE = 0, //Common retprobe
183 SWAP_FBI_PROBE = 1, //Function body instrumentation probe
184 SWAP_LD_PROBE = 2, //Preloaded API probe
185 SWAP_WEBPROBE = 3, //Webprobe
188 #define IS_OPT_SET_IN(OPT, reg) (reg & (OPT))
189 #define IS_OPT_SET(OPT) IS_OPT_SET_IN((OPT), prof_session.conf.use_features0)
191 enum supported_device {
198 static const char *supported_devices_strings[] = {
205 #define array_size(x) (sizeof(x)/sizeof((x)[0]))
206 enum { supported_devices_count = array_size(supported_devices_strings) };
208 #define TARGER_MSG_MAX_LEN 4096
209 #define HOST_CTL_MSG_MAX_LEN (10 * 1024 * 1024)
211 struct _msg_target_t {
217 struct msg_target_t {
220 char data[TARGER_MSG_MAX_LEN];
223 enum { MSG_HEADER_LEN = offsetof(struct msg_target_t, data) };
226 #define MAX_FILENAME 128
228 #define MSG_DATA_HDR_LEN 20
238 #define MSG_CMD_HDR_LEN 8
255 uint64_t use_features0;
256 uint64_t use_features1;
257 uint32_t system_trace_period;
258 uint32_t data_message_period;
261 typedef uint32_t log_interval_t;
265 APP_TYPE_UNKNOWN = 0,
267 APP_TYPE_RUNNING = 2,
285 struct us_func_inst_plane_t {
287 //name | type | len | info
288 //------------------------------------------
289 //func_addr | uint64 | 8 |
290 //probe_type | char | 1 |
294 } __attribute__ ((packed));
296 struct us_lib_inst_t {
300 struct user_space_inst_t {
302 struct app_list_t *app_inst_list;
304 struct lib_list_t *lib_inst_list;
306 struct lib_list_t *ld_lib_inst_list;
310 struct replay_event_t {
312 struct input_event ev;
315 struct replay_event_seq_t {
319 struct replay_event_t *events;
322 struct prof_session_t {
324 struct user_space_inst_t user_space_inst;
325 struct replay_event_seq_t replay_event_seq;
326 unsigned running_status:1; // to stop properly (1 - it is running, 0 - no)
329 int parseHostMessage(struct msg_t *log, char *msg);
330 int host_message_handler(struct msg_t *msg);
332 char *msg_ID_str(enum HostMessageT ID);
335 #include <sys/stat.h>
340 struct thread_info_t {
345 struct other_process_info_t {
350 struct inst_process_info_t {
353 uint64_t virtual_memory;
354 uint64_t resident_memory;
355 uint64_t shared_memory;
357 uint64_t total_alloc_size;
358 uint32_t count_of_threads;
366 * Adding pointer memebers to struct %system_info_t REQUIRES updating code,
367 * calculating length of bytevector, suitable for serializing it. See
368 * msg_data_payload_length()
371 struct system_info_t {
373 float *cpu_frequency;
376 // total thread count to calculate msg size
377 uint32_t count_of_threads;
380 uint64_t system_memory_used;
381 uint64_t system_total_gem_memory;
384 uint32_t count_of_inst_processes;
385 uint32_t count_of_other_processes;
389 uint32_t fd_peration_count;
392 uint32_t total_used_drive;
394 uint32_t disk_bytes_read;
395 uint32_t disk_writes;
396 uint32_t disk_bytes_write;
399 uint32_t network_send_size;
400 uint32_t network_receive_size;
403 uint32_t wifi_status;
406 uint32_t brightness_status;
407 uint32_t camera_status;
408 uint32_t sound_status;
409 uint32_t audio_status;
410 uint32_t vibration_status;
411 uint32_t voltage_status;
412 uint32_t rssi_status;
413 uint32_t video_status;
414 uint32_t call_status;
415 uint32_t dnet_status;
419 uint32_t energy_per_device[supported_devices_count];
420 uint32_t app_energy_per_device[supported_devices_count];
423 struct recorded_event_t {
430 #ifndef da_static_assert
431 #define da_static_assert(cond) \
432 char __attribute__((unused)) __static_assert[(cond) ? 1 : -1];
435 #define pack_int64(to, n) do { \
436 da_static_assert(sizeof(n) == 8); \
437 *(uint64_t *)to = (n); \
438 to += sizeof(uint64_t); \
441 #define pack_int32(to, n) do { \
442 da_static_assert(sizeof(n) == 4); \
443 *(uint32_t *)to = (n); \
444 to += sizeof(uint32_t); \
447 #define pack_int8(to, n) do { \
448 da_static_assert(sizeof(n) == 1); \
449 *(uint8_t *)to = (n); \
450 to += sizeof(uint8_t); \
453 #define pack_time(to, n) \
455 pack_int32(to, n.tv_sec); \
456 pack_int32(to, n.tv_usec); \
459 #define pack_float(to, n) \
462 to += sizeof(float); \
465 #define pack_str(to, n) \
467 memcpy(to, n, strlen(n) + 1); \
468 to = (char *)to + strlen(n) + 1; \
471 #define pack_path_with_len(to, n) \
474 len = strnlen(n, PATH_MAX) + 1; \
475 pack_int32(to, len); \
476 memcpy(to, n, len); \
480 static inline void* pack_str_array(void *buffer, const char **strings,
484 for (index = 0; index != count; ++index)
485 pack_str(buffer, strings[index]);
489 struct msg_data_t *pack_system_info(struct system_info_t *sys_info);
490 int write_to_buf(struct msg_data_t *msg);
491 void free_msg_data(struct msg_data_t *msg);
492 void free_msg_payload(struct msg_t *msg);
493 void free_sys_info(struct system_info_t *sys_info);
494 int start_replay(void);
495 void stop_replay(void);
497 enum ErrorCode stop_all(void);
498 enum ErrorCode stop_all_no_lock(void);
499 int stop_all_in_process(void);
500 void stop_all_done(void);
502 void reset_msg(struct msg_t *msg);
503 void reset_replay_event_seq(struct replay_event_seq_t *res);
504 void reset_system_info(struct system_info_t *sys);
505 int check_running_status(const struct prof_session_t *prof_session);
507 void prepare_config_msg(struct msg_target_t *msg);
509 extern struct prof_session_t prof_session;
511 int send_msg_to_sock(int sock, struct msg_target_t *msg);
512 int recv_msg_from_sock(int sock, struct msg_target_t *msg, size_t data_len);
515 void print_replay_event(struct replay_event_t *ev, uint32_t num, char *tab);
516 void feature_code_str(uint64_t feature0, uint64_t feature1, char *to,
519 int sendACKToHost(enum HostMessageT resp, enum ErrorCode err_code,
520 char *payload, int payload_size);
522 int parse_int8(struct msg_buf_t *msg, uint8_t *val);
523 int parse_int32(struct msg_buf_t *msg, uint32_t *val);
524 int parse_int64(struct msg_buf_t *msg, uint64_t *val);
525 int parse_string(struct msg_buf_t *msg, char **str);
526 int parse_string_no_alloc(struct msg_buf_t *msg, char *str);
527 int parse_replay_event_seq(struct msg_buf_t *msg, struct replay_event_seq_t *res);
533 int md5sum_by_file(struct md5sum *md5sum, const char *filename);
534 char *md5sum_to_str(const struct md5sum *md5sum, char *to, size_t buff_len);
536 void init_prof_session(struct prof_session_t *prof_session);
537 #endif /* _DA_PROTOCOL_ */