Skip to content

Instantly share code, notes, and snippets.

@laoar
Last active December 9, 2019 10:33
Show Gist options
  • Save laoar/210cad74b4f42f9c5f9c4666e0b83fe7 to your computer and use it in GitHub Desktop.
Save laoar/210cad74b4f42f9c5f9c4666e0b83fe7 to your computer and use it in GitHub Desktop.
trace: trace to help anayze issue
# usage : stap -g get_memcg_count.stp
# I only verified it on CentOS 7 (kernel-3.10) @yafang
# With it we can calculate how many offline memcgs.
# This script gets all memcgs, and /proc/cgroup gets online memcgs.
#
# all memcgs = online memcgs + offline memcgs
%{
#include <linux/rcupdate.h>
#include <linux/cgroup.h>
#include <linux/memcontrol.h>
/* The embedded c function must have a return value.
* If it doesn't has an argument, we must use a specified void.
*/
int get_memcg_count(void)
{
struct cgroup_subsys_state *tmp;
int count = 1;
int i;
rcu_read_lock();
/* CSS_ID_MAX is 65535, 0 is unused */
for (i = 1; i < 65536; i++) {
tmp = css_lookup(&mem_cgroup_subsys, i);
if (tmp)
count++;
}
rcu_read_unlock();
return count;
}
%}
function do_calc:long()
%{
int count = 0;
count = get_memcg_count();
STAP_RETVALUE = count;
%}
probe begin {
printf("probe begin\n");
printf("count %ld\n", do_calc());
}
probe end {
printf("probe end\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment