Simple CPU Usage Demo for Windows


GeeXLab - Simple CPU Usage Utility for Windows

Here is a small demo that shows the use of gh_utils.cpu_usage_xxxxxx() set of functions:
gh_utils.cpu_usage_init()
gh_utils.cpu_usage_get_core_count()
gh_utils.cpu_usage_update()
gh_utils.cpu_usage_get_core_usage()
gh_utils.cpu_usage_cleanup()

These functions work only on Windows and are available in Lua and Python. Here is how to use them in the different types of scripts to get the overall CPU usage:

INIT script (Lua):

cpu_usage_initialized = gh_utils.cpu_usage_init()
overall_cpu_usage = 0

TERMINATE script (Lua):

gh_utils.cpu_usage_cleanup()

FRAME script (Lua):

if (cpu_usage_initialized == 1) then
  gh_utils.cpu_usage_update()
  cpu_num_cores = gh_utils.cpu_usage_get_core_count()
  overall_cpu_usage = 0
  for i=0, cpu_num_cores-1 do
    usage = gh_utils.cpu_usage_get_core_usage(i)
    overall_cpu_usage = overall_cpu_usage + usage
  end
  overall_cpu_usage = overall_cpu_usage / cpu_num_cores
end

The demo displays the overall CPU usage as well as the usage of each CPU core. The CPU usage is updated every second. The demo is available in the full code sample pack in the gl-32/cpu_usage_win32_64/ folder. Launch GeeXLab 0.17+ and drag/drop the demo into GeeXLab.

The demo shows also how to use ImGui functions to display the CPU usage graph (histogram). ImGui is really cool…


GeeXLab - Simple CPU Usage Utility for Windows

Leave a Comment

Your email address will not be published. Required fields are marked *