4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
8 * Jaewon Lim <jaewon81.lim@samsung.com>
9 * Woojin Jung <woojin2.jung@samsung.com>
10 * Juyoung Kim <j0.kim@samsung.com>
11 * Cherepanov Vitaliy <v.cherepanov@samsung.com>
12 * Nikita Kalyazin <n.kalyazin@samsung.com>
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
18 * http://www.apache.org/licenses/LICENSE-2.0
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
28 * - Samsung RnD Institute Russia
36 #include <stdint.h> // for uint64_t, int64_t
37 #include <pthread.h> // for pthread_mutex_t
39 #include "da_protocol.h"
46 #define PROTOCOL_VERSION "2.1"
48 #define RUN_APP_LOADER
50 #define MAX_TARGET_COUNT 8
51 #define DA_MSG_MAX 4096
52 #define RECV_BUF_MAX 4104 // = sizeof(msg_t)
55 #define MAX_FILENAME 128
60 ERR_LOCKFILE_CREATE_FAILED = -101,
61 ERR_ALREADY_RUNNING = -102,
62 ERR_INITIALIZE_SYSTEM_INFO_FAILED = -103,
63 ERR_HOST_SERVER_SOCKET_CREATE_FAILED = -104,
64 ERR_TARGET_SERVER_SOCKET_CREATE_FAILED = -105,
65 ERR_SIGNAL_MASK_SETTING_FAILED = -106,
66 ERR_WRONG_MESSAGE_FORMAT = -201,
67 ERR_WRONG_MESSAGE_TYPE = -202,
68 ERR_WRONG_MESSAGE_DATA = -203,
69 ERR_CANNOT_START_PROFILING = -204,
70 ERR_WRONG_PROTOCOL_VERSION = -205
73 enum TargetMessageType
87 #define IS_PROBE_MSG(type) (((type) & 0x0100) == 0x0100)
100 MSG_CAPTURE_SCREEN = 108,
113 DAS_TARGET_ARM_START = 1,
114 DAS_TARGET_X86_START = 2,
115 DAS_EMUL_ARM_START = 3,
116 DAS_EMUL_X86_START = 4,
117 DAS_TARGET_ARM_BATT_START = 5,
118 DAS_TARGET_X86_BATT_START = 6,
119 DAS_EMUL_ARM_BATT_START = 7,
120 DAS_EMUL_X86_BATT_START = 8,
128 #define likely(x) __builtin_expect((x), 1)
129 #define unlikely(x) __builtin_expect((x), 0)
132 #define EVENT_STOP 0x00000001
133 #define EVENT_PID 0x00000002
134 #define EVENT_ERROR 0x00000004
140 char data[DA_MSG_MAX];
147 pthread_mutex_t data_socket_mutex;
152 int64_t allocmem; // written only by recv thread
153 pid_t pid; // written only by recv thread
154 int socket; // written only by main thread
155 pthread_t recv_thread; // written only by main thread
156 int event_fd; // for thread communication (from recv thread to main thread)
157 int initial_log; // written only by main thread
169 } __file_descriptors;
173 int host_server_socket;
174 int target_server_socket;
178 unsigned int config_flag;
179 int app_launch_timerfd;
180 int connect_timeout_timerfd;
181 pthread_t sampling_thread;
182 pthread_t replay_thread;
183 pthread_t transfer_thread;
188 __da_target_info target[MAX_TARGET_COUNT];
189 __file_descriptors fd;
190 char appPath[128]; // application executable path
193 extern __da_manager manager;
195 uint64_t get_total_alloc_size(void);
196 void initialize_log(void);
197 int daemonLoop(void);
198 void unlink_portfile(void);
200 int makeRecvThread(int index);
201 int samplingStart(void);
202 int samplingStop(void);
207 // TODO maybe need move to other file
208 int prepare_profiling(void);
209 int start_profiling(void);
210 void stop_profiling(void);
211 int reconfigure(struct conf_t conf);
212 int sendACKCodeToHost(enum HostMessageType resp, int msgcode);
213 void terminate_all(void);