// start and terminate control functions
// ========================================================================================
-static int startProfiling(long launchflag)
+int startProfiling(long launchflag)
{
- char execPath[PATH_MAX];
+ const struct app_info_t *app_info = &prof_session.app_info;
// remove previous screen capture files
remove_indir(SCREENSHOT_DIR);
#endif
manager.config_flag = launchflag;
-#ifdef RUN_APP_LOADER
- strcpy(execPath, manager.appPath);
-#else
- get_executable(manager.appPath, execPath, PATH_MAX);
-#endif
- if(samplingStart() < 0)
+ if (samplingStart() < 0)
return -1;
- if(exec_app(execPath, get_app_type(manager.appPath)) == 0)
- {
+ switch (app_info->app_type) {
+ case APP_TYPE_TIZEN:
+ if (exec_app_tizen(app_info->app_id, app_info->exe_path)) {
+ LOGE("Cannot exec tizen app %s\n", app_info->app_id);
+ samplingStop();
+ return -1;
+ }
+ break;
+ case APP_TYPE_RUNNING:
+ // TODO: nothing, it's running
+ break;
+ case APP_TYPE_COMMON:
+ if (exec_app_common(app_info->exe_path)) {
+ LOGE("Cannot exec common app %s\n", app_info->exe_path);
+ samplingStop();
+ return -1;
+ }
+ break;
+ default:
+ LOGE("Unknown app type %d\n", app_info->app_type);
samplingStop();
return -1;
+ break;
}
- LOGI("Timer Started\n");
-
return 0;
}
}
// terminate all target and wait for threads
-static void terminate_all()
+void terminate_all()
{
int i;
terminate_all_target();
// return -11 if all target process closed
static int targetEventHandler(int epollfd, int index, uint64_t msg)
{
- msg_t log;
-
if(msg & EVENT_PID)
{
- if(index == 0) // assume index 0 is main application process
- {
- int base_address;
- char tempBuff[DA_MSG_MAX];
- char tempBuff2[DA_MSG_MAX];
- char tempPath[PATH_MAX];
-
- get_executable(manager.appPath, tempPath, PATH_MAX);
- if(realpath(tempPath, tempBuff) == NULL)
- {
- LOGW("Failed to get realpath of app\n");
- strcpy(tempBuff, tempPath);
- }
-
- sprintf(tempPath, "/proc/%d/maps", manager.target[index].pid);
- sprintf(tempBuff2, "cat %s | grep %s | cut -d\"-\" -f1 > %s",
- tempPath, tempBuff, DA_BASE_ADDRESS);
- LOGI("base address command is %s\n", tempBuff2);
-
- do {
- if(access(tempPath, F_OK) != 0)
- return -1;
- if(is_same_app_process(manager.appPath, manager.target[index].pid) == 0)
- return -1;
-
- system(tempBuff2);
- if(get_app_base_address(&base_address) == 1)
- break;
- sleep(0);
- } while(1);
-
- tempPath[0] = '\0';
- get_app_install_path(tempPath, PATH_MAX);
-
-#ifndef LOCALTEST
- get_device_info(tempBuff, DA_MSG_MAX);
-#endif
-
- log.type = MSG_DEVICE;
- if (strlen(tempPath) > 0)
- {
- get_executable(manager.appPath, tempBuff2, DA_MSG_MAX);
- log.length = sprintf(log.data, "%s`,%d`,%Lu`,%d`,%u`,%d`,%s/%s", tempBuff,
- manager.target[index].pid, manager.target[index].starttime,
- is_app_built_pie(), base_address, get_app_type(manager.appPath),
- tempPath, get_app_name(tempBuff2));
- }
- else
- {
- log.length = sprintf(log.data, "%s`,%d`,%Lu`,%d`,%u`,%d`,", tempBuff,
- manager.target[index].pid, manager.target[index].starttime,
- is_app_built_pie(), base_address, get_app_type(manager.appPath));
- }
-
- LOGI("%s\n", log.data);
- }
- else
- {
- log.type = MSG_PID;
- log.length = sprintf(log.data, "%d`,%Lu", manager.target[index].pid, manager.target[index].starttime);
- }
-
- sendDataToHost(&log);
manager.target[index].initial_log = 1;
}
terminate_target(index);
epoll_ctl(epollfd, EPOLL_CTL_DEL, manager.target[index].event_fd, NULL);
setEmptyTargetSlot(index);
- if (0 == __sync_sub_and_fetch(&manager.target_count, 1)) // all target client are closed
- {
- log.type = MSG_TERMINATE;
- log.length = 0;
- log.data[0] = '\0';
- sendDataToHost(&log);
+ if (0 == __sync_sub_and_fetch(&manager.target_count, 1)) // all target client are closed
return -11;
- }
}
return 0;
// execute applcation with executable binary path
// return 0 to fail to execute
// return 1 to succeed to execute
-#ifdef USE_LAUNCH_PAD
-int exec_app(const char* exec_path, int app_type)
+int exec_app_tizen(const char *app_id, const char *exec_path)
{
pid_t pid;
char command[PATH_MAX];
char appid[PATH_MAX];
- if (exec_path == NULL || strlen(exec_path) <= 0)
- {
+ if (exec_path == NULL || !strlen(exec_path)) {
LOGE("Executable path is not correct\n");
return 0;
}
- if (( pid = fork()) < 0) // fork error
- return 0;
- else if(pid > 0)
- return 1; // exit parent process with successness
-
- if(get_appid(exec_path, appid, PATH_MAX) < 0)
- {
- LOGE("failed to get appid\n");
- return 0;
- }
- else
- {
- LOGI("launch app path is %s, executable path is %s\n", LAUNCH_APP_PATH, exec_path);
- execl(LAUNCH_APP_PATH, LAUNCH_APP_NAME, appid, LAUNCH_APP_SDK, DA_PRELOAD_EXEC, NULL);
+ pid = fork();
+ if (pid == -1)
return 1;
- }
+ else if (pid > 0)
+ return 0; // exit parent process with success
+
+ LOGI("launch app path is %s, executable path is %s\n",
+ LAUNCH_APP_PATH, exec_path);
+ execl(LAUNCH_APP_PATH, LAUNCH_APP_NAME, app_id, LAUNCH_APP_SDK,
+ DA_PRELOAD_EXEC, NULL);
+
+ return 0;
}
-#else
-int exec_app(const char* exec_path, int app_type)
+
+int exec_app_common(const char* exec_path)
{
- pid_t pid;
- int isHwAcc = 0;
+ pid_t pid;
+ int hw_acc = 0;
char manifest[PATH_MAX];
char command[PATH_MAX];
#ifndef LOCALTEST
char appid[SMACK_LABEL_LEN];
#endif
- if (exec_path == NULL || strlen(exec_path) <= 0)
- {
+ if (exec_path == NULL || !strlen(exec_path)) {
LOGE("Executable path is not correct\n");
- return 0;
+ return 1;
}
- if (( pid = fork()) < 0) // fork error
- return 0;
-
- else if(pid > 0)
- return 1; // exit parent process with successness
+ pid = fork();
+ if (pid == -1)
+ return 1;
+ else if (pid > 0)
+ return 0; // exit parent process with success
- if(get_manifest_path(exec_path, manifest, PATH_MAX) == 0)
- {
+ if (get_manifest_path(exec_path, manifest, PATH_MAX) == 0) {
FILE* fp;
char buffer[BUFFER_MAX];
char* res;
// grep for manifest
- sprintf(command, "grep \"HwAcceleration=\\\"On\\\"\" %s", manifest);
+ sprintf(command, "grep \"HwAcceleration=\\\"On\\\"\" %s",
+ manifest);
fp = popen(command, "r");
- if(fp != NULL)
- {
+ if (fp != NULL) {
buffer[0] = '\0';
res = fgets(buffer, BUFFER_MAX, fp);
- if(res != NULL && strlen(buffer) != 0)
- {
- isHwAcc = 1;
+ if (res != NULL && strlen(buffer) != 0) {
+ hw_acc = 1;
}
pclose(fp);
}
}
+ // FIXME: I think the followin does not make sense
+/* #ifndef LOCALTEST */
+/* if (get_smack_label(exec_path, appid, SMACK_LABEL_LEN - 1) < 0) { */
+/* LOGE("failed to get smack label\n"); */
+/* return 1; */
+/* } else */
+/* #endif */
+/* { */
+/* #ifndef LOCALTEST */
+/* LOGI("smack lable is %s\n", appid); */
+/* if(smack_set_label_for_self(appid) < 0) { */
+/* LOGE("failed to set label for self\n"); */
+/* } */
+/* #endif */
+/* set_appuser_groups(); */
+/* if (setgid(SID_APP) < 0) { */
+/* LOGE("failed to setgid\n"); */
+/* } */
+/* if (setuid(SID_APP) < 0) { */
+/* LOGE("failed to setuid\n"); */
+/* } */
+
+/* pid = getpid(); */
+/* if (setpgid(pid, pid) < 0) { */
+/* LOGE("failed to setpgid\n"); */
+/* } */
+
+/* if (hw_acc != 0) { */
+/* sprintf(command, "HWACC=USE %s %s", DA_PRELOAD(app_type), exec_path); */
+/* } else { */
+/* sprintf(command, "%s %s", DA_PRELOAD(app_type), exec_path); */
+/* } */
+
+/* LOGI("launch app path is %s, executable path is %s\n", LAUNCH_APP_PATH, exec_path); */
+/* execl(SHELL_CMD, SHELL_CMD, "-c", command, NULL); */
+/* return 0; */
+/* } */
+ // TODO:
+ /* if (hw_acc) */
+ /* sprintf(command, "HWACC=USE %s %s", */
+ /* DA_PRELOAD(app_type), exec_path); */
+ /* else */
+ /* sprintf(command, "%s %s", */
+ /* DA_PRELOAD(app_type), exec_path); */
#ifndef LOCALTEST
- if(get_smack_label(exec_path, appid, SMACK_LABEL_LEN - 1) < 0)
- {
- LOGE("failed to get smack label\n");
- return 0;
- }
- else
-#endif
- {
-#ifndef LOCALTEST
- LOGI("smack lable is %s\n", appid);
- if(smack_set_label_for_self(appid) < 0)
- {
- LOGE("failed to set label for self\n");
- }
-#endif
- set_appuser_groups();
- if(setgid(SID_APP) < 0)
- {
- LOGE("failed to setgid\n");
- }
- if(setuid(SID_APP) < 0)
- {
- LOGE("failed to setuid\n");
- }
+ sprintf(command, "%s %s",
+ DA_PRELOAD_OSP, exec_path);
+#else /* LOCALTEST */
+ sprintf(command, "%s", exec_path);
+#endif /* LOCALTEST */
- pid = getpid();
- if(setpgid(pid, pid) < 0)
- {
- LOGE("failed to setpgid\n");
- }
-
- if(isHwAcc != 0)
- {
- sprintf(command, "HWACC=USE %s %s", DA_PRELOAD(app_type), exec_path);
- }
- else
- {
- sprintf(command, "%s %s", DA_PRELOAD(app_type), exec_path);
- }
+ LOGI("launching commmon app, command: %s\n", command);
+ execl(SHELL_CMD, SHELL_CMD, "-c", command, NULL);
- LOGI("launch app path is %s, executable path is %s\n", LAUNCH_APP_PATH, exec_path);
- execl(SHELL_CMD, SHELL_CMD, "-c", command, NULL);
- return 1;
- }
+ return 0;
}
-#endif
// find process id from executable binary path
pid_t find_pid_from_path(const char* path)
}
}
-int get_app_type(char* appPath)
-{
- int fd;
- char buf[BUFFER_MAX];
-
- sprintf(buf, "%s.exe", appPath);
- fd = open(buf, O_RDONLY);
- if(fd != -1)
- {
- close(fd);
- return APP_TYPE_OSP;
- }
- else
- {
- return APP_TYPE_TIZEN;
- }
-}
-
int get_executable(char* appPath, char* buf, int buflen)
{
int fd;