SystemResources.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // ======================================================================
  2. // \title SystemResources.hpp
  3. // \author mstarch
  4. // \brief hpp file for SystemResources component implementation class
  5. //
  6. // \copyright
  7. // Copyright 2021, by the California Institute of Technology.
  8. // ALL RIGHTS RESERVED. United States Government Sponsorship
  9. // acknowledged.
  10. //
  11. // ======================================================================
  12. #ifndef _SystemResources_hpp_
  13. #define _SystemResources_hpp_
  14. #include <FpConfig.hpp>
  15. namespace Os {
  16. namespace SystemResources {
  17. enum SystemResourcesStatus {
  18. SYSTEM_RESOURCES_OK, //!< Call was successful
  19. SYSTEM_RESOURCES_ERROR, //!< Call failed
  20. };
  21. struct CpuTicks {
  22. FwSizeType used; //!< Filled with non-idle (system, user) CPU ticks
  23. FwSizeType total; //!< Filled with total CPU ticks
  24. };
  25. struct MemUtil {
  26. FwSizeType used; //!< Filled with used bytes of volatile memory (permanent, paged-in)
  27. FwSizeType total; //!< Filled with total non-volatile memory
  28. };
  29. /**
  30. * \brief Request the count of the CPUs detected by the system
  31. *
  32. * \param cpu_count: (output) filled with CPU count on system
  33. * \return: SYSTEM_RESOURCES_OK with valid CPU count, SYSTEM_RESOURCES_ERROR when error occurs
  34. */
  35. SystemResourcesStatus getCpuCount(U32& cpu_count);
  36. /**
  37. * \brief Get the CPU tick information for a given CPU
  38. *
  39. * CPU ticks represent a small time slice of processor time. This will retrieve the used CPU ticks and total
  40. * ticks for a given CPU. This information in a running accumulation and thus a sample-to-sample
  41. * differencing is needed to see the 'realtime' changing load. This shall be done by the caller.
  42. *
  43. * \param ticks: (output) filled with the tick information for the given CPU
  44. * \param cpu_index: index for CPU to read
  45. * \return: SYSTEM_RESOURCES_ERROR when error occurs, SYSTEM_RESOURCES_OK otherwise.
  46. */
  47. SystemResourcesStatus getCpuTicks(CpuTicks& ticks, U32 cpu_index = 0);
  48. /**
  49. * \brief Get system memory usage
  50. *
  51. * \param memory_util: (output) data structure used to store memory usage
  52. * \return: SYSTEM_RESOURCES_ERROR when error occurs, SYSTEM_RESOURCES_OK otherwise.
  53. */
  54. SystemResourcesStatus getMemUtil(MemUtil& memory_util);
  55. } // namespace SystemResources
  56. } // namespace Os
  57. #endif