[asterisk-commits] astfd: Adds a timestamp for each entry. (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Sep 21 08:43:46 CDT 2015


Joshua Colp has submitted this change and it was merged.

Change subject: astfd: Adds a timestamp for each entry.
......................................................................


astfd: Adds a timestamp for each entry.

Now with menuselect "DEBUG_FD_LEAKS" and CLI "core show fd", a timestamp is
shown with each file descriptor. This helps to debug leaked UDP/TCP ports on
long-lived servers, for example.

ASTERISK-25405 #close

Change-Id: I968339e5155a512eba1032a5263f1ec8b5e1f80b
---
M main/astfd.c
1 file changed, 11 insertions(+), 2 deletions(-)

Approvals:
  Anonymous Coward #1000019: Verified
  Matt Jordan: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved



diff --git a/main/astfd.c b/main/astfd.c
index 7467376..d1879f0 100644
--- a/main/astfd.c
+++ b/main/astfd.c
@@ -46,6 +46,8 @@
 #include "asterisk/lock.h"
 #include "asterisk/strings.h"
 #include "asterisk/unaligned.h"
+#include "asterisk/localtime.h"
+#include "asterisk/time.h"
 
 static struct fdleaks {
 	const char *callname;
@@ -54,6 +56,7 @@
 	char file[40];
 	char function[25];
 	char callargs[60];
+	struct timeval now;
 } fdleaks[1024] = { { "", }, };
 
 /* COPY does ast_copy_string(dst, src, sizeof(dst)), except:
@@ -79,6 +82,7 @@
 #define STORE_COMMON(offset, name, ...)     \
 	do { \
 		struct fdleaks *tmp = &fdleaks[offset]; \
+		tmp->now = ast_tvnow(); \
 		COPY(tmp->file, file);      \
 		tmp->line = line;           \
 		COPY(tmp->function, func);  \
@@ -271,7 +275,7 @@
 	case CLI_GENERATE:
 		return NULL;
 	}
-	getrlimit(RLIMIT_FSIZE, &rl);
+	getrlimit(RLIMIT_NOFILE, &rl);
 	if (rl.rlim_cur == RLIM_INFINITY || rl.rlim_max == RLIM_INFINITY) {
 		ast_copy_string(line, "unlimited", sizeof(line));
 	} else {
@@ -280,8 +284,13 @@
 	ast_cli(a->fd, "Current maxfiles: %s\n", line);
 	for (i = 0; i < ARRAY_LEN(fdleaks); i++) {
 		if (fdleaks[i].isopen) {
+			struct ast_tm tm = {0};
+			char datestring[256];
+
+			ast_localtime(&fdleaks[i].now, &tm, NULL);
+			ast_strftime(datestring, sizeof(datestring), "%F %T", &tm);
 			snprintf(line, sizeof(line), "%d", fdleaks[i].line);
-			ast_cli(a->fd, "%5d %15s:%-7.7s (%-25s): %s(%s)\n", i, fdleaks[i].file, line, fdleaks[i].function, fdleaks[i].callname, fdleaks[i].callargs);
+			ast_cli(a->fd, "%5d [%s] %22s:%-7.7s (%-25s): %s(%s)\n", i, datestring, fdleaks[i].file, line, fdleaks[i].function, fdleaks[i].callname, fdleaks[i].callargs);
 		}
 	}
 	return CLI_SUCCESS;

-- 
To view, visit https://gerrit.asterisk.org/1287
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I968339e5155a512eba1032a5263f1ec8b5e1f80b
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Alexander Traud <pabstraud at compuserve.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list