Return-Path: Received: from movementarian.org ([178.79.150.28]:45672 "EHLO movementarian.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727069AbfKLXPo (ORCPT ); Tue, 12 Nov 2019 18:15:44 -0500 From: John Levon Subject: [PATCH] Implement memory tracker for Solarish systems Date: Tue, 12 Nov 2019 22:57:26 +0000 Message-Id: <1573599446-21673-1-git-send-email-john.levon@joyent.com> Sender: smatch-owner@vger.kernel.org List-ID: To: smatch@vger.kernel.org Cc: Patrick Mooney From: Patrick Mooney In addition, only try to track if requested by the mem option. Portions-contributed-by: John Levon --- 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 #include +#ifdef __sun +#include +#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