There appears to be something missing from that code. $func and $name have no means of being populated, and even if they were, nothing gets done with $stub after it's been created. If you change the first line to
my ($func, $name) = @_;, then I believe you can change
thing_to_profile(@args) to
profile(\&thing_to_profile, "thing_to_profile")->(@args) and the code will work as expected.