Если вы используете Windows, вы можете вызывать память Powershell и другие объекты производительности для RGui и сжатия памяти как системные команды через R и вызывать различные счетчики памяти. У меня пока нет пути для хранения объектов Powershell в R. Код Powershell для RGui и «Сжатие памяти», используемый Windows для хранения часто используемых объектов:
$t1 = ps | where {$_.Name -EQ 'RGui' -or $_.Name -EQ 'Memory Compression'};
$t2 = $t1 | Select { $_.Id;
[math]::Round($_.WorkingSet64/1MB);
[math]::Round($_.PrivateMemorySize64/1MB);
[math]::Round($_.VirtualMemorySize64/1MB) };
$t2 | ft *
$t1 | gm -View All
$t1.Modules
$t1.MaxWorkingSet
Встроенный в R Powershell:
ps_f <- function() { system("powershell -ExecutionPolicy Bypass -command $t1 = ps | where {$_.Name -EQ 'RGui' -or $_.Name -EQ 'Memory Compression'};
$t2 = $t1 | Select {
$_.Id;
[math]::Round($_.WorkingSet64/1MB);
[math]::Round($_.PrivateMemorySize64/1MB);
[math]::Round($_.VirtualMemorySize64/1MB) };
$t2 | ft * "); }
ps_f()
$_.Id;
[math]::Round($_.WorkingSet64/1MB);
[math]::Round($_.PrivateMemorySize64/1MB);
[math]::Round($_.VirtualMemorySize64/1MB)
-----------------------------------------------------------------------------------------------------------------------
{2264, 1076, 3, 1401}
{15832, 3544, 6691, 11965}
ps_mem <- function() { system("powershell -ExecutionPolicy Bypass -command $t1 = ps | where {$_.Name -EQ 'RGui' -or $_.Name -EQ 'Memory Compression'};
$t1 | Select ProcessName,MaxWorkingSet,MinWorkingSet,PagedMemorySize64,NonpagedSystemMemorySize64;")}
> ps_mem()
ProcessName : Memory Compression
MaxWorkingSet :
MinWorkingSet :
PagedMemorySize64 : 3411968
NonpagedSystemMemorySize64 : 0
ProcessName : Rgui
MaxWorkingSet : 1413120
MinWorkingSet : 204800
PagedMemorySize64 : 7014719488
NonpagedSystemMemorySize64 : 6662736
# run some data.table operation
> ps_mem()
ProcessName : Memory Compression
MaxWorkingSet :
MinWorkingSet :
PagedMemorySize64 : 3411968
NonpagedSystemMemorySize64 : 0
ProcessName : Rgui
MaxWorkingSet : 1413120
MinWorkingSet : 204800
PagedMemorySize64 : 7015915520
NonpagedSystemMemorySize64 : 6662736
Код Powershell:
$t1 | where {$_.ProcessName -eq "Rgui"} | Measure-Object -Maximum *memory* | ft Property,Maximum
Powershell, встроенный в R:
ps_mem_ <- function() { system("powershell -ExecutionPolicy Bypass -command $t1 = ps | where {$_.Name -EQ 'RGui' -or $_.Name -EQ 'Memory Compression'};
$t2 = $t1 | where {$_.ProcessName -eq 'Rgui'};
$t2 | Measure-Object -Maximum *memory* | ft Property,Maximum ")}
# having some problems with rollover...
> ps_mem_()
Property Maximum
-------- -------
NonpagedSystemMemorySize 6662736
NonpagedSystemMemorySize64 6662736
PagedMemorySize -1570734080
PagedMemorySize64 7019200512
PagedSystemMemorySize 680240
PagedSystemMemorySize64 680240
PeakPagedMemorySize -1260961792
PeakPagedMemorySize64 11623940096
PeakVirtualMemorySize -161009664
PeakVirtualMemorySize64 17018859520
PrivateMemorySize -1570734080
PrivateMemorySize64 7019200512
VirtualMemorySize -339103744
VirtualMemorySize64 12545798144
some data.table run
> ps_mem_()
Property Maximum
-------- -------
NonpagedSystemMemorySize 6662736
NonpagedSystemMemorySize64 6662736
PagedMemorySize -1570734080
PagedMemorySize64 7019200512
PagedSystemMemorySize 680240
PagedSystemMemorySize64 680240
PeakPagedMemorySize -1260961792
PeakPagedMemorySize64 11623940096
PeakVirtualMemorySize -161009664
PeakVirtualMemorySize64 17018859520
PrivateMemorySize -1570734080
PrivateMemorySize64 7019200512
VirtualMemorySize -339103744
VirtualMemorySize64 12545798144
Чтобы увидеть все объекты Rgui:
$t1 | gm -View All
TypeName: System.Diagnostics.Process
Name MemberType Definition
---- ---------- ----------
Handles AliasProperty Handles = Handlecount
Name AliasProperty Name = ProcessName
NPM AliasProperty NPM = NonpagedSystemMemorySize64
PM AliasProperty PM = PagedMemorySize64
SI AliasProperty SI = SessionId
VM AliasProperty VM = VirtualMemorySize64
WS AliasProperty WS = WorkingSet64
Disposed Event System.EventHandler Disposed(System.Object, System.EventArgs)
ErrorDataReceived Event System.Diagnostics.DataReceivedEventHandler ErrorDataReceived(System.Object, System.Diagnostics.DataReceivedEventArgs)
...