Performance counters

OK, so I'm pretty sure I'm not the first person to run into this... I've got a fairly large, complex program. It seems to work fine. But now I want to add some counters to measure various things. Trouble is, to do that, I'd have to "infect" the entire program with boilerplate code to propogate these counters. At best I could wrap it up in a monad, but it's still annoying to have to make 90% of the code in the program monadic just to carry these performance counters around. Does anybody know of a better solution? I could use the dreaded unsafePerformIO to prod some IORefs, but now you have to start sprinkling NOINLINE pragmas around and hope you know what you're doing... Scary! o_O

andrewcoppin:
OK, so I'm pretty sure I'm not the first person to run into this...
I've got a fairly large, complex program. It seems to work fine. But now I want to add some counters to measure various things.
Trouble is, to do that, I'd have to "infect" the entire program with boilerplate code to propogate these counters. At best I could wrap it up in a monad, but it's still annoying to have to make 90% of the code in the program monadic just to carry these performance counters around.
Does anybody know of a better solution? I could use the dreaded unsafePerformIO to prod some IORefs, but now you have to start sprinkling NOINLINE pragmas around and hope you know what you're doing... Scary! o_O
What kind of counters? Do you just want to measure how often things are evaluated? Use -fhpc (which inserts 'ticks' for you). Otherwise, you'll need some kind of manual tick system. -- Don

Don Stewart wrote:
andrewcoppin:
OK, so I'm pretty sure I'm not the first person to run into this...
I've got a fairly large, complex program. It seems to work fine. But now I want to add some counters to measure various things.
Trouble is, to do that, I'd have to "infect" the entire program with boilerplate code to propogate these counters. At best I could wrap it up in a monad, but it's still annoying to have to make 90% of the code in the program monadic just to carry these performance counters around.
Does anybody know of a better solution? I could use the dreaded unsafePerformIO to prod some IORefs, but now you have to start sprinkling NOINLINE pragmas around and hope you know what you're doing... Scary! o_O
What kind of counters? Do you just want to measure how often things are evaluated? Use -fhpc (which inserts 'ticks' for you).
Otherwise, you'll need some kind of manual tick system.
Stuff like "how many times does this function get called? How what's the maximum depth it recurses to?" That kind of thing.

Andrew Coppin wrote:
Don Stewart wrote:
andrewcoppin:
OK, so I'm pretty sure I'm not the first person to run into this...
I've got a fairly large, complex program. It seems to work fine. But now I want to add some counters to measure various things.
Trouble is, to do that, I'd have to "infect" the entire program with boilerplate code to propogate these counters. At best I could wrap it up in a monad, but it's still annoying to have to make 90% of the code in the program monadic just to carry these performance counters around.
Does anybody know of a better solution? I could use the dreaded unsafePerformIO to prod some IORefs, but now you have to start sprinkling NOINLINE pragmas around and hope you know what you're doing... Scary! o_O
What kind of counters? Do you just want to measure how often things are evaluated? Use -fhpc (which inserts 'ticks' for you).
Otherwise, you'll need some kind of manual tick system.
Stuff like "how many times does this function get called? How what's the maximum depth it recurses to?" That kind of thing.
It won't help you, but wouldn't it be the kind of thing that'd fit in the GHC runtime? Do you also require that the counters are available to the program itself? (This is starting to sound like something Don mentioned in his talk in London...) /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe

Magnus Therning wrote:
Andrew Coppin wrote:
Stuff like "how many times does this function get called? How what's the maximum depth it recurses to?" That kind of thing.
It won't help you, but wouldn't it be the kind of thing that'd fit in the GHC runtime?
Do you also require that the counters are available to the program itself?
(This is starting to sound like something Don mentioned in his talk in London...)
[I'm getting *really* tired of my ISP thinking that 30% of the traffic from Haskell-cafe is spam. If only there was a way to whitelist it or something... repeatedly clicking "this is not spam" doesn't seem to get the message across.] Um... hmm, that's a good question. Basically I've written a program that does adaptive sampling, and I want to see how much it's recursing. There are two parameters you can adjust: the minimum step size, and the maximum error tollerance. I'd like to know which of the two limits the program is reaching. (In other words, does the error eventually fall below the threshold, or does the step size become too small first?) I guess *ideally* I'd like the end user to be able to find this out from the running program... but I guess to do that there really is no other way than to sprinkle monads or unsafe I/O around the place.

2009/5/5 Andrew Coppin
Magnus Therning wrote:
Andrew Coppin wrote:
Stuff like "how many times does this function get called? How what's the maximum depth it recurses to?" That kind of thing.
It won't help you, but wouldn't it be the kind of thing that'd fit in the GHC runtime?
Do you also require that the counters are available to the program itself?
(This is starting to sound like something Don mentioned in his talk in London...)
[I'm getting *really* tired of my ISP thinking that 30% of the traffic from Haskell-cafe is spam. If only there was a way to whitelist it or something... repeatedly clicking "this is not spam" doesn't seem to get the message across.]
Um... hmm, that's a good question. Basically I've written a program that does adaptive sampling, and I want to see how much it's recursing. There are two parameters you can adjust: the minimum step size, and the maximum error tollerance. I'd like to know which of the two limits the program is reaching. (In other words, does the error eventually fall below the threshold, or does the step size become too small first?)
I guess *ideally* I'd like the end user to be able to find this out from the running program... but I guess to do that there really is no other way than to sprinkle monads or unsafe I/O around the place.
Hi, Since your recursive function has to test if the recursion should be ended or continued, when it ends, you know the reason. So why not just wrap your result inside something like: data Result a = ThresholdReached a | StepSizeTooSmall a ? Also, passing an accumulator to the function to record the number of steps should be straightforward. Cheers, Thu

While not entirely handy, do the .prof files not contain enough
information on entries into a function?
[tom@Mavlo Test]$ grep addLeaf PingNet.prof
addLeaf Network.Pastry.Data.LeafSet
822 1 0.0 0.0 0.0 0.0
addLeaf Network.Pastry.Data.LeafSet
687 243 0.0 0.0 0.1 0.1
addLeaf Network.Pastry.Data.LeafSet
734 619933 0.1 0.0 60.5 94.6
addLeaf Network.Pastry.Data.LeafSet
609 4013 0.0 0.0 0.5 0.6
addLeaf Network.Pastry.Data.LeafSet
644 3600 0.0 0.0 0.3 0.6
addLeaf Network.Pastry.Data.LeafSet
784 2666 0.0 0.0 0.3 0.4
addLeaf Network.Pastry.Data.LeafSet
566 6 0.0 0.0 0.0 0.0
addLeaf Network.Pastry.Data.LeafSet
569 0 0.0 0.0 0.0 0.0
In this manner I know addLeaf was entered 72000+ times. Though it
won't give you any information about recursion depth (which is often
optimized out so you see fewer entries than there are logical calls to
the function). I'm not proposing people want to do this manually, but
asking if pulling the information out of the .prof files with some
tool would give much of the information you desire?
Or perhaps you desire this information within the program like Magnus mentioned.
Thomas
On Mon, May 4, 2009 at 1:35 PM, Andrew Coppin
Don Stewart wrote:
andrewcoppin:
OK, so I'm pretty sure I'm not the first person to run into this...
I've got a fairly large, complex program. It seems to work fine. But now I want to add some counters to measure various things.
Trouble is, to do that, I'd have to "infect" the entire program with boilerplate code to propogate these counters. At best I could wrap it up in a monad, but it's still annoying to have to make 90% of the code in the program monadic just to carry these performance counters around.
Does anybody know of a better solution? I could use the dreaded unsafePerformIO to prod some IORefs, but now you have to start sprinkling NOINLINE pragmas around and hope you know what you're doing... Scary! o_O
What kind of counters? Do you just want to measure how often things are evaluated? Use -fhpc (which inserts 'ticks' for you).
Otherwise, you'll need some kind of manual tick system.
Stuff like "how many times does this function get called? How what's the maximum depth it recurses to?" That kind of thing.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Andrew Coppin
-
Don Stewart
-
Magnus Therning
-
minh thu
-
Thomas DuBuisson