Implement memory tracker for Solarish systems
PATCH 1/1 Implement memory tracker for Solarish systems
From: Patrick Mooney <[email protected]>
In addition, only try to track if requested by the mem option.
Portions-contributed-by John Levon <[email protected]>
--- smatch_mem_tracker.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-)
smatch_mem_tracker.c +34 -5
@@ -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 )
Signature · 1 line
2.17.1