summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Stelmach <l.stelmach@samsung.com>2016-12-14 17:30:54 +0100
committerŁukasz Stelmach <l.stelmach@samsung.com>2016-12-14 18:12:14 +0100
commit1b0c3b283ae9a30a8c323596296a17e0bbb61224 (patch)
treeddd69442f55c5dd269f2f017fd0a825c8a2ad5cc
parent65113e02bd5de3e83ffafcb37e74e5a47b0e5353 (diff)
downloadcrash-worker-1b0c3b283ae9a30a8c323596296a17e0bbb61224.tar.gz
crash-worker-1b0c3b283ae9a30a8c323596296a17e0bbb61224.tar.bz2
crash-worker-1b0c3b283ae9a30a8c323596296a17e0bbb61224.zip
crash-stack: print memory information
Print information from /proc/meminfo and /proc/PID/status Change-Id: I6c66e9ee6c8eca20a8925e9ecc23e09c0dabcb25
-rw-r--r--src/crash-stack/crash-stack.c75
1 files changed, 74 insertions, 1 deletions
diff --git a/src/crash-stack/crash-stack.c b/src/crash-stack/crash-stack.c
index 9da6d93..fbf39c0 100644
--- a/src/crash-stack/crash-stack.c
+++ b/src/crash-stack/crash-stack.c
@@ -1038,7 +1038,80 @@ static char *fgets_fd(char *str, int len, int fd)
*/
static void __crash_stack_print_meminfo(FILE* outputfile, pid_t pid)
{
- fprintf(outputfile, "\nMemory Information\n");
+ char infoname[BUF_SIZE];
+ char memsize[BUF_SIZE];
+ char linebuf[BUF_SIZE];
+ char file_path[PATH_MAX];
+ int fd;
+
+ printf("\nMemory information\n");
+
+ if ((fd = open("/proc/meminfo", O_RDONLY)) < 0) {
+ fprintf(errfile, "[crash-stack] cannot open /proc/meminfo\n");
+ } else {
+ while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
+ sscanf(linebuf, "%s %s %*s", infoname, memsize);
+ if (strcmp("MemTotal:", infoname) == 0) {
+ printf("%s %8s KB\n", infoname, memsize);
+ } else if (strcmp("MemFree:", infoname) == 0) {
+ printf("%s %8s KB\n", infoname, memsize);
+ } else if (strcmp("Buffers:", infoname) == 0) {
+ printf("%s %8s KB\n", infoname, memsize);
+ } else if (strcmp("Cached:", infoname) == 0) {
+ printf("%s %8s KB\n", infoname, memsize);
+ break;
+ }
+ }
+ close(fd);
+ }
+
+ snprintf(file_path, PATH_MAX, "/proc/%d/status", pid);
+ if ((fd = open(file_path, O_RDONLY)) < 0) {
+ fprintf(errfile, "[crash-stack] cannot open %s\n", file_path);
+ } else {
+ while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
+ sscanf(linebuf, "%s %s %*s", infoname, memsize);
+ if (strcmp("VmPeak:", infoname) == 0) {
+ printf("%s %8s KB\n", infoname,
+ memsize);
+ } else if (strcmp("VmSize:", infoname) == 0) {
+ printf("%s %8s KB\n", infoname,
+ memsize);
+ } else if (strcmp("VmLck:", infoname) == 0) {
+ printf("%s %8s KB\n", infoname,
+ memsize);
+ } else if (strcmp("VmPin:", infoname) == 0) {
+ printf("%s %8s KB\n", infoname,
+ memsize);
+ } else if (strcmp("VmHWM:", infoname) == 0) {
+ printf("%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmRSS:", infoname) == 0) {
+ printf("%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmData:", infoname) == 0) {
+ printf("%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmStk:", infoname) == 0) {
+ printf("%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmExe:", infoname) == 0) {
+ printf("%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmLib:", infoname) == 0) {
+ printf("%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmPTE:", infoname) == 0) {
+ printf("%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmSwap:", infoname) == 0) {
+ printf("%s %8s KB\n",
+ infoname, memsize);
+ break;
+ }
+ }
+ close(fd);
+ }
}
/**