All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Implement memory tracker for Solarish systems
@ 2019-11-12 22:57 John Levon
  0 siblings, 0 replies; only message in thread
From: John Levon @ 2019-11-12 22:57 UTC (permalink / raw)
  To: smatch; +Cc: Patrick Mooney

From: Patrick Mooney <pmooney@pfmooney.com>

In addition, only try to track if requested by the mem option.

Portions-contributed-by: John Levon <john.levon@joyent.com>
---
 smatch_mem_tracker.c | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/smatch_mem_tracker.c b/smatch_mem_tracker.c
index b1671857..a92b8f35 100644
--- a/smatch_mem_tracker.c
+++ b/smatch_mem_tracker.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2018 Oracle.
+ * Copyright 2019 Joyent, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -16,21 +17,46 @@
  */
 
 #include "smatch.h"
+#include <fcntl.h>
 #include <unistd.h>
+#ifdef __sun
+#include <sys/procfs.h>
+#endif
 
 static int my_id;
 
 static unsigned long max_size;
 
+#ifdef __sun
+unsigned long get_mem_kb(void)
+{
+	static int my_fd = -2;
+	prpsinfo_t pbuf;
+
+	if (my_fd == -2) {
+		/* Do not repeatedly attempt this if it fails. */
+		my_fd = open("/proc/self/psinfo", O_RDONLY);
+	}
+	if (my_fd == -1) {
+		return (0);
+	}
+
+	if (pread(my_fd, &pbuf, sizeof (pbuf), 0) != sizeof (pbuf)) {
+		return (0);
+	}
+
+	return (pbuf.pr_rssize);
+}
+#else
 unsigned long get_mem_kb(void)
 {
 	FILE *file;
-	char buf[1024];
+	char buf[1024] = "0";
 	unsigned long size;
 
 	file = fopen("/proc/self/statm", "r");
 	if (!file)
-		return 0;
+	        return 0;
 	fread(buf, 1, sizeof(buf), file);
 	fclose(file);
 
@@ -38,14 +64,17 @@ unsigned long get_mem_kb(void)
 	size = size * sysconf(_SC_PAGESIZE) / 1024;
 	return size;
 }
+#endif
 
 static void match_end_func(struct symbol *sym)
 {
 	unsigned long size;
 
-	size = get_mem_kb();
-	if (size > max_size)
-		max_size = size;
+	if (option_mem) {
+		size = get_mem_kb();
+		if (size > max_size)
+			max_size = size;
+	}
 }
 
 unsigned long get_max_memory(void)
-- 
2.17.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-11-12 23:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-12 22:57 [PATCH] Implement memory tracker for Solarish systems John Levon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.