[FIX] stop profiling when children terminate 43/26543/2
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 26 Aug 2014 08:16:26 +0000 (12:16 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 26 Aug 2014 08:24:53 +0000 (12:24 +0400)
Change-Id: Ie603aa3445fb20c2543f2bbea39eabce618c67d9
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
daemon/daemon.c
daemon/daemon.h
daemon/main.c
daemon/utils.c

index edbb8aa..03d6707 100644 (file)
 #define MAX_APP_LAUNCH_TIME            60
 #define MAX_CONNECT_TIMEOUT_TIME       5*60
 
+
+int get_comm_pid(void)
+{
+       return manager.comm_pid;
+}
+
+void set_comm_pid(int pid)
+{
+       manager.comm_pid = pid;
+}
+
+void reset_comm_pid(void)
+{
+       set_comm_pid(no_comm_pid);
+}
+
 uint64_t get_total_alloc_size_by_pid(pid_t pid)
 {
        int i;
@@ -310,6 +326,8 @@ void terminate_all()
                        LOGI("join recv thread %d. done\n", i);
                }
        }
+
+       reset_comm_pid();
 }
 
 // terminate all profiling by critical error
@@ -541,10 +559,16 @@ static int target_event_pid_handler(int index, uint64_t msg)
 
 static int target_event_stop_handler(int index, uint64_t msg)
 {
+       int cnt, comm_pid;
+
        LOGI("target close, socket(%d), pid(%d) : (remaining %d target)\n",
             manager.target[index].socket, manager.target[index].pid,
             manager.target_count - 1);
 
+       comm_pid = get_comm_pid();
+       if (manager.target[index].pid == comm_pid)
+               reset_comm_pid();
+
        if (index == 0)         // main application
                stop_replay();
 
@@ -552,7 +576,8 @@ static int target_event_stop_handler(int index, uint64_t msg)
 
        setEmptyTargetSlot(index);
        // all target client are closed
-       if (0 == __sync_sub_and_fetch(&manager.target_count, 1)) {
+       cnt = __sync_sub_and_fetch(&manager.target_count, 1);
+       if (0 == cnt && no_comm_pid == comm_pid) {
                LOGI("all targets are stopped\n");
                if (stop_all() != ERR_NO)
                        LOGE("Stop failed\n");
index 8f92e39..251722b 100644 (file)
@@ -164,6 +164,7 @@ typedef struct
 
 typedef struct
 {
+       int comm_pid;
        int host_server_socket;
        int target_server_socket;
        int target_count;
@@ -185,6 +186,14 @@ typedef struct
 
 extern __da_manager manager;
 
+
+enum { no_comm_pid = -1 };
+
+int get_comm_pid(void);
+void set_comm_pid(int pid);
+void reset_comm_pid(void);
+
+
 uint64_t get_total_alloc_size(void);
 void initialize_log(void);
 int daemonLoop(void);
index 42d6aec..8474895 100644 (file)
@@ -62,6 +62,7 @@
 // initialize global variable
 __da_manager manager =
 {
+       .comm_pid = no_comm_pid,
        .host_server_socket = -1,
        .target_server_socket = -1,
        .target_count = 0,
index 4151ffa..12212e3 100644 (file)
@@ -185,6 +185,7 @@ int exec_app_common(const char* exec_path)
                return -1;
 
        if (pid > 0) { /* parent */
+               set_comm_pid(pid);
                return 0;
        } else { /* child */
                execl(SHELL_CMD, SHELL_CMD, "-c", command, NULL);