2017-03-04 4 views
3

Gibt es eine nette Möglichkeit, die aktuellen Systeminformationen in Julia zu bekommen (mein Anwendungsfall hier ist Speicher, aber auch interessiert an im Grunde alles Informationen, die ich von top auf Linux ausführen konnte).Erhalte Systemspeicher Informationen von Julia

Dies ist, was ich im Moment habe: (im Grunde immer nur die Ausgabe von `frei -m`) < - Das kann ich nicht bekommen, um mich und Backticks markieren halten entgehen lassen Code ...

import Base.DataFmt: readdlm_string, invalid_dlm 

""" 
    getmeminfo() 
Returns (in MB) A tuple of containing: 
    - Memory(total, used, buffer, available) 
    - Swap(total, used, free) 
""" 
function getmeminfo() 
    memstats = readdlm_string(readstring(`free -m`),invalid_dlm(Char), Int, '\n', true, Dict()) 
    return Tuple{Array{Int,1},Array{Int,1}}((memstats[2,[2;3;6;7]], memstats[3,[2;3;4]])) 
end 

Gibt es etwas in Base oder bessere Ideen?

+1

Auf Linux (vielleicht Mac) kannst du auch 'cat/proc/meminfo' anschauen (' free' ist auch Unix-spezifisch) –

+0

ahh yeah, 'readdlm ("/proc/meminfo ")' ist viel prägnanter. .. –

Antwort

8

Das integrierte Modul Sys enthält Funktionen zum Abrufen von Systeminformationen.

julia> Sys.total_memory()/2^20 
15988.84765625 

julia> Sys.free_memory()/2^20 
331.609375 

julia> Sys.cpu_name 
"haswell" 

julia> Sys. 
ARCH    SC_CLK_TCK   cpu_info   loadavg 
CPU_CORES   UV_cpu_info_t  cpu_name   maxrss 
CPUinfo   WINDOWS_VISTA_VER cpu_summary  set_process_title 
JIT    WORD_SIZE   eval    total_memory 
KERNEL   __init__   free_memory  uptime 
MACHINE   _cpu_summary  get_process_title windows_version 

Es ist zwar nicht alle Informationen von top sofern nicht unterstützt, es wird hoffentlich die Informationen, die Sie für suchen.

+0

dachte, da müsste sowas sein! –

Verwandte Themen