#! /usr/local/bin/stap -g -p4 # simple script to test out the per runtime libraries %{ #include "perf.c" static struct perf_event_attr cycles_attr = { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CPU_CYCLES, {.sample_period = 5000000} }; static Perf *ppp; static atomic_t s_count[NR_CPUS]; /* silly routine to count off the interrupts */ static void sample_event_handler(struct perf_event *e, int nmi, struct perf_sample_data *data, struct pt_regs *regs) { int p = smp_processor_id(); atomic_inc(&(s_count[p])); } %} function perf_start:long () %{ ppp = _stp_perf_init (&cycles_attr, sample_event_handler, NULL, NULL); %} function ppp_value:long () %{ THIS->__retvalue = (int64_t) ppp; %} function perf_stop:long () %{ int cpu; stp_for_each_cpu(cpu){ printk(KERN_INFO "sample_event_handler cpu%d count %d\n", cpu, atomic_read(&(s_count[cpu]))); } /* shut down performance event sampling */ _stp_perf_del (ppp); %} probe begin { perf_start(); printf("ppp = %p\n", ppp_value()); } probe end { perf_stop() }