Created
April 30, 2015 19:08
-
-
Save phillipberndt/25dc8154e390a3906645 to your computer and use it in GitHub Desktop.
Android bionic patch to log /etc/hosts lookup times, see https://github.com/sufficientlysecure/ad-away/issues/491
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c | |
index 2612d6a..277afb0 100644 | |
--- a/libc/dns/net/getaddrinfo.c | |
+++ b/libc/dns/net/getaddrinfo.c | |
@@ -80,6 +80,7 @@ | |
#include <fcntl.h> | |
#include <sys/cdefs.h> | |
#include <sys/types.h> | |
+#include <time.h> | |
#include <sys/stat.h> | |
#include <sys/param.h> | |
#include <sys/socket.h> | |
@@ -103,6 +104,7 @@ | |
#include <string.h> | |
#include <strings.h> | |
#include <unistd.h> | |
+#include <private/libc_logging.h> | |
#include <syslog.h> | |
#include <stdarg.h> | |
@@ -2042,15 +2044,18 @@ _gethtent(FILE **hostf, const char *name, const struct addrinfo *pai) | |
const char *addr; | |
char hostbuf[8*1024]; | |
+ clock_t start = clock(); | |
+ void *retval = NULL; | |
+ | |
// fprintf(stderr, "_gethtent() name = '%s'\n", name); | |
assert(name != NULL); | |
assert(pai != NULL); | |
if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "r" ))) | |
- return (NULL); | |
+ goto ret; | |
again: | |
if (!(p = fgets(hostbuf, sizeof hostbuf, *hostf))) | |
- return (NULL); | |
+ goto ret; | |
if (*p == '#') | |
goto again; | |
if (!(cp = strpbrk(p, "#\n"))) | |
@@ -2095,7 +2100,16 @@ found: | |
} | |
} | |
} | |
- return res0; | |
+ retval = res0; | |
+ clock_t endt; | |
+ret: | |
+ endt = clock(); | |
+ unsigned int mstime = (endt - start) * 1000 / CLOCKS_PER_SEC; | |
+ | |
+ __libc_format_log(ANDROID_LOG_WARN, "libc", "Lookup of `%s' took %u ms\n", name, mstime); | |
+ | |
+ | |
+ return retval; | |
} | |
/*ARGSUSED*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment