Print elapased time for debugging
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 5 Jan 2021 04:40:42 +0000 (13:40 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 5 Jan 2021 22:53:35 +0000 (07:53 +0900)
Change-Id: I0e6084fa753385500fd1b48d26e821b0999aec58
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_anr_monitor.c
src/lib/amd_anr_monitor.h
src/lib/amd_launch.c

index a28a808358e2d4752e008365422c789a00af0733..c49943c0d9926b94a58a8d4821f5a6b2e454325d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2018 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 #define _GNU_SOURCE
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
+#include <sys/types.h>
+#include <time.h>
 #include <unistd.h>
 #include <glib.h>
 #include <aul.h>
@@ -48,6 +49,8 @@ typedef struct proc_info_s {
        pid_t pid;
        int ref;
        guint timer;
+       int cmd;
+       struct timespec ts;
 } proc_info_t;
 
 static GHashTable *__proc_tbl;
@@ -121,7 +124,7 @@ static gboolean __timeout_handler(gpointer data)
                return G_SOURCE_REMOVE;
        }
 
-       _W("Application(%d) Not Responding", pid);
+       _W("Application(%d) Not Responding. cmd(%d)", pid, ctx->cmd);
        if (__can_ignore_anr_policy(app_status)) {
                _W("Ignore ANR policy. pid(%d)", pid);
                return G_SOURCE_REMOVE;
@@ -138,7 +141,7 @@ static gboolean __timeout_handler(gpointer data)
        return G_SOURCE_REMOVE;
 }
 
-static proc_info_t *__create_proc_info(pid_t pid)
+static proc_info_t *__create_proc_info(pid_t pid, int cmd)
 {
        proc_info_t *ctx;
 
@@ -156,6 +159,9 @@ static proc_info_t *__create_proc_info(pid_t pid)
        if (ctx->timer == 0)
                _E("Failed to add timer");
 
+       ctx->cmd = cmd;
+       clock_gettime(CLOCK_MONOTONIC, &ctx->ts);
+
        return ctx;
 }
 
@@ -200,6 +206,9 @@ static void __remove_proc_info(pid_t pid)
 
 static void __reset_timer(proc_info_t *ctx)
 {
+       struct timespec end;
+       unsigned int elapsed_time;
+
        if (ctx->timer > 0)
                g_source_remove(ctx->timer);
 
@@ -208,22 +217,28 @@ static void __reset_timer(proc_info_t *ctx)
        if (ctx->timer == 0)
                _E("Failed to add timer. pid(%d)", ctx->pid);
 
-       _W("Reset timer. pid(%d)", ctx->pid);
+       clock_gettime(CLOCK_MONOTONIC, &end);
+       elapsed_time = (end.tv_sec - ctx->ts.tv_sec) * 1e3 +
+               (end.tv_nsec - ctx->ts.tv_nsec) / 1e6;
+       _W("Reset timer. pid(%d), elapsed_time(%u), previous_cmd(%d)",
+                       ctx->pid, elapsed_time, ctx->cmd);
+       clock_gettime(CLOCK_MONOTONIC, &ctx->ts);
 }
 
-int _anr_monitor_add_timer(pid_t pid)
+int _anr_monitor_add_timer(pid_t pid, int cmd)
 {
        proc_info_t *ctx;
 
-       _W("Add timer. pid(%d)", pid);
+       _W("Add timer. pid(%d), cmd(%d)", pid, cmd);
        ctx = __find_proc_info(pid);
        if (ctx) {
                __reset_timer(ctx);
+               ctx->cmd = cmd;
                ctx->ref++;
                return 0;
        }
 
-       ctx = __create_proc_info(pid);
+       ctx = __create_proc_info(pid, cmd);
        if (!ctx) {
                _E("Failed to create process(%d) info", pid);
                return -1;
index 971f226089c104f66c9a426e916f3809c34ba888..42d5d550dc7daa1fb323a53cb10d39f93ec14de9 100644 (file)
@@ -24,7 +24,7 @@
 extern "C" {
 #endif
 
-int _anr_monitor_add_timer(pid_t pid);
+int _anr_monitor_add_timer(pid_t pid, int cmd);
 
 int _anr_monitor_remove_timer(pid_t pid);
 
index 676e44491cfa06371353935a5f7613f95f9207c0..9f315619a7991c50b07ad25970add2d93d7e7f4f 100644 (file)
@@ -907,7 +907,7 @@ static void __set_reply_handler(int fd, int pid, request_h req, int cmd)
        g_source_set_priority(src, G_PRIORITY_DEFAULT);
        g_source_attach(src, NULL);
 
-       _anr_monitor_add_timer(pid);
+       _anr_monitor_add_timer(pid, cmd);
 
        _D("listen fd : %d, send fd : %d", fd, r_info->clifd);
 }