aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llsys.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcommon/llsys.cpp')
-rw-r--r--linden/indra/llcommon/llsys.cpp81
1 files changed, 61 insertions, 20 deletions
diff --git a/linden/indra/llcommon/llsys.cpp b/linden/indra/llcommon/llsys.cpp
index 25749e1..95b6b55 100644
--- a/linden/indra/llcommon/llsys.cpp
+++ b/linden/indra/llcommon/llsys.cpp
@@ -46,6 +46,7 @@
46#elif LL_DARWIN 46#elif LL_DARWIN
47# include <sys/sysctl.h> 47# include <sys/sysctl.h>
48# include <sys/utsname.h> 48# include <sys/utsname.h>
49# include <stdint.h>
49#elif LL_LINUX 50#elif LL_LINUX
50# include <sys/utsname.h> 51# include <sys/utsname.h>
51# include <unistd.h> 52# include <unistd.h>
@@ -482,57 +483,97 @@ LLMemoryInfo::LLMemoryInfo()
482{ 483{
483} 484}
484 485
485U32 LLMemoryInfo::getPhysicalMemory() const 486#if LL_WINDOWS
487static U32 LLMemoryAdjustKBResult(U32 inKB)
488{
489 // Moved this here from llfloaterabout.cpp
490
491 //! \bug
492 // For some reason, the reported amount of memory is always wrong.
493 // The original adjustment assumes it's always off by one meg, however
494 // errors of as much as 2520 KB have been observed in the value
495 // returned from the GetMemoryStatusEx function. Here we keep the
496 // original adjustment from llfoaterabout.cpp until this can be
497 // fixed somehow.
498 inKB += 1024;
499
500 return inKB;
501}
502#endif
503
504U32 LLMemoryInfo::getPhysicalMemoryKB() const
486{ 505{
487#if LL_WINDOWS 506#if LL_WINDOWS
488 MEMORYSTATUS state; 507 MEMORYSTATUSEX state;
489 state.dwLength = sizeof(state); 508 state.dwLength = sizeof(state);
490 GlobalMemoryStatus(&state); 509 GlobalMemoryStatusEx(&state);
491 510
492 return (U32)state.dwTotalPhys; 511 return LLMemoryAdjustKBResult((U32)(state.ullTotalPhys >> 10));
493 512
494#elif LL_DARWIN 513#elif LL_DARWIN
495 // This might work on Linux as well. Someone check... 514 // This might work on Linux as well. Someone check...
496 unsigned int phys = 0; 515 uint64_t phys = 0;
497 int mib[2] = { CTL_HW, HW_PHYSMEM }; 516 int mib[2] = { CTL_HW, HW_MEMSIZE };
498 517
499 size_t len = sizeof(phys); 518 size_t len = sizeof(phys);
500 sysctl(mib, 2, &phys, &len, NULL, 0); 519 sysctl(mib, 2, &phys, &len, NULL, 0);
501 520
502 return phys; 521 return (U32)(phys >> 10);
522
503#elif LL_LINUX 523#elif LL_LINUX
524 U64 phys = 0;
525 phys = (U64)(getpagesize()) * (U64)(get_phys_pages());
526 return (U32)(phys >> 10);
504 527
505 return getpagesize() * get_phys_pages();
506#elif LL_SOLARIS 528#elif LL_SOLARIS
507 return getpagesize() * sysconf(_SC_PHYS_PAGES); 529 U64 phys = 0;
530 phys = (U64)(getpagesize()) * (U64)(sysconf(_SC_PHYS_PAGES));
531 return (U32)(phys >> 10);
532
508#else 533#else
509 return 0; 534 return 0;
510 535
511#endif 536#endif
512} 537}
513 538
539U32 LLMemoryInfo::getPhysicalMemoryClamped() const
540{
541 // Return the total physical memory in bytes, but clamp it
542 // to no more than U32_MAX
543
544 U32 phys_kb = getPhysicalMemoryKB();
545 if (phys_kb >= 4194304 /* 4GB in KB */)
546 {
547 return U32_MAX;
548 }
549 else
550 {
551 return phys_kb << 10;
552 }
553}
554
514void LLMemoryInfo::stream(std::ostream& s) const 555void LLMemoryInfo::stream(std::ostream& s) const
515{ 556{
516#if LL_WINDOWS 557#if LL_WINDOWS
517 MEMORYSTATUS state; 558 MEMORYSTATUSEX state;
518 state.dwLength = sizeof(state); 559 state.dwLength = sizeof(state);
519 GlobalMemoryStatus(&state); 560 GlobalMemoryStatusEx(&state);
520 561
521 s << "Percent Memory use: " << (U32)state.dwMemoryLoad << '%' << std::endl; 562 s << "Percent Memory use: " << (U32)state.dwMemoryLoad << '%' << std::endl;
522 s << "Total Physical Kb: " << (U32)state.dwTotalPhys/1024 << std::endl; 563 s << "Total Physical KB: " << (U32)(state.ullTotalPhys/1024) << std::endl;
523 s << "Avail Physical Kb: " << (U32)state.dwAvailPhys/1024 << std::endl; 564 s << "Avail Physical KB: " << (U32)(state.ullAvailPhys/1024) << std::endl;
524 s << "Total page Kb: " << (U32)state.dwTotalPageFile/1024 << std::endl; 565 s << "Total page KB: " << (U32)(state.ullTotalPageFile/1024) << std::endl;
525 s << "Avail page Kb: " << (U32)state.dwAvailPageFile/1024 << std::endl; 566 s << "Avail page KB: " << (U32)(state.ullAvailPageFile/1024) << std::endl;
526 s << "Total Virtual Kb: " << (U32)state.dwTotalVirtual/1024 << std::endl; 567 s << "Total Virtual KB: " << (U32)(state.ullTotalVirtual/1024) << std::endl;
527 s << "Avail Virtual Kb: " << (U32)state.dwAvailVirtual/1024 << std::endl; 568 s << "Avail Virtual KB: " << (U32)(state.ullAvailVirtual/1024) << std::endl;
528#elif LL_DARWIN 569#elif LL_DARWIN
529 U64 phys = 0; 570 uint64_t phys = 0;
530 571
531 size_t len = sizeof(phys); 572 size_t len = sizeof(phys);
532 573
533 if(sysctlbyname("hw.memsize", &phys, &len, NULL, 0) == 0) 574 if(sysctlbyname("hw.memsize", &phys, &len, NULL, 0) == 0)
534 { 575 {
535 s << "Total Physical Kb: " << phys/1024 << std::endl; 576 s << "Total Physical KB: " << phys/1024 << std::endl;
536 } 577 }
537 else 578 else
538 { 579 {
@@ -543,7 +584,7 @@ void LLMemoryInfo::stream(std::ostream& s) const
543 584
544 phys = (U64)(sysconf(_SC_PHYS_PAGES)) * (U64)(sysconf(_SC_PAGESIZE)/1024); 585 phys = (U64)(sysconf(_SC_PHYS_PAGES)) * (U64)(sysconf(_SC_PAGESIZE)/1024);
545 586
546 s << "Total Physical Kb: " << phys << std::endl; 587 s << "Total Physical KB: " << phys << std::endl;
547#else 588#else
548 // *NOTE: This works on linux. What will it do on other systems? 589 // *NOTE: This works on linux. What will it do on other systems?
549 FILE* meminfo = LLFile::fopen(MEMINFO_FILE,"rb"); 590 FILE* meminfo = LLFile::fopen(MEMINFO_FILE,"rb");