3

I try to make some DB in Haskell, and I want to find a way to check memory and CPU usage in the program.

I try to search using keywords like "haskell memory usage" or "haskell memory checking", "haskell CPU usage", ..., but there is no answer I want (Memory and CPU checking in haskell program itself).

Is there portable way to get memory and CPU usage in itself, while the program is running?

Please let me know.

2 Answers2

3

What about using SNMP for that?

SNMP is usually used to remotely monitor devices, but nothing prevents you from running a agent locally and querying it from (a thread in) your Haskell application. That way, CPU and memory usage information would be collected by a separate application (the SNMP agent) and your application would ask for it when it needs. In order to that, you could use one these Haskell packages: snmp or NetSNMP.

You'll probably be able to find a lot of useful information/tutorials/examples regarding process monitoring using SNMP in the Internet (if you are not familiar with it) and once you understood them, implementing what you need in Haskell using those packages should be straightforward. Also, I found this related question.

Community
  • 1
  • 1
0

Your first query phrase is already providing me with lots of links I would recommend to follow:

For more information in a long time application - take a look at hackage: ekg, blog ocharles: about ekg, and an article of the author of ekg.

If you want to implement something yourself, the GHC.Stats API would be a starting point

epsilonhalbe
  • 15,637
  • 5
  • 46
  • 74
  • I do __not want__ to do a __profiling__. I want to check memory usage in __program itself__, for program command. GHC.Stats is GHC specific, so it is __not portable__. Again I say, 'I try to search but i can't find what i want'. – Junyoung Clare Jang May 28 '16 at 22:47
  • Well GHC is the most mature and feature complete compiler, but you are right that GHC is but one implementation of haskell - if you want to get a readout of the current cpu/ram/disk this will be operating system specific I guess - but other than the answer I gave I have no knowledge of any libraries that would do that job – epsilonhalbe May 29 '16 at 00:44