diff options
Diffstat (limited to 'indra/llcommon')
| -rw-r--r-- | indra/llcommon/llerror.h | 103 | ||||
| -rw-r--r-- | indra/llcommon/llprocessor.cpp | 85 | ||||
| -rw-r--r-- | indra/llcommon/llsdutil.cpp | 26 | ||||
| -rw-r--r-- | indra/llcommon/llsys.cpp | 133 | 
4 files changed, 188 insertions, 159 deletions
| diff --git a/indra/llcommon/llerror.h b/indra/llcommon/llerror.h index 6f6b349cf5..a70b5cef3a 100644 --- a/indra/llcommon/llerror.h +++ b/indra/llcommon/llerror.h @@ -1,4 +1,4 @@ -/**  +/**   * @file llerror.h   * @date   December 2006   * @brief error message system @@ -6,21 +6,21 @@   * $LicenseInfo:firstyear=2006&license=viewerlgpl$   * Second Life Viewer Source Code   * Copyright (C) 2010, Linden Research, Inc. - *  + *   * This library is free software; you can redistribute it and/or   * modify it under the terms of the GNU Lesser General Public   * License as published by the Free Software Foundation;   * version 2.1 of the License only. - *  + *   * This library 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   * Lesser General Public License for more details. - *  + *   * You should have received a copy of the GNU Lesser General Public   * License along with this library; if not, write to the Free Software   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA - *  + *   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ @@ -95,6 +95,11 @@ const int LL_ERR_NOERR = 0;  #define LL_STATIC_ASSERT(func, msg) static_assert(func, msg)  #define LL_BAD_TEMPLATE_INSTANTIATION(type, msg) static_assert(false, msg)  #else +#if LL_LINUX +// We need access to raise and SIGSEGV +#include <signal.h> +#endif +  #define LL_STATIC_ASSERT(func, msg) BOOST_STATIC_ASSERT(func)  #define LL_BAD_TEMPLATE_INSTANTIATION(type, msg) BOOST_STATIC_ASSERT(sizeof(type) != 0 && false);  #endif @@ -103,12 +108,12 @@ const int LL_ERR_NOERR = 0;  /** Error Logging Facility  	Information for most users: -	 +  	Code can log messages with constructions like this: -	 +  		LL_INFOS("StringTag") << "request to fizzbip agent " << agent_id  			<< " denied due to timeout" << LL_ENDL; -		 +  	Messages can be logged to one of four increasing levels of concern,  	using one of four "streams": @@ -116,45 +121,45 @@ const int LL_ERR_NOERR = 0;  		LL_INFOS("StringTag")	- informational messages that are normal shown  		LL_WARNS("StringTag")	- warning messages that signal a problem  		LL_ERRS("StringTag")	- error messages that are major, unrecoverable failures -		 +  	The later (LL_ERRS("StringTag")) automatically crashes the process after the message  	is logged. -	 +  	Note that these "streams" are actually #define magic.  Rules for use:  		* they cannot be used as normal streams, only to start a message  		* messages written to them MUST be terminated with LL_ENDL  		* between the opening and closing, the << operator is indeed  		  writing onto a std::ostream, so all conversions and stream  		  formating are available -	 +  	These messages are automatically logged with function name, and (if enabled)  	file and line of the message.  (Note: Existing messages that already include  	the function name don't get name printed twice.) -	 +  	If you have a class, adding LOG_CLASS line to the declaration will cause  	all messages emitted from member functions (normal and static) to be tagged  	with the proper class name as well as the function name: -	 +  		class LLFoo  		{  			LOG_CLASS(LLFoo);  		public:  			...  		}; -	 +  		void LLFoo::doSomething(int i)  		{  			if (i > 100)  			{ -				LL_WARNS("FooBarTag") << "called with a big value for i: " << i << LL_ENDL;  +				LL_WARNS("FooBarTag") << "called with a big value for i: " << i << LL_ENDL;  			}  			...  		} -	 +  	will result in messages like: -	 +  		WARN #FooBarTag# llcommon/llfoo(100) LLFoo::doSomething : called with a big value for i: 283 -	 +      the syntax is:          <timestamp> SPACE <level> SPACE <tags> SPACE <location> SPACE <function> SPACE COLON SPACE <message> @@ -169,7 +174,7 @@ const int LL_ERR_NOERR = 0;      A copy of that file named logcontrol-dev.xml can be made in the users personal settings      directory; that will override the installed default file.  See the logcontrol.xml      file or http://wiki.secondlife.com/wiki/Logging_System_Overview for configuration details. -	 +  	Lastly, logging is now very efficient in both compiled code and execution  	when skipped.  There is no need to wrap messages, even debugging ones, in  	#ifdef _DEBUG constructs.  LL_DEBUGS("StringTag") messages are compiled into all builds, @@ -182,12 +187,12 @@ namespace LLError  	{  		LEVEL_ALL = 0,  			// used to indicate that all messages should be logged -			 +  		LEVEL_DEBUG = 0,  		LEVEL_INFO = 1,  		LEVEL_WARN = 2,  		LEVEL_ERROR = 3,	// used to be called FATAL -		 +  		LEVEL_NONE = 4  			// not really a level  			// used to indicate that no messages should be logged @@ -223,13 +228,13 @@ namespace LLError  		// Represents a specific place in the code where a message is logged  		// This is public because it is used by the macros below.  It is not  		// intended for public use. -		CallSite(ELevel level,  -				const char* file,  +		CallSite(ELevel level, +				const char* file,  				int line, -				const std::type_info& class_info,  -				const char* function,  -				bool print_once,  -				const char** tags,  +				const std::type_info& class_info, +				const char* function, +				bool print_once, +				const char** tags,  				size_t tag_count);  		~CallSite(); @@ -238,16 +243,16 @@ namespace LLError  		bool shouldLog();  #else // LL_LIBRARY_INCLUDE  		bool shouldLog() -		{  -			return mCached  -					? mShouldLog  -					: Log::shouldLog(*this);  +		{ +			return mCached +					? mShouldLog +					: Log::shouldLog(*this);  		}  			// this member function needs to be in-line for efficiency  #endif // LL_LIBRARY_INCLUDE -		 +  		void invalidate(); -		 +  		// these describe the call site and never change  		const ELevel			mLevel;  		const char* const		mFile; @@ -263,22 +268,22 @@ namespace LLError  								mTagString;  		bool					mCached,  								mShouldLog; -		 +  		friend class Log;  	}; -	 -	 + +  	class End { };  	inline std::ostream& operator<<(std::ostream& s, const End&)  		{ return s; }  		// used to indicate the end of a message -		 +  	class LL_COMMON_API NoClassInfo { };  		// used to indicate no class info known for logging      //LLCallStacks keeps track of call stacks and output the call stacks to log file      // -    //Note: to be simple, efficient and necessary to keep track of correct call stacks,  +    //Note: to be simple, efficient and necessary to keep track of correct call stacks,      //LLCallStacks is designed not to be thread-safe.      //so try not to use it in multiple parallel threads at same time.      //Used in a single thread at a time is fine. @@ -287,8 +292,8 @@ namespace LLError      private:          typedef std::vector<std::string> StringVector;          static StringVector sBuffer ; -               -    public:    + +    public:          static void push(const char* function, const int line) ;          static void insert(std::ostream& out, const char* function, const int line) ;          static void print() ; @@ -326,7 +331,7 @@ namespace LLError      };  } -//this is cheaper than llcallstacks if no need to output other variables to call stacks.  +//this is cheaper than llcallstacks if no need to output other variables to call stacks.  #define LL_PUSH_CALLSTACKS() LLError::LLCallStacks::push(__FUNCTION__, __LINE__)  #define llcallstacks                                                    \ @@ -341,7 +346,7 @@ namespace LLError  	}  #define LL_CLEAR_CALLSTACKS() LLError::LLCallStacks::clear() -#define LL_PRINT_CALLSTACKS() LLError::LLCallStacks::print()  +#define LL_PRINT_CALLSTACKS() LLError::LLCallStacks::print()  /*  	Class type information for logging @@ -350,7 +355,7 @@ namespace LLError  #define LOG_CLASS(s)	typedef s _LL_CLASS_TO_LOG  	// Declares class to tag logged messages with.  	// See top of file for example of how to use this -	 +  typedef LLError::NoClassInfo _LL_CLASS_TO_LOG;  	// Outside a class declaration, or in class without LOG_CLASS(), this  	// typedef causes the messages to not be associated with any class. @@ -392,7 +397,7 @@ typedef LLError::NoClassInfo _LL_CLASS_TO_LOG;  //Use this construct if you need to do computation in the middle of a  //message: -//	 +//  //	LL_INFOS("AgentGesture") << "the agent " << agend_id;  //	switch (f)  //	{ @@ -401,17 +406,23 @@ typedef LLError::NoClassInfo _LL_CLASS_TO_LOG;  //		case FOP_SAYS:		LL_CONT << "says " << message;	break;  //	}  //	LL_CONT << " for " << t << " seconds" << LL_ENDL; -//	 +//  //Such computation is done iff the message will be logged.  #define LL_CONT	_out  #define LL_NEWLINE '\n'  // Use this only in LL_ERRS or in a place that LL_ERRS may not be used + +#ifndef LL_LINUX  #define LLERROR_CRASH                                   \  {                                                       \      crashdriver([](int* ptr){ *ptr = 0; exit(*ptr); }); \  } +#else +// For Linux we just call raise and be done with it. No fighting the compiler to create a crashing code snippet. +#define LLERROR_CRASH raise(SIGSEGV ); +#endif  #define LL_ENDL                                         \              LLError::End();                             \ @@ -510,7 +521,7 @@ LL_ENDL;  LL_DEBUGS("SomeTag") performs the locking and map-searching ONCE, then caches  the result in a static variable. -*/  +*/  // used by LLERROR_CRASH  void crashdriver(void (*)(int*)); diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp index 28f8bc2b93..4cdc3d7519 100644 --- a/indra/llcommon/llprocessor.cpp +++ b/indra/llcommon/llprocessor.cpp @@ -793,19 +793,55 @@ private:  };  #elif LL_LINUX + +// *NOTE:Mani - eww, macros! srry. +#define LLPI_SET_INFO_STRING(llpi_id, cpuinfo_id) \ +		if (!cpuinfo[cpuinfo_id].empty()) \ +		{ setInfo(llpi_id, cpuinfo[cpuinfo_id]);} + +#define LLPI_SET_INFO_INT(llpi_id, cpuinfo_id) \ +		{\ +			S32 result; \ +			if (!cpuinfo[cpuinfo_id].empty() \ +				&& LLStringUtil::convertToS32(cpuinfo[cpuinfo_id], result))	\ +		    { setInfo(llpi_id, result);} \ +		} +  const char CPUINFO_FILE[] = "/proc/cpuinfo"; -class LLProcessorInfoLinuxImpl : public LLProcessorInfoImpl -{ +class LLProcessorInfoLinuxImpl : public LLProcessorInfoImpl {  public: -	LLProcessorInfoLinuxImpl()  -	{ -		get_proc_cpuinfo(); -	} +    LLProcessorInfoLinuxImpl() { +        get_proc_cpuinfo(); +    } + +    virtual ~LLProcessorInfoLinuxImpl() {} -	virtual ~LLProcessorInfoLinuxImpl() {}  private: +    F64 getCPUMaxMHZ() +    { +        // Nicky: We just look into cpu0. In theory we could iterate over all cores +        // "/sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_max_freq" +        // But those should not fluctuate that much? +        std::ifstream fIn { "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" }; + +        if( !fIn.is_open() ) +            return 0.0; + +        std::string strLine; +        fIn >> strLine; +        if( strLine.empty() ) +            return 0.0l; + +        F64 mhz {}; +        if( !LLStringUtil::convertToF64(strLine, mhz ) ) +            return 0.0; + +        mhz = mhz / 1000.0; +        return mhz; +    } +  	void get_proc_cpuinfo()  	{  		std::map< std::string, std::string > cpuinfo; @@ -834,31 +870,24 @@ private:  				std::string llinename(linename);  				LLStringUtil::toLower(llinename);  				std::string lineval( spacespot + 1, nlspot ); -				cpuinfo[ llinename ] = lineval; +                    cpuinfo[ llinename ] = lineval;  			}  			fclose(cpuinfo_fp);  		}  # if LL_X86 -// *NOTE:Mani - eww, macros! srry. -#define LLPI_SET_INFO_STRING(llpi_id, cpuinfo_id) \ -		if (!cpuinfo[cpuinfo_id].empty()) \ -		{ setInfo(llpi_id, cpuinfo[cpuinfo_id]);} - -#define LLPI_SET_INFO_INT(llpi_id, cpuinfo_id) \ -		{\ -			S32 result; \ -			if (!cpuinfo[cpuinfo_id].empty() \ -				&& LLStringUtil::convertToS32(cpuinfo[cpuinfo_id], result))	\ -		    { setInfo(llpi_id, result);} \ -		} -		 -		F64 mhz; -		if (LLStringUtil::convertToF64(cpuinfo["cpu mhz"], mhz) -			&& 200.0 < mhz && mhz < 10000.0) -		{ -		    setInfo(eFrequency,(F64)(mhz)); -		} +        F64 mhzFromSys = getCPUMaxMHZ(); +        F64 mhzFromProc {}; +        if( !LLStringUtil::convertToF64(cpuinfo["cpu mhz"], mhzFromProc ) ) +            mhzFromProc = 0.0; +        if (mhzFromSys > 1.0 && mhzFromSys > mhzFromProc ) +        { +            setInfo( eFrequency, mhzFromSys ); +        } +        else if (  200.0 < mhzFromProc && mhzFromProc < 10000.0) +        { +            setInfo(eFrequency,(F64)(mhzFromProc)); +        }  		LLPI_SET_INFO_STRING(eBrandName, "model name");		  		LLPI_SET_INFO_STRING(eVendor, "vendor_id"); @@ -867,7 +896,7 @@ private:  		LLPI_SET_INFO_INT(eModel, "model"); -		S32 family;							  +		S32 family{};  		if (!cpuinfo["cpu family"].empty()   			&& LLStringUtil::convertToS32(cpuinfo["cpu family"], family))	  		{  diff --git a/indra/llcommon/llsdutil.cpp b/indra/llcommon/llsdutil.cpp index e98fc0285a..4d5fb0d818 100644 --- a/indra/llcommon/llsdutil.cpp +++ b/indra/llcommon/llsdutil.cpp @@ -1,4 +1,4 @@ -/**  +/**   * @file llsdutil.cpp   * @author Phoenix   * @date 2006-05-24 @@ -7,21 +7,21 @@   * $LicenseInfo:firstyear=2006&license=viewerlgpl$   * Second Life Viewer Source Code   * Copyright (C) 2010, Linden Research, Inc. - *  + *   * This library is free software; you can redistribute it and/or   * modify it under the terms of the GNU Lesser General Public   * License as published by the Free Software Foundation;   * version 2.1 of the License only. - *  + *   * This library 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   * Lesser General Public License for more details. - *  + *   * You should have received a copy of the GNU Lesser General Public   * License along with this library; if not, write to the Free Software   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA - *  + *   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ @@ -161,7 +161,7 @@ LLSD ll_binary_from_string(const LLSD& sd)  char* ll_print_sd(const LLSD& sd)  {  	const U32 bufferSize = 10 * 1024; -	static char buffer[bufferSize]; +	static char buffer[bufferSize + 1];  	std::ostringstream stream;  	//stream.rdbuf()->pubsetbuf(buffer, bufferSize);  	stream << LLSDOStreamer<LLSDXMLFormatter>(sd); @@ -183,7 +183,7 @@ char* ll_pretty_print_sd_ptr(const LLSD* sd)  char* ll_pretty_print_sd(const LLSD& sd)  {  	const U32 bufferSize = 100 * 1024; -	static char buffer[bufferSize]; +	static char buffer[bufferSize + 1];  	std::ostringstream stream;  	//stream.rdbuf()->pubsetbuf(buffer, bufferSize);  	stream << LLSDOStreamer<LLSDXMLFormatter>(sd, LLSDFormatter::OPTIONS_PRETTY); @@ -324,7 +324,7 @@ BOOL compare_llsd_with_template(  	return TRUE;  } -// filter_llsd_with_template() is a direct clone (copy-n-paste) of  +// filter_llsd_with_template() is a direct clone (copy-n-paste) of  // compare_llsd_with_template with the following differences:  // (1) bool vs BOOL return types  // (2) A map with the key value "*" is a special value and maps any key in the @@ -386,7 +386,7 @@ bool filter_llsd_with_template(  		else  		{  			// Traditional compare_llsd_with_template matching -			 +  			for (template_iter = template_llsd.beginArray();  				 template_iter != template_llsd.endArray() &&  					 test_iter != llsd_to_test.endArray(); @@ -417,7 +417,7 @@ bool filter_llsd_with_template(  	else if (llsd_to_test.isMap())  	{  		resultant_llsd = LLSD::emptyMap(); -		 +  		//now we loop over the keys of the two maps  		//any excess is taken from the template  		//excess is ignored in the test @@ -464,7 +464,7 @@ bool filter_llsd_with_template(  		{  			LLSD sub_value;  			LLSD::map_const_iterator test_iter; -			 +  			for (test_iter = llsd_to_test.beginMap();  				 test_iter != llsd_to_test.endMap();  				 ++test_iter) @@ -944,9 +944,9 @@ LLSD drill(const LLSD& blob, const LLSD& path)  } // namespace llsd -// Construct a deep partial clone of of an LLSD object. primitive types share  +// Construct a deep partial clone of of an LLSD object. primitive types share  // references, however maps, arrays and binary objects are duplicated. An optional -// filter may be include to exclude/include keys in a map.  +// filter may be include to exclude/include keys in a map.  LLSD llsd_clone(LLSD value, LLSD filter)  {      LL_PROFILE_ZONE_SCOPED diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp index 42400e90af..e53c82ad2b 100644 --- a/indra/llcommon/llsys.cpp +++ b/indra/llcommon/llsys.cpp @@ -1,25 +1,25 @@ -/**  +/**   * @file llsys.cpp   * @brief Implementation of the basic system query functions.   *   * $LicenseInfo:firstyear=2002&license=viewerlgpl$   * Second Life Viewer Source Code   * Copyright (C) 2010, Linden Research, Inc. - *  + *   * This library is free software; you can redistribute it and/or   * modify it under the terms of the GNU Lesser General Public   * License as published by the Free Software Foundation;   * version 2.1 of the License only. - *  + *   * This library 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   * Lesser General Public License for more details. - *  + *   * You should have received a copy of the GNU Lesser General Public   * License along with this library; if not, write to the Free Software   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA - *  + *   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ @@ -96,7 +96,7 @@ static const F32 MEM_INFO_THROTTLE = 20;  static const F32 MEM_INFO_WINDOW = 10*60;  LLOSInfo::LLOSInfo() : -	mMajorVer(0), mMinorVer(0), mBuild(0), mOSVersionString("")	  +	mMajorVer(0), mMinorVer(0), mBuild(0), mOSVersionString("")  {  #if LL_WINDOWS @@ -186,7 +186,7 @@ LLOSInfo::LLOSInfo() :  	if (NULL != pGNSI) //check if it has failed  		pGNSI(&si); //success  	else -		GetSystemInfo(&si); //if it fails get regular system info  +		GetSystemInfo(&si); //if it fails get regular system info  	//(Warning: If GetSystemInfo it may result in incorrect information in a WOW64 machine, if the kernel fails to load)  	// Try calling GetVersionEx using the OSVERSIONINFOEX structure. @@ -266,12 +266,12 @@ LLOSInfo::LLOSInfo() :  	LLStringUtil::trim(mOSString);  #elif LL_DARWIN -	 +  	// Initialize mOSStringSimple to something like:  	// "Mac OS X 10.6.7"  	{  		const char * DARWIN_PRODUCT_NAME = "Mac OS X"; -		 +  		int64_t major_version, minor_version, bugfix_version = 0;  		if (LLGetDarwinOSInfo(major_version, minor_version, bugfix_version)) @@ -282,7 +282,7 @@ LLOSInfo::LLOSInfo() :  			std::stringstream os_version_string;  			os_version_string << DARWIN_PRODUCT_NAME << " " << mMajorVer << "." << mMinorVer << "." << mBuild; -			 +  			// Put it in the OS string we are compiling  			mOSStringSimple.append(os_version_string.str());  		} @@ -291,12 +291,12 @@ LLOSInfo::LLOSInfo() :  			mOSStringSimple.append("Unable to collect OS info");  		}  	} -	 +  	// Initialize mOSString to something like:  	// "Mac OS X 10.6.7 Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386 i386"  	struct utsname un;  	if(uname(&un) != -1) -	{		 +	{  		mOSString = mOSStringSimple;  		mOSString.append(" ");  		mOSString.append(un.sysname); @@ -311,9 +311,9 @@ LLOSInfo::LLOSInfo() :  	{  		mOSString = mOSStringSimple;  	} -	 +  #elif LL_LINUX -	 +  	struct utsname un;  	if(uname(&un) != -1)  	{ @@ -353,7 +353,7 @@ LLOSInfo::LLOSInfo() :  	if ( ll_regex_match(glibc_version, matched, os_version_parse) )  	{  		LL_INFOS("AppInit") << "Using glibc version '" << glibc_version << "' as OS version" << LL_ENDL; -	 +  		std::string version_value;  		if ( matched[1].matched ) // Major version @@ -367,7 +367,7 @@ LLOSInfo::LLOSInfo() :  		else  		{  			LL_ERRS("AppInit") -				<< "OS version regex '" << OS_VERSION_MATCH_EXPRESSION  +				<< "OS version regex '" << OS_VERSION_MATCH_EXPRESSION  				<< "' returned true, but major version [1] did not match"  				<< LL_ENDL;  		} @@ -383,7 +383,7 @@ LLOSInfo::LLOSInfo() :  		else  		{  			LL_ERRS("AppInit") -				<< "OS version regex '" << OS_VERSION_MATCH_EXPRESSION  +				<< "OS version regex '" << OS_VERSION_MATCH_EXPRESSION  				<< "' returned true, but minor version [1] did not match"  				<< LL_ENDL;  		} @@ -409,7 +409,7 @@ LLOSInfo::LLOSInfo() :  	}  #else -	 +  	struct utsname un;  	if(uname(&un) != -1)  	{ @@ -509,57 +509,46 @@ const S32 LLOSInfo::getOSBitness() const  	return mOSBitness;  } -//static -U32 LLOSInfo::getProcessVirtualSizeKB() -{ -	U32 virtual_size = 0; +namespace { + +    U32 readFromProcStat( std::string entryName ) +    { +        U32 val{};  #if LL_LINUX -#   define STATUS_SIZE 2048	 -	LLFILE* status_filep = LLFile::fopen("/proc/self/status", "rb"); -	if (status_filep) -	{ -		S32 numRead = 0;		 -		char buff[STATUS_SIZE];		/* Flawfinder: ignore */ +        constexpr U32 STATUS_SIZE  = 2048; -		size_t nbytes = fread(buff, 1, STATUS_SIZE-1, status_filep); -		buff[nbytes] = '\0'; +        LLFILE* status_filep = LLFile::fopen("/proc/self/status", "rb"); +        if (status_filep) +        { +            char buff[STATUS_SIZE];		/* Flawfinder: ignore */ -		// All these guys return numbers in KB -		char *memp = strstr(buff, "VmSize:"); -		if (memp) -		{ -			numRead += sscanf(memp, "%*s %u", &virtual_size); -		} -		fclose(status_filep); -	} +            size_t nbytes = fread(buff, 1, STATUS_SIZE-1, status_filep); +            buff[nbytes] = '\0'; + +            // All these guys return numbers in KB +            char *memp = strstr(buff, entryName.c_str()); +            if (memp) +            { +                (void) sscanf(memp, "%*s %u", &val); +            } +            fclose(status_filep); +        }  #endif -	return virtual_size; +        return val; +    } +  }  //static -U32 LLOSInfo::getProcessResidentSizeKB() +U32 LLOSInfo::getProcessVirtualSizeKB()  { -	U32 resident_size = 0; -#if LL_LINUX -	LLFILE* status_filep = LLFile::fopen("/proc/self/status", "rb"); -	if (status_filep != NULL) -	{ -		S32 numRead = 0; -		char buff[STATUS_SIZE];		/* Flawfinder: ignore */ - -		size_t nbytes = fread(buff, 1, STATUS_SIZE-1, status_filep); -		buff[nbytes] = '\0'; +    return readFromProcStat( "VmSize:" ); +} -		// All these guys return numbers in KB -		char *memp = strstr(buff, "VmRSS:"); -		if (memp) -		{ -			numRead += sscanf(memp, "%*s %u", &resident_size); -		} -		fclose(status_filep); -	} -#endif -	return resident_size; +//static +U32 LLOSInfo::getProcessResidentSizeKB() +{ +    return readFromProcStat( "VmRSS:" );  }  //static @@ -577,7 +566,7 @@ bool LLOSInfo::is64Bit()  #endif  #else // ! LL_WINDOWS      // we only build a 64-bit mac viewer and currently we don't build for linux at all -    return true;  +    return true;  #endif  } @@ -1001,11 +990,11 @@ LLSD LLMemoryInfo::loadStatsMap()  #elif LL_DARWIN  	const vm_size_t pagekb(vm_page_size / 1024); -	 +  	//  	// Collect the vm_stat's  	// -	 +  	{  		vm_statistics64_data_t vmstat;  		mach_msg_type_number_t vmstatCount = HOST_VM_INFO64_COUNT; @@ -1025,16 +1014,16 @@ LLSD LLMemoryInfo::loadStatsMap()  			stats.add("Page reactivations",		vmstat.reactivations);  			stats.add("Page-ins",				vmstat.pageins);  			stats.add("Page-outs",				vmstat.pageouts); -			 +  			stats.add("Faults",					vmstat.faults);  			stats.add("Faults copy-on-write",	vmstat.cow_faults); -			 +  			stats.add("Cache lookups",			vmstat.lookups);  			stats.add("Cache hits",				vmstat.hits); -			 +  			stats.add("Page purgeable count",	vmstat.purgeable_count);  			stats.add("Page purges",			vmstat.purges); -			 +  			stats.add("Page speculative reads",	vmstat.speculative_count);  		}  	} @@ -1046,7 +1035,7 @@ LLSD LLMemoryInfo::loadStatsMap()  		{  		task_events_info_data_t taskinfo;  		unsigned taskinfoSize = sizeof(taskinfo); -		 +  		if (task_info(mach_task_self(), TASK_EVENTS_INFO, (task_info_t) &taskinfo, &taskinfoSize) != KERN_SUCCESS)  					{  			LL_WARNS("LLMemoryInfo") << "Unable to collect task information" << LL_ENDL; @@ -1061,8 +1050,8 @@ LLSD LLMemoryInfo::loadStatsMap()  			stats.add("Task unix system call count",	taskinfo.syscalls_unix);  			stats.add("Task context switch count",		taskinfo.csw);  			} -	}	 -	 +	} +  	//  	// Collect the basic task info  	// @@ -1348,8 +1337,8 @@ BOOL gunzip_file(const std::string& srcfile, const std::string& dstfile)  			goto err;  		}  	} while(gzeof(src) == 0); -	fclose(dst);  -	dst = NULL;	 +	fclose(dst); +	dst = NULL;  	if (LLFile::rename(tmpfile, dstfile) == -1) goto err;		/* Flawfinder: ignore */  	retval = TRUE;  err: | 
