Recent

Author Topic: How to set Heaptrc in linux  (Read 3176 times)

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: How to set Heaptrc in linux
« Reply #15 on: February 03, 2023, 08:24:25 am »
so, n-th posts further along and we finally arrive at the culprit as could have been seen from the first dump that i posted: heaptrace (or the data it relies on) is borked for x86_64-linux.

Would be interesting to see how this discussion progresses. As a wild guess: very sloooow  :D

Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Re: How to set Heaptrc in linux
« Reply #16 on: February 03, 2023, 08:31:57 am »
This should also be the case on Linux, otherwise there is a bug. (or a setup problem)
Specialize a type, not a var.

af0815

  • Hero Member
  • *****
  • Posts: 1289
Re: How to set Heaptrc in linux
« Reply #17 on: February 03, 2023, 11:32:46 am »
Now I see.

Can you set in Project options the level of optimazion to 0 = No optimazion for debugging. It looks like the callstack for heaptrace is in Linux shorter.

I work every day with heaptrace, but if i see the first lines in a leak, i know normaly where my fault is, so did not see it is shorten on Linux (got blind at work)
regards
Andreas

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: How to set Heaptrc in linux
« Reply #18 on: February 03, 2023, 11:44:07 am »
Can you set in Project options the level of optimazion to 0 = No optimazion for debugging. It looks like the callstack for heaptrace is in Linux shorter.
If you got the log from my post then you are effectively looking at the output from no optimization on whatsoever.

edit: lpi
Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
  <ProjectOptions>
    <Version Value="12"/>
    <General>
      <SessionStorage Value="InProjectDir"/>
      <Title Value="project1"/>
      <Scaled Value="True"/>
      <ResourceType Value="res"/>
      <UseXPManifest Value="True"/>
      <XPManifest>
        <DpiAware Value="True"/>
      </XPManifest>
      <Icon Value="0"/>
    </General>
    <BuildModes>
      <Item Name="Default" Default="True"/>
    </BuildModes>
    <PublishOptions>
      <Version Value="2"/>
      <UseFileFilters Value="True"/>
    </PublishOptions>
    <RunParams>
      <FormatVersion Value="2"/>
    </RunParams>
    <RequiredPackages>
      <Item>
        <PackageName Value="LCL"/>
      </Item>
    </RequiredPackages>
    <Units>
      <Unit>
        <Filename Value="project1.lpr"/>
        <IsPartOfProject Value="True"/>
      </Unit>
      <Unit>
        <Filename Value="unit1.pas"/>
        <IsPartOfProject Value="True"/>
        <ComponentName Value="Form1"/>
        <ResourceBaseClass Value="Form"/>
        <UnitName Value="Unit1"/>
      </Unit>
    </Units>
  </ProjectOptions>
  <CompilerOptions>
    <Version Value="11"/>
    <Target>
      <Filename Value="project1"/>
    </Target>
    <SearchPaths>
      <IncludeFiles Value="$(ProjOutDir)"/>
      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
    </SearchPaths>
    <CodeGeneration>
      <Optimizations>
        <OptimizationLevel Value="0"/>
      </Optimizations>
    </CodeGeneration>
    <Linking>
      <Debugging>
        <UseHeaptrc Value="True"/>
      </Debugging>
      <Options>
        <Win32>
          <GraphicApplication Value="True"/>
        </Win32>
      </Options>
    </Linking>
  </CompilerOptions>
  <Debugging>
    <Exceptions>
      <Item>
        <Name Value="EAbort"/>
      </Item>
      <Item>
        <Name Value="ECodetoolError"/>
      </Item>
      <Item>
        <Name Value="EFOpenError"/>
      </Item>
    </Exceptions>
  </Debugging>
</CONFIG>
« Last Edit: February 03, 2023, 11:50:21 am by TRon »

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to set Heaptrc in linux
« Reply #19 on: February 03, 2023, 12:07:12 pm »
Please go back and re read Blaazen's post, heaptrace on linux reports what calls the function or procedure where the leak happens.  In this case -

$0000000000450BE7  DOCREATE,  line 921 of include/customform.inc

That tells you its happening in a create form function. Sure its not great but it does tell you its happening and tells you to look in the create function of one of your forms. Its usually not that hard to look at the most recently changed formcreate() and there it is !

Davo

 
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: How to set Heaptrc in linux
« Reply #20 on: February 03, 2023, 12:13:09 pm »
@dbannon:
I /lnow/ how to interpret the output from heaptrace. That is not the problem.

If you are truly of the opinion that this is how a trace is suppose to look like then that is fine but then using heaptrace for finding leaks is useless for me and for every other common user of Lazarus (let alone newbies or advising newbies to use heaptrace).

It is simply borked, and if that output is actually what should be outputted then it is broken by design (not to add completely useless for real world situations).

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to set Heaptrc in linux
« Reply #21 on: February 03, 2023, 12:42:06 pm »
No, I am quite sure thats not how it is supposed to look, but it is how it does look ! Either fix it or get used to it.

If the leak in in the 'main' function, bad luck ! Or a method called directly by LCL. But in most cases of a leak, its in a method that has been called from your own code, and therefore the report is far easy to read.
Quote
It is simply borked, and if that output is actually what should be outputted then it is broken by design (not to add completely useless for real world situations).
Rubbish. As I said, its not great but it is usually quite functional. I have been using it like that for years, and I have written a lot of leaky code ! But I never failed to find the leak. I always assumed every one only saw the calling method. Quite surprised that windows user get more specific information, good for them !

Here is a simple rule to avoid this problem, when you write leaky code, make sure its in a function or procedure that is called by your own code !  Easy...

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: How to set Heaptrc in linux
« Reply #22 on: February 03, 2023, 01:07:34 pm »
NOte that if the topline is missing, your code is possibly compiled with optimization on that turns off stackframes for leaf procedures/methods ?

Curt Carpenter

  • Sr. Member
  • ****
  • Posts: 396
Re: How to set Heaptrc in linux
« Reply #23 on: July 02, 2023, 04:53:40 am »
If you open Console In/Output (Ctrl+Alt+O or View -> Debug Window -> ...) you can see output when you terminate your program (GUI or non-GUI).

<snip>


Could someone that knows how please add Blaazen's key (above) to using heaptrc with Linux systems  to the https://wiki.freepascal.org/heaptrc page?  I think it would greatly improve the page for Linux users.  (I tried, but don't know if my "talk" submission will have any effect.)
« Last Edit: July 02, 2023, 05:06:42 am by Curt Carpenter »

Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Re: How to set Heaptrc in linux
« Reply #24 on: July 02, 2023, 06:54:39 am »
The wiki is simply correct. It does not matter if you use Windows or Linux. I wrote most of the wiki entry using Debian x86_64-Linux. I do not understand what your problem is, because there isn't any.
If anything, Windows can be a bit more annoying compared to Linux. As I explained in the wiki.
The entry was also tested for Debian arm-linux and X86_64-win64.

And I just verified on what machine I wrote it.
« Last Edit: July 02, 2023, 07:23:11 am by Thaddy »
Specialize a type, not a var.

Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Re: How to set Heaptrc in linux
« Reply #25 on: July 02, 2023, 10:53:01 am »
So, show me what is not clear in the wiki and I will edit it if it has merit....
Specialize a type, not a var.

Curt Carpenter

  • Sr. Member
  • ****
  • Posts: 396
Re: How to set Heaptrc in linux
« Reply #26 on: July 02, 2023, 04:59:58 pm »
I didn't say the wiki was incorrect:  I said it could be more helpful to linux users.

In https://wiki.freepascal.org/heaptrc, near the top, this line appears:

Quote
"On *nix (including BSD, Linux and macOS), by default, nothing will be shown for GUI programs. See leakview for details on how to make use of Heaptrc effectively."

I found Blaazen's note here in this thread to be more helpful than this, since rather than saying "nothing will be shown" it shows the reader how to actually see something of the heaptrc results.  He wrote:

Quote
"I wrote it above, if you open Console In/Output (Ctrl+Alt+O or View -> Debug Window -> Console) you can see there output when you terminate your program (GUI or non-GUI). You must use -gh (or the checkbox as in your screenshot in your very first post)."

I posted a "talk" note on the wiki.  If someone knows how to incorporate the note in the wiki page itself, I think it would enhance the page.  An opinion you may not share, of course, and that's OK.

Meanwhile though:  maybe being rude is a badge of honor in your culture, but I find it unconstructive and unpleasant. Not my first encounter with the attitude or I wouldn't mention it.


Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Re: How to set Heaptrc in linux
« Reply #27 on: July 02, 2023, 07:46:45 pm »
Ah, now I see. That is a part of the wiki that I did not write. It is also incorrect, so I will edit it away this week with some remarks.
When started from a terminal window a GUI app on Linux will neatly report the heap trace to that terminal.
Specialize a type, not a var.

Curt Carpenter

  • Sr. Member
  • ****
  • Posts: 396
Re: How to set Heaptrc in linux
« Reply #28 on: July 04, 2023, 08:25:50 pm »
If you open Console In/Output (Ctrl+Alt+O or View -> Debug Window -> ...) you can see output when you terminate your program (GUI or non-GUI).

<snip>

I (believe) I added Blaazen's note on seeing heaptrc output  to the wiki page as an extension to the "On *nix " note there.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to set Heaptrc in linux
« Reply #29 on: July 06, 2023, 01:16:38 pm »
Well done Curt, you are now officially a wiki editor !

And I do, now, see your point about how to see the heaptrc output. I suspect the problem might be that it was too obvious and therefore easy to overlook !  Most Linux users will probably be working, most of the time, with that console window open, I could not get anything done without it !

Anyway, good edit !  Please consider adding more as you come across things.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018