Solved problem with RAM calculations

This commit is contained in:
Eduardo Cueto Mendoza 2020-07-28 16:07:21 -06:00
parent a3c3a69f0e
commit 46aef70cb1
1 changed files with 17 additions and 9 deletions

View File

@ -76,20 +76,26 @@ end
rampowerdraw()::Float64 rampowerdraw()::Float64
[Approximate RAM Power Draw](https://www.jedec.org/) the values are provided by the JEDEC we just take the [Approximate RAM Power Draw](https://www.jedec.org/) the values are provided by the JEDEC we just take the
ratio of activated memory against the unactivated for the maximum power value and convert it average of the total RAM with its Watt value to get the approximate power draw.
to hours.
""" """
function rampowerdraw() function rampowerdraw(ramtype="DDR3")
ramcommand = `free` ramcommand = `free -m`
powerused = Array{Float64}(undef,60) powerused = Array{Float64}(undef,60)
for count in 1:60 for count in 1:60
ram = read(ramcommand, String); ram = read(ramcommand, String);
ram = split(ram,"\n") ram = split(ram,"\n")
ram = split(ram[2]," ") ram = split(ram[2]," ")
filter!(x->x≠"",ram) filter!(x->x≠"",ram)
usedram = parse(Float64,ram[3])
totalram = parse(Float64,ram[2]) totalram = parse(Float64,ram[2])
powerused[count] = ((usedram*1.575)/totalram)*1.904 if ramtype == "DDR3"
powerused[count] = (totalram/1024)*0.3125
elseif ramtype == "DDR2"
powerused[count] = (totalram/1024)*0.625
elseif ramtype == "DDR"
powerused[count] = (totalram/1024)*6.5
else
error("$ramtype unrecognized RAM type.")
end
sleep(1) sleep(1)
end end
return mean(powerused) return mean(powerused)
@ -108,8 +114,10 @@ the number of available gpus.
`apd = 1.58*t*(pc + pr + g*pg)/1000` `apd = 1.58*t*(pc + pr + g*pg)/1000`
returns the average power consumption in kWh. returns the average power consumption in kWh.
By default it assumes you use `"DDR3"` memory but you can pass `"DDR2"` or `"DDR"` to get a better estimate.
""" """
function avgpowerdraw() function avgpowerdraw(freeram="DDR3")
g, pg, pc, pr = 0.0, 0.0, 0.0, 0.0 g, pg, pc, pr = 0.0, 0.0, 0.0, 0.0
starttime = time() starttime = time()
try try
@ -125,12 +133,12 @@ function avgpowerdraw()
return 0.0 return 0.0
end end
try try
pr = rampowerdraw() pr = rampowerdraw(freeram)
catch ex catch ex
println(ex.msg) println(ex.msg)
return 0.0 return 0.0
end end
endtime = time() endtime = time()
elapsedtime = (endtime - starttime)/3600 elapsedtime = (endtime - starttime)*0.0002777778
return 1.58*elapsedtime*(pc + pr + g*pg)/1000 return 1.58*elapsedtime*(pc + pr + g*pg)/1000
end end