summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/llprocessor.cpp85
-rw-r--r--indra/llcommon/llsdutil.cpp5
-rw-r--r--indra/llcommon/llsys.cpp133
3 files changed, 121 insertions, 102 deletions
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..7438524272 100644
--- a/indra/llcommon/llsdutil.cpp
+++ b/indra/llcommon/llsdutil.cpp
@@ -36,6 +36,7 @@
# include <winsock2.h> // for htonl
#elif LL_LINUX
# include <netinet/in.h>
+#pragma GCC diagnostic ignored "-Wstringop-truncation" // It's actually okay what happens here
#elif LL_DARWIN
# include <arpa/inet.h>
#endif
@@ -161,7 +162,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 +184,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);
diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp
index 2bf12fb0eb..7473de988c 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$
*/
@@ -97,7 +97,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
@@ -187,7 +187,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.
@@ -267,12 +267,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))
@@ -283,7 +283,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());
}
@@ -292,12 +292,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);
@@ -312,9 +312,9 @@ LLOSInfo::LLOSInfo() :
{
mOSString = mOSStringSimple;
}
-
+
#elif LL_LINUX
-
+
struct utsname un;
if(uname(&un) != -1)
{
@@ -354,7 +354,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
@@ -368,7 +368,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;
}
@@ -384,7 +384,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;
}
@@ -410,7 +410,7 @@ LLOSInfo::LLOSInfo() :
}
#else
-
+
struct utsname un;
if(uname(&un) != -1)
{
@@ -510,57 +510,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
@@ -578,7 +567,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
}
@@ -1003,11 +992,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;
@@ -1027,16 +1016,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);
}
}
@@ -1048,7 +1037,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;
@@ -1063,8 +1052,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
//
@@ -1350,8 +1339,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: