server: add python process stats

This commit is contained in:
Koushik Dutta
2022-02-14 12:34:43 -08:00
parent 87328ae478
commit adcd11d785
3 changed files with 25 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ import shutil
import gc
import threading
import gi
import resource
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GLib
@@ -316,6 +317,23 @@ async def async_main(loop: AbstractEventLoop):
peer.params['getRemote'] = lambda api, pluginId: PluginRemote(
api, pluginId, loop)
def oob_runner():
ptime = round(time.process_time() * 1000000)
heapTotal = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
oob = {
'type': 'stats',
'cpuUsage': {
'user': ptime,
'system': 0,
},
'memoryUsage': {
'heapTotal': heapTotal,
},
}
peer.sendOob(oob)
loop.call_later(10, oob_runner)
oob_runner()
await readLoop(loop, peer, reader)

View File

@@ -370,3 +370,9 @@ class RpcPeer:
}
self.send(paramMessage, reject)
return await self.createPendingResult(send)
def sendOob(self, oob: Any):
self.send({
'type': 'oob',
'oob': oob,
})