/*
- * 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>
pid_t pid;
int ref;
guint timer;
+ int cmd;
+ struct timespec ts;
} proc_info_t;
static GHashTable *__proc_tbl;
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;
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;
if (ctx->timer == 0)
_E("Failed to add timer");
+ ctx->cmd = cmd;
+ clock_gettime(CLOCK_MONOTONIC, &ctx->ts);
+
return ctx;
}
static void __reset_timer(proc_info_t *ctx)
{
+ struct timespec end;
+ unsigned int elapsed_time;
+
if (ctx->timer > 0)
g_source_remove(ctx->timer);
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;