Re: [Haskell-cafe] Diagnose stack space overflow

2011-07-08 Thread Ketil Malde
Max Bolingbroke batterseapo...@hotmail.com writes:

 Stack space overflow: current size 8388608 bytes.
 Use `+RTS -Ksize -RTS' to increase it.

 I want to find out the culprit function and rewrite it tail-recursively. Is
 there a way to find out which function is causing this error other
 than reviewing the code manually?

 It's possible that building your program with profiling and then
 running with +RTS -xc will print a useful call stack.

Does this help, really?  I've tried that occasionally, but can't really
say it's ever helped pinpoint the problem.  (Not complaining, stack
traces are hard in Haskell.)

I generally heap-profile (often with the -hd option), most stack
overflows will also retain heap data (i.e. a stack of (+) operations
will point to all the numbers as well), which should give you an idea of
where to look.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Diagnose stack space overflow

2011-07-08 Thread Ketil Malde
John Lato jwl...@gmail.com writes:

 I want to find out the culprit function and rewrite it tail-recursively. Is
 there a way to find out which function is causing this error other
 than reviewing the code manually?

 I'd like to point out that a stack-space overflow in Haskell isn't quite the
 same thing as in other functional languages.  In particular, it's possible
 for tail-recursive functions to overflow the stack because of laziness.

..in fact, you often want to *avoid* tail recursion (e.g. as implemented in
foldl) and use something that is not tail recursive (e.g. foldr) but
more laziness-friendly.  Or use strictness (foldl').

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: [Haskell-cafe] Diagnose stack space overflow

2011-07-08 Thread Daniel Fischer
On Friday 08 July 2011, 11:29:40, Ketil Malde wrote:
 Max Bolingbroke batterseapo...@hotmail.com writes:
  Stack space overflow: current size 8388608 bytes.
  Use `+RTS -Ksize -RTS' to increase it.
  
  I want to find out the culprit function and rewrite it
  tail-recursively. Is there a way to find out which function is
  causing this error other than reviewing the code manually?
  
  It's possible that building your program with profiling and then
  running with +RTS -xc will print a useful call stack.
 
 Does this help, really?  I've tried that occasionally, but can't really
 say it's ever helped pinpoint the problem.  (Not complaining, stack
 traces are hard in Haskell.)

It can help. I recently had a stack overflow in some code with ghc-7 (which 
worked fine in ghc-6) which was a pain to locate.
I had forgotten about the -xc way and when (after the fact) I read Max' 
post, I reverted the fix and tried that.
And, hey presto, the printed call stack, although not incredibly 
informative, revealed the function in which the overflow occurred.
It would have been faster to pinpoint with -xc.

 
 I generally heap-profile (often with the -hd option), most stack
 overflows will also retain heap data (i.e. a stack of (+) operations
 will point to all the numbers as well), which should give you an idea of
 where to look.

The abovementioned didn't reveal anything in the heap profiles, apart from 
the data that should have been there (in the correct amounts), there were 
only TSOs and BLACKHOLE in the profiles, not attributed to anything 
(despite ample SCC pragmas).


I have little experience with stack overflows, so I can't tell whether heap 
profiling is generally more informative than the stack trace to find them 
or not, it's certainly reasonable to expect that often retained data will 
show you where to look, but it doesn't always do it.
One should be aware of both ways, where the first one tried doesn't help, 
the other one may.

Cheers,
Daniel

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Diagnose stack space overflow

2011-07-04 Thread Logo Logo
Hi,

For the following error:

Stack space overflow: current size 8388608 bytes.
Use `+RTS -Ksize -RTS' to increase it.

I want to find out the culprit function and rewrite it tail-recursively. Is
there a way to find out which function is causing this error other
than reviewing the code manually?

Thanks,
Loganathan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Diagnose stack space overflow

2011-07-04 Thread Don Stewart
Profile!!

E.g.

http://stackoverflow.com/questions/6429085/haskell-heap-issues-with-parameter-passing-style/6429888#6429888



On Mon, Jul 4, 2011 at 11:44 AM, Logo Logo sarasl...@gmail.com wrote:
 Hi,

 For the following error:

 Stack space overflow: current size 8388608 bytes.
 Use `+RTS -Ksize -RTS' to increase it.

 I want to find out the culprit function and rewrite it tail-recursively. Is
 there a way to find out which function is causing this error other
 than reviewing the code manually?

 Thanks,
 Loganathan
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Diagnose stack space overflow

2011-07-04 Thread Chris Smith
You can use the heap profiling options in GHC to find out what is using all
the memory.  You'll want to compile with -prof and -rtsopts, and then invoke
the program with +RTS -hx, where x is one of 'c', 'y', or a few others.
Then run hp2ps on the resulting .hp file to get a graph of what's using all
the memory.

-- 
Chris Smith
On Jul 4, 2011 9:46 AM, Logo Logo sarasl...@gmail.com wrote:
 Hi,

 For the following error:

 Stack space overflow: current size 8388608 bytes.
 Use `+RTS -Ksize -RTS' to increase it.

 I want to find out the culprit function and rewrite it tail-recursively.
Is
 there a way to find out which function is causing this error other
 than reviewing the code manually?

 Thanks,
 Loganathan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Diagnose stack space overflow

2011-07-04 Thread Max Bolingbroke
On 4 July 2011 16:44, Logo Logo sarasl...@gmail.com wrote:
 Hi,

 For the following error:

 Stack space overflow: current size 8388608 bytes.
 Use `+RTS -Ksize -RTS' to increase it.

 I want to find out the culprit function and rewrite it tail-recursively. Is
 there a way to find out which function is causing this error other
 than reviewing the code manually?

It's possible that building your program with profiling and then
running with +RTS -xc will print a useful call stack.

Cheers,
Max

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Diagnose stack space overflow

2011-07-04 Thread Roman Cheplyaka
Hi Don,

I find this answer confusing. The SO question you're linking to is about
heap size, not stack overflow.

The stack size in this example is 8M. The whole heap size may be much
bigger (and increasing the stack size may actually remove the overflow).

It would be interesting to learn about success stories of investigation
of a stack overflow using heap profiling.

* Don Stewart don...@gmail.com [2011-07-04 12:08:05-0400]
 Profile!!
 
 E.g.
 
 http://stackoverflow.com/questions/6429085/haskell-heap-issues-with-parameter-passing-style/6429888#6429888
 
 
 
 On Mon, Jul 4, 2011 at 11:44 AM, Logo Logo sarasl...@gmail.com wrote:
  Hi,
 
  For the following error:
 
  Stack space overflow: current size 8388608 bytes.
  Use `+RTS -Ksize -RTS' to increase it.
 
  I want to find out the culprit function and rewrite it tail-recursively. Is
  there a way to find out which function is causing this error other
  than reviewing the code manually?

-- 
Roman I. Cheplyaka :: http://ro-che.info/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Diagnose stack space overflow

2011-07-04 Thread John Lato
 From: Logo Logo sarasl...@gmail.com

 Hi,

 For the following error:

 Stack space overflow: current size 8388608 bytes.
 Use `+RTS -Ksize -RTS' to increase it.

 I want to find out the culprit function and rewrite it tail-recursively. Is
 there a way to find out which function is causing this error other
 than reviewing the code manually?


I'd like to point out that a stack-space overflow in Haskell isn't quite the
same thing as in other functional languages.  In particular, it's possible
for tail-recursive functions to overflow the stack because of laziness.

Consider this tail-recursive sum function:

 trSum :: [Int] - Int
 trSum l = go 0 l
  where
   go acc [] = acc
   go acc (x:xs) = go (acc+x) xs

It's tail-recursive.  But if you enter this in ghci and run it, you'll find
that it uses increasing stack space, and will likely cause a stack overflow
for large enough inputs.  The problem is that the accumulator 'acc' isn't
strict and builds up a thunk of the form:

0+n1+n2+...+nn

The solution is to add strictness.  For this example, a '!' on the
accumulator will do.  GHC will sometimes spot cases where extra strictness
is helpful (it'll figure this one out when compiled with -O), but it often
needs help.

I'd recommend Edward Yang's series of blog posts about debugging, space
leaks, and the Haskell heap.  One useful article is
http://blog.ezyang.com/2011/05/anatomy-of-a-thunk-leak/ , but you may want
to start at the beginning of the heap series.

John L.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe