diff --git a/knife/tools.lua b/knife/tools.lua new file mode 100644 index 0000000..90f1617 --- /dev/null +++ b/knife/tools.lua @@ -0,0 +1,15 @@ +-- returns the PID and memory peak of lua process itself +local process_information = function () + local result = { memory_peak = 0, PID = nil} + for lines in io.lines ('/proc/self/status') do + if (lines:find ("Pid:") == 1) then + result["PID"] = lines:match ("%d+") + end + if (lines:find ("VmPeak:") == 1) then + result["memory_peak"] = lines:match ("%d+") + end + end + return result +end + +return { process_information = process_information } diff --git a/knife/tools.py b/knife/tools.py new file mode 100644 index 0000000..27ec69c --- /dev/null +++ b/knife/tools.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Nov 24 12:09:33 2016 + +@author: markus +""" + +# returns the PID and memory peak of python process itself +def process_information (): + result = {'memory_peak': 0, 'PID': None} + fh = open('/proc/self/status') + for line in fh: + if (line.find ("VmPeak:") == 0): + result["memory_peak"] = float (line.split (":")[1].strip ().split (" ")[0]) + if (line.find ("Pid:") == 0): + result["PID"] = int (line.split (":")[1].strip ()) + fh.close () + return result + \ No newline at end of file