--------------------- PatchSet 2383 Date: 2001/05/27 11:46:15 Author: serassio Branch: cygwin Tag: (none) Log: Added PSAPI.DLL support for memory usage informations Members: src/Makefile.in:1.3.26.4->1.3.26.5 src/tools.c:1.7.2.10->1.7.2.11 Index: squid/src/Makefile.in =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/Makefile.in,v retrieving revision 1.3.26.4 retrieving revision 1.3.26.5 diff -u -r1.3.26.4 -r1.3.26.5 --- squid/src/Makefile.in 26 Apr 2001 21:35:51 -0000 1.3.26.4 +++ squid/src/Makefile.in 27 May 2001 11:46:45 -0000 1.3.26.5 @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.in,v 1.3.26.4 2001/04/26 21:35:51 serassio Exp $ +# $Id: Makefile.in,v 1.3.26.5 2001/05/27 11:46:45 serassio Exp $ # # Uncomment and customize the following to suit your needs: # @@ -69,6 +69,7 @@ AC_CFLAGS = @CFLAGS@ LDFLAGS = @LDFLAGS@ XTRA_LIBS = @XTRA_LIBS@ +WIN32_LIBS = @WIN32_LIBS@ XTRA_OBJS = @XTRA_OBJS@ STORE_OBJS = @STORE_OBJS@ STORE_MODULES = @STORE_MODULES@ @@ -81,7 +82,7 @@ INCLUDE = -I. -I../include -I$(top_srcdir)/include CFLAGS = $(AC_CFLAGS) $(INCLUDE) $(DEFINES) SQUID_LIBS = -L../lib $(CRYPTLIB) $(REGEXLIB) @SQUID_PTHREAD_LIB@ \ - $(SNMPLIB) $(MALLOCLIB) $(SSLLIB) -lmiscutil $(XTRA_LIBS) + $(SNMPLIB) $(MALLOCLIB) $(SSLLIB) -lmiscutil $(XTRA_LIBS) $(WIN32_LIBS) CLIENT_LIBS = -L../lib -lmiscutil $(XTRA_LIBS) DNSSERVER_LIBS = -L../lib -lmiscutil $(XTRA_LIBS) PINGER_LIBS = -L../lib -lmiscutil $(XTRA_LIBS) Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.7.2.10 retrieving revision 1.7.2.11 diff -u -r1.7.2.10 -r1.7.2.11 --- squid/src/tools.c 6 May 2001 16:50:19 -0000 1.7.2.10 +++ squid/src/tools.c 27 May 2001 11:46:15 -0000 1.7.2.11 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.7.2.10 2001/05/06 16:50:19 serassio Exp $ + * $Id: tools.c,v 1.7.2.11 2001/05/27 11:46:15 serassio Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -34,6 +34,11 @@ */ #include "squid.h" +#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) +#include +#include +#include +#endif #define DEAD_MSG "\ The Squid Cache (version %s) died.\n\ @@ -176,10 +181,44 @@ /* Solaris 2.5 has getrusage() permission bug -- Arjan de Vet */ enter_suid(); #endif +#ifndef _SQUID_MSWIN_ getrusage(RUSAGE_SELF, r); +#endif #ifdef _SQUID_SOLARIS_ leave_suid(); #endif +#if HAVE_WIN32_PSAPI && (defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)) + if ((WIN32_OS_version == _WIN_OS_WINNT) || (WIN32_OS_version == _WIN_OS_WIN2K)) + { + /* On Windows NT/2000 call PSAPI.DLL for process Memory */ + /* informations -- Guido Serassio */ + HANDLE hProcess; + PROCESS_MEMORY_COUNTERS pmc; + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | + PROCESS_VM_READ, + FALSE, GetCurrentProcessId()); +#if defined (_SQUID_MSWIN_) + { + /* Microsoft Visual C++ doesn't have getrusage function, */ + /* so we get process CPU time information from PSAPI.DLL. */ + FILETIME ftCreate, ftExit, ftKernel, ftUser; + if (GetProcessTimes(hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser)) + { + LONGLONG tUser64 = *(LONGLONG *)&ftUser; + LONGLONG tKernel64 = *(LONGLONG *)&ftKernel; + r->ru_utime.tv_usec =(DWORD)(tUser64 / 10); + r->ru_stime.tv_usec =(DWORD)(tKernel64 / 10); + } + } +#endif + if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) + { + r->ru_maxrss=(DWORD)(pmc.WorkingSetSize /1024); + r->ru_majflt=pmc.PageFaultCount; + } + CloseHandle( hProcess ); + } +#endif #endif }