sg_get_page_stats(3)

πŸ“¦
version 0.92.1 Β· 2 versions
, in alpine 3.24, arch rolling, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0

πŸ’– sg_get_page_stats(3) πŸ’–

okay so bestie, you opened the 3 manual page for sg_get_page_stats, and it's from that libstatgrab life. this whole page is about paging statistics and honestly? it's giving "small but mighty." let's get into it 🫢


✨ NAME ✨

sg_get_page_stats, sg_get_page_stats_r, sg_get_page_stats_diff, sg_get_page_stats_diff_between, sg_free_page_stats β€” get paging statistics. that's the whole vibe. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <statgrab.h>

sg_page_stats *sg_get_page_stats (size_t *entries);

sg_page_stats *sg_get_page_stats_r (size_t *entries);

sg_page_stats *sg_get_page_stats_diff (size_t *entries);

sg_page_stats *sg_get_page_stats_diff_between (const sg_page_stats *cur,
                const sg_page_stats *last, size_t *entries);

sg_error sg_free_page_stats (sg_page_stats *data);

like, look at all those functions. one big happy paging family. 🌸


πŸŽ€ DESCRIPTION πŸŽ€

so the page stats module? it delivers the number of pages swapped in and out. that's it, that's the job. ✨

and it does it in two whole flavors:

  • either since the machine has been booted β€” that's sg_get_page_stats() and sg_get_page_stats_r() doing their thing
  • or the difference between two measured statistics β€” that's sg_get_page_stats_diff() and sg_get_page_stats_diff_between() stepping in πŸ”₯

now, sg_get_page_stats_diff() is lowkey the interesting one. it calculates the difference between the last call to sg_get_page_stats() in this thread. and like, how? the statistics of the earlier call get saved, and sg_get_page_stats() is called immediately after that. it's doing the math for you, bestie. πŸ’€

πŸ’« API Shortcut πŸ’«

no table energy today, so here's the same tea in list form β€” function, what it returns, and who owns the data:

  • sg_get_page_stats β†’ returns sg_page_stats * β†’ data owner is libstatgrab (thread local)
  • sg_get_page_stats_r β†’ returns sg_page_stats * β†’ data owner is the caller
  • sg_get_page_stats_diff β†’ returns sg_page_stats * β†’ data owner is libstatgrab (thread local)
  • sg_get_page_stats_diff_between β†’ returns sg_page_stats * β†’ data owner is the caller

and this part matters, okay? 🚨 the sg_page_stats buffer you get from sg_get_page_stats_r() and from sg_get_page_stats_diff_between() must be freed using sg_free_page_stats() when you don't need it any more. the caller is responsible for doing it. that's you. you're the caller. don't forget. πŸ™ˆ


πŸ‘‘ RETURN VALUES πŸ‘‘

here's the struct, iconic as ever:

typedef struct{
        unsigned long long pages_pagein;
        unsigned long long pages_pageout;
        time_t systime;
}sg_page_stats;

and the fields, one by one:

  • pages_pagein β€” the number of pages swapped into memory.
  • pages_pageout β€” the number of pages swapped out of memory (to swap).
  • systime β€” the timestamp when the above stats were collected, in seconds since epoch. or, the time period over which pages_pagein and pages_pageout were transferred. two moods, same field. πŸ¦‹

πŸ’€ BUGS πŸ’€

Solaris doesn't seem to report accurately. it reports the number of pages swapped into memory, not necessarily from swap. this feature isn't deemed entirely reliable.

so yeah. on Solaris, take those numbers with a grain of salt. maybe two grains. 😭


🌈 SEE ALSO 🌈

  • statgrab(3) β€” go read it, bestie, iykyk πŸ’œ

🌸 WEBSITE 🌸

⟨https://libstatgrab.org/⟩ β€” the mothership. go say hi. ⭐


and that's the page!! brought to you by libstatgrab, dated 2019-03-08, manual section 3, sg_get_page_stats(3) β€” mwah, slay, periodt πŸ’…πŸ’–