This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: Proposed systemtap access to perfmon hardware
To try to get a feel on how the performance monitoring hardware support
would work in SystemTap I wrote some simple examples. Below are examples
for computing IPC, average cycle count, and sampling within a function.
The IPC and average cycle count function need a bit of rework to work
for a SMP machines.
Let me know if there are comments or questions on the examples.
-Will
COMPUTING IPC
global cycles_h
global instr_retired_h
probe perfmon.event("cycles") {cycles_h = $handle;}
probe perfmon.event("intr_retired") {instr_retired_h = $handle;}
probe begin {print ("start probe");}
probe end
{
factor=100;
ipc = (factor*perfmon_get_counter(intr_retired_h))/
perfmon_get_counter(cycles_h);
print ("ipc is %d.%d \n", ipc/factor, ipc % factor);
}
DETERMINING AVERAGE CYCLE COUNT FOR FUNCTION (AND CHILDREN)
global cycles_h
probe perfmon.event("cycles") {
cycles_h = $handle;
perfmon_stop_counter(cycles_h);
}
global count
probe kernel.function("blah"){
++count;
perfmon_start_counter(cycles_h);
}
probe kernel.function.return("blah"){
perfmon_stop_counter(cycles_h);
}
probe begin {print ("start probe");}
probe end
{
total_cycles=perfmon_stop_counter(cycles_h);
print ("average count in blah %d\n", total_cycles/count);
}
SAMPLING WITHIN A FUNCTION (AND CHILDREN)
global cycles_h
global where_am_i
probe perfmon.event("cycles").sample(100000) {
cycles_h = $handle;
# record where sample occured
where_am_i[instruction_pointer()]++;
}
global count
probe kernel.function("blah"){
++count;
perfmon_start_counter(cycles_h);
}
probe kernel.function("blah").return{
perfmon_stop_counter(cycles_h);
}
probe begin
{
# turn off the sampling
perfmon_stop_counter(cycles_h);
print("start probe");
}
probe end
{
#write out the where_am_i entries
print("address\tcount\n");
foreach ([+ip] in where_am_i) {
print("0x%x\t%d\n", ip, where_am_i[ip]);
}
}