diff options
-rw-r--r-- | Makefile.nmake | 6 | ||||
-rw-r--r-- | epan/CMakeLists.txt | 1 | ||||
-rw-r--r-- | epan/Makefile.common | 2 | ||||
-rw-r--r-- | epan/Makefile.nmake | 2 | ||||
-rw-r--r-- | epan/app_mem_usage.c | 130 | ||||
-rw-r--r-- | epan/app_mem_usage.h | 29 | ||||
-rw-r--r-- | ui/gtk/memory_dlg.c | 110 |
7 files changed, 171 insertions, 109 deletions
diff --git a/Makefile.nmake b/Makefile.nmake index 89787e0010..f6dab8a470 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -96,7 +96,7 @@ wireshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ !ENDIF tshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ - wsock32.lib user32.lib \ + wsock32.lib user32.lib psapi.lib \ $(GLIB_LIBS) \ $(GTHREAD_LIBS) \ wsutil\libwsutil.lib \ @@ -116,7 +116,7 @@ tshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ !ENDIF rawshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ - wsock32.lib user32.lib \ + wsock32.lib user32.lib psapi.lib \ $(GLIB_LIBS) \ wsutil\libwsutil.lib \ $(GNUTLS_LIBS) \ @@ -167,7 +167,7 @@ dumpcap_LIBS= \ $(GTHREAD_LIBS) dftest_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \ - wsock32.lib user32.lib \ + wsock32.lib user32.lib psapi.lib \ $(GLIB_LIBS) \ wsutil\libwsutil.lib \ $(GNUTLS_LIBS) \ diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index 81f1e39abc..e5d662c070 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -1429,6 +1429,7 @@ set(LIBWIRESHARK_FILES address_to_str.c adler32.c afn.c + app_mem_usage.c asn1.c atalk-utils.c base64.c diff --git a/epan/Makefile.common b/epan/Makefile.common index 7ca9b04dd6..f6bf2ac79d 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -29,6 +29,7 @@ LIBWIRESHARK_SRC = \ address_to_str.c \ adler32.c \ afn.c \ + app_mem_usage.c \ asn1.c \ atalk-utils.c \ base64.c \ @@ -150,6 +151,7 @@ LIBWIRESHARK_INCLUDES = \ adler32.h \ afn.h \ aftypes.h \ + app_mem_usage.h \ arcnet_pids.h \ arptypes.h \ ax25_pids.h \ diff --git a/epan/Makefile.nmake b/epan/Makefile.nmake index aa989e2176..fb28ca44d6 100644 --- a/epan/Makefile.nmake +++ b/epan/Makefile.nmake @@ -113,7 +113,7 @@ libwireshark.exp: libwireshark.dll libwireshark.dll: ..\config.h $(LIBWIRESHARK_OBJECTS) crypt ftypes dfilter wmem $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \ crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib wmem/wmem.lib dissectors\dissectors.lib $(WSLUA_LIB) $(WSPYTHON_LIB) ..\image\libwireshark.res @echo Linking libwireshark.dll - $(link) $(dlllflags) $(conlibsdll) shell32.lib \ + $(link) $(dlllflags) $(conlibsdll) shell32.lib psapi.lib \ $(LOCAL_LDFLAGS) $(DLL_LDFLAGS) \ /OUT:libwireshark.dll \ /IMPLIB:libwireshark.lib $(LIBWIRESHARK_OBJECTS) \ diff --git a/epan/app_mem_usage.c b/epan/app_mem_usage.c new file mode 100644 index 0000000000..97eee7d706 --- /dev/null +++ b/epan/app_mem_usage.c @@ -0,0 +1,130 @@ +/* + * app_mem_usage.c + * + * $Id: get_app_mem_usage.c 50885 2013-07-25 04:40:37Z etxrab $ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* code copied from ekg2, GPL-2 */ +#include "config.h" + +#include <glib.h> + +#include "app_mem_usage.h" + +#ifdef HAVE_SYS_UTSNAME_H +#include <sys/utsname.h> +#endif + +#ifdef _WIN32 +#include <windows.h> +#include <psapi.h> +#endif /* _WIN32 */ + +gsize +get_total_mem_used_by_app(void) +{ +#if defined(_WIN32) + HANDLE pHandle; + PROCESS_MEMORY_COUNTERS pmc; + SIZE_T workingSize = 0; + + pHandle = GetCurrentProcess(); + + if (GetProcessMemoryInfo(pHandle, &pmc, sizeof(pmc))){ + workingSize = pmc.WorkingSetSize; + + workingSize = workingSize / 1024; + } + + CloseHandle(pHandle); + + if(workingSize == 0){ + return -1; + }else{ + return (int)workingSize; + } +#else + char *temp, *p = NULL; + FILE *file = NULL; + size_t rd = 0; + int rozmiar = 0, unmres; + struct utsname sys; + + unmres = uname(&sys); + + temp = g_strdup_printf("/proc/%d/status", getpid()); + + if ( (unmres != -1 && !strcmp(sys.sysname, "FreeBSD")) || (file = fopen(temp,"rb")) ) { + g_free(temp); + { +#ifdef __linux__ + char buf[1024]; + + rd = fread(buf, 1, 1024, file); + fclose(file); + if (rd == 0) + { + return -1; + } + p = strstr(buf, "VmSize"); + if (p) { + sscanf(p, "VmSize: %d kB", &rozmiar); + } else { + return -1; + } +#elif __sun + pstatus_t proc_stat; + rd = fread(&proc_stat, sizeof(proc_stat), 1, file); + fclose(file); + if (rd == 0) + { + return -1; + } + rozmiar = proc_stat.pr_brksize + proc_stat.pr_stksize; +#elif __FreeBSD__ /* link with -lkvm */ + char errbuf[_POSIX2_LINE_MAX]; + int nentries = -1; + struct kinfo_proc *kp; + static kvm_t *kd; + + if (!(kd = kvm_openfiles(NULL /* "/dev/null" */, "/dev/null", NULL, /* O_RDONLY */0, errbuf))) { + return -1; + } + kp = kvm_getprocs(kd, KERN_PROC_PID, getpid(), &nentries); + if (!kp || nentries != 1) { + return -1; + } +#ifdef HAVE_STRUCT_KINFO_PROC_KI_SIZE + rozmiar = (u_long) kp->ki_size/1024; /* freebsd5 */ +#else + rozmiar = kp->kp_eproc.e_vm.vm_map.size/1024; /* freebsd4 */ +#endif /* HAVE_STRUCT_KINFO_PROC_KI_SIZE */ +#else + /* no /proc mounted */ + return -1; +#endif + } + } else { + return -1; + } + return rozmiar; +#endif /* (_WIN32) */ +}
\ No newline at end of file diff --git a/epan/app_mem_usage.h b/epan/app_mem_usage.h new file mode 100644 index 0000000000..2092a2cc1d --- /dev/null +++ b/epan/app_mem_usage.h @@ -0,0 +1,29 @@ +/* + * app_mem_usage.h + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef __APP_MEM_USAGE_H__ +#define __APP_MEM_USAGE_H__ + +gsize get_total_mem_used_by_app(void); + +#endif /* APP_MEM_USAGE_H */
\ No newline at end of file diff --git a/ui/gtk/memory_dlg.c b/ui/gtk/memory_dlg.c index acfa69565c..3aca56e691 100644 --- a/ui/gtk/memory_dlg.c +++ b/ui/gtk/memory_dlg.c @@ -1,4 +1,6 @@ -/* io_stat.c +/* memory_dlg.c + * + * Based on * io_stat 2002 Ronnie Sahlberg * * $Id$ @@ -28,15 +30,6 @@ #include <math.h> #include <gtk/gtk.h> -#ifdef HAVE_SYS_UTSNAME_H -#include <sys/utsname.h> -#endif - -#ifdef _WIN32 -#include <windows.h> -#include <psapi.h> -#endif /* _WIN32 */ - #include "ui/gtk/dlg_utils.h" #include "ui/simple_dialog.h" #include "ui/gtk/gui_utils.h" @@ -44,6 +37,7 @@ #include "ui/gtk/gui_utils.h" #include "wsutil/str_util.h" +#include "epan/app_mem_usage.h" enum { MEMORY_TOTAL = 0, @@ -649,100 +643,6 @@ init_io_stat_window(io_stat_t *io) window_present(io->window); } -/* code copied from ekg2, GPL-2 */ -static gsize -get_total(void) -{ -#if defined(_WIN32) - HANDLE pHandle; - PROCESS_MEMORY_COUNTERS pmc; - SIZE_T workingSize = 0; - - pHandle = GetCurrentProcess(); - - if (GetProcessMemoryInfo(pHandle, &pmc, sizeof(pmc))){ - workingSize = pmc.WorkingSetSize; - - workingSize = workingSize / 1024; - } - - CloseHandle(pHandle); - - if (workingSize == 0){ - return -1; - } else { - return (int)workingSize; - } -#else - char *temp; - FILE *file = NULL; - int rozmiar = 0, unmres; - struct utsname sys; - - unmres = uname(&sys); - - temp = g_strdup_printf("/proc/%d/status", getpid()); - - if ( (unmres != -1 && !strcmp(sys.sysname, "FreeBSD")) || (file = fopen(temp,"rb")) ) { - g_free(temp); - { -#ifdef __linux__ - size_t rd; - char buf[1024]; - char *p; - - rd = fread(buf, 1, 1024, file); - fclose(file); - if (rd == 0) - { - return -1; - } - p = strstr(buf, "VmSize"); - if (p) { - sscanf(p, "VmSize: %d kB", &rozmiar); - } else { - return -1; - } -#elif __sun - size_t rd; - pstatus_t proc_stat; - - rd = fread(&proc_stat, sizeof(proc_stat), 1, file); - fclose(file); - if (rd == 0) - { - return -1; - } - rozmiar = proc_stat.pr_brksize + proc_stat.pr_stksize; -#elif __FreeBSD__ /* link with -lkvm */ - char errbuf[_POSIX2_LINE_MAX]; - int nentries = -1; - struct kinfo_proc *kp; - static kvm_t *kd; - - if (!(kd = kvm_openfiles(NULL /* "/dev/null" */, "/dev/null", NULL, /* O_RDONLY */0, errbuf))) { - return -1; - } - kp = kvm_getprocs(kd, KERN_PROC_PID, getpid(), &nentries); - if (!kp || nentries != 1) { - return -1; - } -#ifdef HAVE_STRUCT_KINFO_PROC_KI_SIZE - rozmiar = (u_long) kp->ki_size/1024; /* freebsd5 */ -#else - rozmiar = kp->kp_eproc.e_vm.vm_map.size/1024; /* freebsd4 */ -#endif /* HAVE_STRUCT_KINFO_PROC_KI_SIZE */ -#else - /* no /proc mounted */ - return -1; -#endif - } - } else { - return -1; - } - return rozmiar; -#endif /* (_WIN32) */ -} static gboolean call_it(gpointer user_data) @@ -766,7 +666,7 @@ gsize se_memory_usage(void); } /* Point to the appropriate io_item_t struct */ - io->graphs[MEMORY_TOTAL].items[idx]->bytes = get_total() * 1000; + io->graphs[MEMORY_TOTAL].items[idx]->bytes = get_total_mem_used_by_app() * 1000; tmp = format_size(io->graphs[MEMORY_TOTAL].items[idx]->bytes, format_size_unit_bytes); g_snprintf(buf, sizeof(buf), "Total [%s]", tmp); gtk_button_set_label(GTK_BUTTON(io->graphs[MEMORY_TOTAL].display_button), buf); |