Browse Source

add knife tools

master
Markus Bergholz 2 years ago
parent
commit
3e15af20ca
2 changed files with 34 additions and 0 deletions
  1. 15
    0
      knife/tools.lua
  2. 19
    0
      knife/tools.py

+ 15
- 0
knife/tools.lua View File

@@ -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 }

+ 19
- 0
knife/tools.py View File

@@ -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

Loading…
Cancel
Save