{"id":21337264,"url":"https://github.com/freeslave/resusage","last_synced_at":"2026-01-02T14:47:00.693Z","repository":{"id":33383855,"uuid":"37028825","full_name":"FreeSlave/resusage","owner":"FreeSlave","description":"D library for getting system and process resource usage","archived":false,"fork":false,"pushed_at":"2023-09-15T22:16:40.000Z","size":258,"stargazers_count":16,"open_issues_count":4,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-22T14:45:44.036Z","etag":null,"topics":["cpu","d","dlang","ram"],"latest_commit_sha":null,"homepage":"","language":"D","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FreeSlave.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_1_0.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-07T19:17:48.000Z","updated_at":"2024-01-09T06:33:51.000Z","dependencies_parsed_at":"2024-11-22T00:10:53.060Z","dependency_job_id":null,"html_url":"https://github.com/FreeSlave/resusage","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fresusage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fresusage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fresusage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fresusage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FreeSlave","download_url":"https://codeload.github.com/FreeSlave/resusage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814893,"owners_count":20352038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpu","d","dlang","ram"],"created_at":"2024-11-22T00:00:39.341Z","updated_at":"2026-01-02T14:47:00.666Z","avatar_url":"https://github.com/FreeSlave.png","language":"D","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Resusage\n\nObtaining of virtual memory, RAM and CPU usage by the whole system or by single process.\n\n[![Build Status](https://github.com/FreeSlave/resusage/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/FreeSlave/resusage/actions/workflows/ci.yml)\n[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/FreeSlave/resusage?branch=master\u0026svg=true)](https://ci.appveyor.com/project/FreeSlave/resusage)\n\nCurrently works on Linux and Windows.\n\nFreeBSD support is partial - only system-wide memory information and per-process CPU usage can be retrieved now.\n\n## Generating documentation\n\nDdoc:\n\n    dub build --build=docs\n\nDdox:\n\n    dub build --build=ddox\n\n## Brief\n\n```d\n// import module\nimport resusage.memory;\n\n// or the whole package\nimport resusage;\n\n// get system memory usage\nSystemMemInfo sysMemInfo = systemMemInfo(); \n\n// access properties\nsysMemInfo.totalRAM;\nsysMemInfo.usedRAM;\nsysMemInfo.freeRAM;\n\nsysMemInfo.totalVirtMem;\nsysMemInfo.usedVirtMem;\nsysMemInfo.freeVirtMem;\n\n// actualize values after some amount of time\nsysMemInfo.update();\n\n// get memory usage of the current process\nProcessMemInfo procMemInfo = processMemInfo();\n\n// or pass process ID to get info about specific process\nint pid = ...;\nProcessMemInfo procMemInfo = processMemInfo(pid);\n\n// access properties\nprocMemInfo.usedVirtMem;\nprocMemInfo.usedRAM;\n\n// actualize values after some amount of time\nprocMemInfo.update();\n\n//import module\nimport resusage.cpu;\n\n// create watcher to watch system CPU\nauto cpuWatcher = new SystemCPUWatcher();\n\n// get actual value when needed\ndouble percent = cpuWatcher.current();\n\n// create CPU watcher for current process\nauto cpuWatcher = new ProcessCPUWatcher();\n\n// or for process with given id\nint pid = ...;\nauto cpuWatcher = new ProcessCPUWatcher(pid);\n\n// get actual value when needed\ndouble percent = cpuWatcher.current();\n```\n\n## Examples\n\n### [Total usage](examples/totalusage.d)\n\nPrints total amount of virtual and physical memory (in bytes) and their current usage in the system (in percents).\n\n    dub examples/totalusage.d\n\n### [Process usage](examples/processusage.d)\n\nPrints amount of virtual and physical memory currently used by process, in bytes.\n\n    dub examples/processusage.d `pidof process`\n\n### [CPU Watcher](examples/cpuwatcher.d)\n\nAll following examples show CPU time used by a system or by a process in the 0-100% range.\n\nWatch system CPU time:\n\n    dub examples/cpuwatcher.d\n\nWatch process CPU time:\n\n    dub examples/cpuwatcher.d `pidof process`\n\nSpawn process and watch for its CPU time:\n\n    dub examples/cpuwatcher.d --spawn firefox\n\nAdjust the rate of output:\n\n    dub examples/cpuwatcher.d --rate=1 --spawn firefox\n\n### [CPU self watcher](examples/cpuselfwatcher.d)\n\nConsume CPU time and report CPU usage by this process:\n\n    dub examples/cpuselfwatcher --threads=2\n\nE.g. if you have 4 cores and run this example with 2 threads it will report 50% CPU time.\n\n## Platform notes and implementation details\n\n### Windows\n\nIn order to provide some functionality **resusage** dynamically loads the following libraries at startup:\n \n1. [Psapi.dll](https://docs.microsoft.com/en-us/windows/win32/psapi/psapi-reference) for [GetProcessMemoryInfo](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683219(v=vs.85).aspx).\n2. [Pdh.dll](https://msdn.microsoft.com/en-us/library/windows/desktop/aa373083(v=vs.85).aspx) to calculate CPU time used by system.\n\nIf Psapi.dll or Pdh.dll could not be loaded, corresponding functions will always throw *WindowsException*.\n\n### Linux\n\nUses [sysinfo](https://linux.die.net/man/2/sysinfo), [clock_gettime](https://linux.die.net/man/3/clock_gettime) and proc stats.\n\n### FreeBSD\n\nUses [sysctl](https://www.freebsd.org/cgi/man.cgi?query=sysctl\u0026apropos=0\u0026sektion=3\u0026arch=default\u0026format=html) to get RAM and \n[libkvm](https://www.freebsd.org/cgi/man.cgi?query=kvm_open\u0026apropos=0\u0026sektion=3\u0026arch=default\u0026format=html) to get swap memory to calculate virtual memory.\nUses clock_gettime to evaluate CPU usage.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeslave%2Fresusage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreeslave%2Fresusage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeslave%2Fresusage/lists"}