mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0023081: This is desirable to retrieve GPU memory information from graphic driver
Added Graphic3d_GraphicDriver::MemoryInfo() function. Added vfps command to estimate average frame rate of 3D Viewer Simplified vdrawsphere command Removed turnVbo and performance measurements from vdrawsphere. Added vvbo command to control VBO usage flag. Added vmemgpu command to display GPU memory info from graphic driver
This commit is contained in:
@@ -23,3 +23,5 @@ OSD_PerfMeter.h
|
||||
OSD_PerfMeter.hxx
|
||||
OSD_MAllocHook.cxx
|
||||
OSD_MAllocHook.hxx
|
||||
OSD_MemInfo.hxx
|
||||
OSD_MemInfo.cxx
|
||||
|
@@ -174,6 +174,7 @@ is
|
||||
---Purpose: Provides tools to load a shared library
|
||||
-- and retrieve the address of an entry point.
|
||||
|
||||
imported MemInfo;
|
||||
imported PThread;
|
||||
imported ThreadFunction;
|
||||
class Thread;
|
||||
|
207
src/OSD/OSD_MemInfo.cxx
Normal file
207
src/OSD/OSD_MemInfo.cxx
Normal file
@@ -0,0 +1,207 @@
|
||||
// Created on: 2011-10-05
|
||||
// Created by: Kirill GAVRILOV
|
||||
// Copyright (c) 2012 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#if (defined(_WIN32) || defined(__WIN32__))
|
||||
#include <windows.h>
|
||||
#include <winbase.h>
|
||||
#include <process.h>
|
||||
#include <Psapi.h>
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "Psapi.lib")
|
||||
#endif
|
||||
#elif (defined(__APPLE__))
|
||||
#include <mach/task.h>
|
||||
#include <mach/mach.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#include <OSD_MemInfo.hxx>
|
||||
|
||||
// =======================================================================
|
||||
// function : OSD_MemInfo
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
OSD_MemInfo::OSD_MemInfo()
|
||||
{
|
||||
Update();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Update
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OSD_MemInfo::Update()
|
||||
{
|
||||
// reset values
|
||||
for (Standard_Integer anIter = 0; anIter < MemCounter_NB; ++anIter)
|
||||
{
|
||||
myCounters[anIter] = Standard_Size(-1);
|
||||
}
|
||||
|
||||
#if (defined(_WIN32) || defined(__WIN32__))
|
||||
MEMORYSTATUSEX aStatEx;
|
||||
aStatEx.dwLength = sizeof(aStatEx);
|
||||
GlobalMemoryStatusEx (&aStatEx);
|
||||
myCounters[MemVirtual] = Standard_Size(aStatEx.ullTotalVirtual - aStatEx.ullAvailVirtual);
|
||||
|
||||
// use Psapi library
|
||||
HANDLE aProcess = GetCurrentProcess();
|
||||
PROCESS_MEMORY_COUNTERS_EX aProcMemCnts;
|
||||
if (GetProcessMemoryInfo (aProcess, (PROCESS_MEMORY_COUNTERS* )&aProcMemCnts, sizeof(aProcMemCnts)))
|
||||
{
|
||||
myCounters[MemPrivate] = aProcMemCnts.PrivateUsage;
|
||||
myCounters[MemWorkingSet] = aProcMemCnts.WorkingSetSize;
|
||||
myCounters[MemWorkingSetPeak] = aProcMemCnts.PeakWorkingSetSize;
|
||||
myCounters[MemSwapUsage] = aProcMemCnts.PagefileUsage;
|
||||
myCounters[MemSwapUsagePeak] = aProcMemCnts.PeakPagefileUsage;
|
||||
}
|
||||
#elif (defined(__linux__) || defined(__linux))
|
||||
// use procfs on Linux
|
||||
char aBuff[4096];
|
||||
snprintf (aBuff, sizeof(aBuff), "/proc/%d/status", getpid());
|
||||
std::ifstream aFile;
|
||||
aFile.open (aBuff);
|
||||
if (!aFile.is_open())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (!aFile.eof())
|
||||
{
|
||||
memset (aBuff, 0, sizeof(aBuff));
|
||||
aFile.getline (aBuff, 4096);
|
||||
if (aBuff[0] == '\0')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strncmp (aBuff, "VmSize:", strlen ("VmSize:")) == 0)
|
||||
{
|
||||
myCounters[MemVirtual] = atol (aBuff + strlen ("VmSize:")) * 1024;
|
||||
}
|
||||
//else if (strncmp (aBuff, "VmPeak:", strlen ("VmPeak:")) == 0)
|
||||
// myVirtualPeak = atol (aBuff + strlen ("VmPeak:")) * 1024;
|
||||
else if (strncmp (aBuff, "VmRSS:", strlen ("VmRSS:")) == 0)
|
||||
{
|
||||
myCounters[MemWorkingSet] = atol (aBuff + strlen ("VmRSS:")) * 1024; // RSS - resident set size
|
||||
}
|
||||
else if (strncmp (aBuff, "VmHWM:", strlen ("VmHWM:")) == 0)
|
||||
{
|
||||
myCounters[MemWorkingSetPeak] = atol (aBuff + strlen ("VmHWM:")) * 1024; // HWM - high water mark
|
||||
}
|
||||
else if (strncmp (aBuff, "VmData:", strlen ("VmData:")) == 0)
|
||||
{
|
||||
if (myCounters[MemPrivate] == Standard_Size(-1)) ++myCounters[MemPrivate];
|
||||
myCounters[MemPrivate] += atol (aBuff + strlen ("VmData:")) * 1024;
|
||||
}
|
||||
else if (strncmp (aBuff, "VmStk:", strlen ("VmStk:")) == 0)
|
||||
{
|
||||
if (myCounters[MemPrivate] == Standard_Size(-1)) ++myCounters[MemPrivate];
|
||||
myCounters[MemPrivate] += atol (aBuff + strlen ("VmStk:")) * 1024;
|
||||
}
|
||||
}
|
||||
aFile.close();
|
||||
#elif (defined(__APPLE__))
|
||||
struct task_basic_info aTaskInfo;
|
||||
mach_msg_type_number_t aTaskInfoCount = TASK_BASIC_INFO_COUNT;
|
||||
if (task_info (mach_task_self(), TASK_BASIC_INFO,
|
||||
(task_info_t )&aTaskInfo, &aTaskInfoCount) == KERN_SUCCESS)
|
||||
{
|
||||
// On Mac OS X, these values in bytes, not pages!
|
||||
myCounters[MemVirtual] = aTaskInfo.virtual_size;
|
||||
myCounters[MemWorkingSet] = aTaskInfo.resident_size;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ToString
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TCollection_AsciiString OSD_MemInfo::ToString() const
|
||||
{
|
||||
TCollection_AsciiString anInfo;
|
||||
if (myCounters[MemPrivate] != Standard_Size(-1))
|
||||
{
|
||||
anInfo += TCollection_AsciiString(" Private memory: ") + Standard_Integer (ValueMiB (MemPrivate)) + " MiB\n";
|
||||
}
|
||||
if (myCounters[MemWorkingSet] != Standard_Size(-1))
|
||||
{
|
||||
anInfo += TCollection_AsciiString(" Working Set: ") + Standard_Integer (ValueMiB (MemWorkingSet)) + " MiB";
|
||||
if (myCounters[MemWorkingSetPeak] != Standard_Size(-1))
|
||||
{
|
||||
anInfo += TCollection_AsciiString(" (peak: ") + Standard_Integer (ValueMiB (MemWorkingSetPeak)) + " MiB)";
|
||||
}
|
||||
anInfo += "\n";
|
||||
}
|
||||
if (myCounters[MemSwapUsage] != Standard_Size(-1))
|
||||
{
|
||||
anInfo += TCollection_AsciiString(" Pagefile usage: ") + Standard_Integer (ValueMiB (MemSwapUsage)) + " MiB";
|
||||
if (myCounters[MemSwapUsagePeak] != Standard_Size(-1))
|
||||
{
|
||||
anInfo += TCollection_AsciiString(" (peak: ") + Standard_Integer (ValueMiB (MemSwapUsagePeak)) + " MiB)";
|
||||
}
|
||||
anInfo += "\n";
|
||||
}
|
||||
if (myCounters[MemVirtual] != Standard_Size(-1))
|
||||
{
|
||||
anInfo += TCollection_AsciiString(" Virtual memory: ") + Standard_Integer (ValueMiB (MemVirtual)) + " MiB\n";
|
||||
}
|
||||
return anInfo;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Value
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Size OSD_MemInfo::Value (const OSD_MemInfo::Counter theCounter) const
|
||||
{
|
||||
if (theCounter < 0 || theCounter >= MemCounter_NB)
|
||||
{
|
||||
return Standard_Size(-1);
|
||||
}
|
||||
return myCounters[theCounter];
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ValueMiB
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Size OSD_MemInfo::ValueMiB (const OSD_MemInfo::Counter theCounter) const
|
||||
{
|
||||
if (theCounter < 0 || theCounter >= MemCounter_NB)
|
||||
{
|
||||
return Standard_Size(-1);
|
||||
}
|
||||
return (myCounters[theCounter] == Standard_Size(-1))
|
||||
? Standard_Size(-1) : (myCounters[theCounter] / (1024 * 1024));
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ShowInfo
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TCollection_AsciiString OSD_MemInfo::PrintInfo()
|
||||
{
|
||||
OSD_MemInfo anInfo;
|
||||
return anInfo.ToString();
|
||||
}
|
102
src/OSD/OSD_MemInfo.hxx
Normal file
102
src/OSD/OSD_MemInfo.hxx
Normal file
@@ -0,0 +1,102 @@
|
||||
// Created on: 2011-10-05
|
||||
// Created by: Kirill GAVRILOV
|
||||
// Copyright (c) 2012 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#ifndef _OSD_MemInfo_H__
|
||||
#define _OSD_MemInfo_H__
|
||||
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
//! This class provide information about memory utilized by current process.
|
||||
//! This information includes:
|
||||
//! - Private Memory - synthetic value that tries to filter out the memory
|
||||
//! usage only by the process itself (allocated for data
|
||||
//! and stack), excluding dynamic libraries.
|
||||
//! These pages may be in RAM or in SWAP.
|
||||
//! - Virtual Memory - amount of reserved and committed memory in the
|
||||
//! user-mode portion of the virtual address space.
|
||||
//! Notice that this counter includes reserved memory
|
||||
//! (not yet in used) and shared between processes memory (libraries).
|
||||
//! - Working Set - set of memory pages in the virtual address space of the process
|
||||
//! that are currently resident in physical memory (RAM).
|
||||
//! These pages are available for an application to use
|
||||
//! without triggering a page fault.
|
||||
//! - Pagefile Usage - space allocated for the pagefile, in bytes.
|
||||
//! Those pages may or may not be in memory (RAM)
|
||||
//! thus this counter couldn't be used to estimate
|
||||
//! how many active pages doesn't present in RAM.
|
||||
//!
|
||||
//! Notice that none of these counters can be used as absolute measure of
|
||||
//! application memory consumption!
|
||||
//!
|
||||
//! User should analyze all values in specific case to make correct decision
|
||||
//! about memory (over)usage. This is also prefferred to use specialized
|
||||
//! tools to detect memory leaks.
|
||||
//!
|
||||
//! This also means that these values should not be used for intellectual
|
||||
//! memory management by application itself.
|
||||
class OSD_MemInfo : public Standard_Transient
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
enum Counter
|
||||
{
|
||||
MemPrivate = 0, //!< Virtual memory allocated for data and stack excluding libraries
|
||||
MemVirtual, //!< Reserved and committed memory of the virtual address space
|
||||
MemWorkingSet, //!< Memory pages that are currently resident in physical memory
|
||||
MemWorkingSetPeak, //!< Peak working set size
|
||||
MemSwapUsage, //!< Space allocated for the pagefile
|
||||
MemSwapUsagePeak, //!< Peak space allocated for the pagefile
|
||||
MemCounter_NB //!< Indicates total counters number
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
//! Create and initialize
|
||||
Standard_EXPORT OSD_MemInfo();
|
||||
|
||||
//! Update counters
|
||||
Standard_EXPORT void Update();
|
||||
|
||||
//! Return the string representation for all available counter.
|
||||
Standard_EXPORT TCollection_AsciiString ToString() const;
|
||||
|
||||
//! Return value or specified counter in bytes.
|
||||
//! Notice that NOT all counters are available on various systems.
|
||||
//! Standard_Size(-1) means invalid (unavailable) value.
|
||||
Standard_EXPORT Standard_Size Value (const OSD_MemInfo::Counter theCounter) const;
|
||||
|
||||
//! Return value or specified counter in MiB.
|
||||
//! Notice that NOT all counters are available on various systems.
|
||||
//! Standard_Size(-1) means invalid (unavailable) value.
|
||||
Standard_EXPORT Standard_Size ValueMiB (const OSD_MemInfo::Counter theCounter) const;
|
||||
|
||||
public:
|
||||
|
||||
//! Return the string representation for all available counter.
|
||||
Standard_EXPORT static TCollection_AsciiString PrintInfo();
|
||||
|
||||
private:
|
||||
|
||||
Standard_Size myCounters[MemCounter_NB]; //!< Counters' values, in bytes
|
||||
|
||||
};
|
||||
|
||||
#endif // _OSD_MemInfo_H__
|
Reference in New Issue
Block a user