proc_meminfo.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #include "proc.h"
  10. #include "procfs.h"
  11. #include <rthw.h>
  12. #include <rtdbg.h>
  13. #include <fcntl.h>
  14. #include <errno.h>
  15. #include <dfs_dentry.h>
  16. #include <mm_page.h>
  17. extern void rt_memory_info(rt_size_t *total,
  18. rt_size_t *used,
  19. rt_size_t *max_used);
  20. static int single_show(struct dfs_seq_file *seq, void *data)
  21. {
  22. rt_size_t total, used, max_used, freed;
  23. rt_size_t total_sum = 0;
  24. rt_size_t total_freed = 0;
  25. rt_memory_info(&total, &used, &max_used);
  26. total_sum = total_sum + total;
  27. total_freed = total_freed + total - used;
  28. dfs_seq_printf(seq, "%-16s%8d KB\n", "MemMaxUsed:", max_used / 1024);
  29. dfs_seq_printf(seq, "%-16s%8d KB\n", "MemAvailable:", (total - used) / 1024);
  30. dfs_seq_printf(seq, "%-16s%8d KB\n", "Cached:", 0);
  31. dfs_seq_printf(seq, "%-16s%8d KB\n", "SReclaimable:", 0);
  32. rt_page_get_info(&total, &freed);
  33. total_sum = total_sum + total * RT_MM_PAGE_SIZE;
  34. total_freed = total_freed + freed * RT_MM_PAGE_SIZE;
  35. dfs_seq_printf(seq, "%-16s%8d KB\n", "MemTotal:", total_sum / 1024);
  36. dfs_seq_printf(seq, "%-16s%8d KB\n", "MemFree:", total_freed / 1024);
  37. dfs_seq_printf(seq, "%-16s%8d KB\n", "LowPageTotal:", total * RT_MM_PAGE_SIZE / 1024);
  38. dfs_seq_printf(seq, "%-16s%8d KB\n", "lowPageFree:", freed * RT_MM_PAGE_SIZE/ 1024);
  39. rt_page_high_get_info(&total, &freed);
  40. dfs_seq_printf(seq, "%-16s%8d KB\n", "HighPageTotal:", total * RT_MM_PAGE_SIZE / 1024);
  41. dfs_seq_printf(seq, "%-16s%8d KB\n", "HighPageFree:", freed * RT_MM_PAGE_SIZE / 1024);
  42. return 0;
  43. }
  44. int proc_meminfo_init(void)
  45. {
  46. struct proc_dentry *dentry = proc_create_single_data("meminfo", 0, NULL, single_show, NULL);
  47. proc_release(dentry);
  48. return 0;
  49. }
  50. INIT_ENV_EXPORT(proc_meminfo_init);