IBM i Global

 View Only
  • 1.  Heap analyze on IBM i

    Posted 17 days ago

    Hello,
    I have to analyze a memory leak in our software running on IBM i. For that I use the following PEX commands:

    ADDPEXDFN DFN(HEAP) TYPE(*TRACE) JOB((123456/MAT/MAT0 *ALL)) TASK(*ALL) MAXSTG(4000000) TRCTYPE(*SLTEVT) SLTEVT(*YES) MCHINST(*NONE) STGEVT((*ACTGRPHEAP))
    
    STRPEX SSNID(HEAP)
    
    - Do something in the job -
    
    ENDPEX SSNID(HEAP) DTALIB(MATTRC) RPLDTA(*YES)
    

    Then I have some outfiles which can be joined together to get the heap address, allocated size and call stack:

    CREATE VIEW mattrc/heapv1 AS
        (SELECT a.QRECN,
                a.QHPASA,
                a.QHPASZ,
                a.QHPOPR,
                a.QHPRET,
    --       c.QTITIMN,
                (SELECT QPRPNM
                    FROM mattrc/QAYPEPROCI
                    WHERE QHPCK1 = QPRKEY) cs1,
                QIASTMT1,
                (SELECT QPRPNM
                    FROM mattrc/QAYPEPROCI
                    WHERE QHPCK2 = QPRKEY) cs2,
                QIASTMT2,
                (SELECT QPRPNM
                    FROM mattrc/QAYPEPROCI
                    WHERE QHPCK3 = QPRKEY) cs3,
                QIASTMT3,
                (SELECT QPRPNM
                    FROM mattrc/QAYPEPROCI
                    WHERE QHPCK4 = QPRKEY) cs4,
                QIASTMT4,
                (SELECT QPRPNM
                    FROM mattrc/QAYPEPROCI
                    WHERE QHPCK5 = QPRKEY) cs5,
                QIASTMT5
          FROM mattrc/QAYPEHEAP a
               INNER JOIN mattrc/QAYPETIDX c
                 ON a.QRECN = c.QRECN
               LEFT JOIN mattrc/QAYPEIAD d
                 ON a.QRECN = d.QRECN);
                 
     /* Check mallocs whithout free */
     SELECT *
      FROM mattrc/heapv1
      WHERE QHPOPR = 0
        AND QHPASA NOT IN(SELECT QHPASA FROM mattrc/heapv1
                           WHERE QHPOPR = 1);

    My problem is, that the outfile QAYPEHEAP has only 5 fields to save 5 call stack entries. Is there a way to get more entries of the call stack?

    How do you analyze memory (heap) leaks on IBM i?
    On Windows we use WPA (Windows Performance Analyzer) for that.

    Thanks and best regards,
    Matthias



    ------------------------------
    Matthias Schatte
    ------------------------------


  • 2.  RE: Heap analyze on IBM i

    Posted 17 days ago

    Dear Matthias

    Chapter 8 of this redbook discusses memory leak on page 111 onwards: IBM Technology for Java Virtual Machine in IBM i5/OS at https://www.redbooks.ibm.com/abstracts/sg247353.html         

    This blog post may also be useful: How to debug memory leaks in your application at  https://community.ibm.com/community/user/wasdevops/blogs/ravali-yatham/2022/04/05/how-to-debug-memory-leaks-in-your-application       



    ------------------------------
    Satid S
    ------------------------------



  • 3.  RE: Heap analyze on IBM i

    Posted 17 days ago
    Edited by Satid S 17 days ago

    Another tool I also use is IBM i Performance Data Investigator (PDI) charts named IBM Technology for Java Memory Overview and IBM Technology for Java Memory by Job. 

    The Overview chart helps me see if I should allocate more memory, and about how much more, to the memory pool in which Java jobs are running. This chart shows a total heap size in all pools.

    The By Job chart may point out any particular job causing a need for more allocated heap size. You need to be aware which job run in which memory pool.  For each job, the red bar exceeding the blue bar is one sign of memory issue.



    ------------------------------
    Satid S
    ------------------------------



  • 4.  RE: Heap analyze on IBM i

    Posted 17 days ago

    Thanks for your reply.

    Sorry, I did not wrote what language we are using. We are using ILE C++ with target release V7R3M0 and newer.

    So we can not use the Java analyze tools.



    ------------------------------
    Matthias Schatte
    ------------------------------



  • 5.  RE: Heap analyze on IBM i

    Posted 17 days ago
    Edited by Matthias Schatte 17 days ago

    In the meantime I have checked some more outfiles an now I can join with file QAYPEIAD and have 16 call stack entries:

    CREATE or replace VIEW mattrc/heapv1 AS(
    SELECT a.QRECN, a.QHPASA, a.QHPASZ, a.QHPOPR, a.QHPRET,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY16 = QPRKEY) cs16, QIASTMT16,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY15 = QPRKEY) cs15, QIASTMT15,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY14 = QPRKEY) cs14, QIASTMT14,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY13 = QPRKEY) cs13, QIASTMT13,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY12 = QPRKEY) cs12, QIASTMT12,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY11 = QPRKEY) cs11, QIASTMT11,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY10 = QPRKEY) cs10, QIASTMT10,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY9  = QPRKEY) cs9 , QIASTMT9,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY8  = QPRKEY) cs8 , QIASTMT8,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY7  = QPRKEY) cs7 , QIASTMT7,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY6  = QPRKEY) cs6 , QIASTMT6,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY5  = QPRKEY) cs5 , QIASTMT5,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY4  = QPRKEY) cs4 , QIASTMT4,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY3  = QPRKEY) cs3 , QIASTMT3,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY2  = QPRKEY) cs2 , QIASTMT2,
    (select rtrim(QPRPGN)||':'||QPRPNM from mattrc/QAYPEPROCI where QIAKEY1  = QPRKEY) cs1 , QIASTMT1
    FROM mattrc/QAYPEHEAP a
    LEFT JOIN mattrc/QAYPEIAD b
          ON a.QRECN = b.QRECN);

    But 16 entries for the call stack is also too low for many C++ applications.



    ------------------------------
    Matthias Schatte
    ------------------------------



  • 6.  RE: Heap analyze on IBM i

    Posted 16 days ago
      |   view attached

    This IBM Paper (PDF file) discusses how to properly use heap memory in IBM i ILE languages: Debug those mysterious problems with your application's memory at https://www.ibm.com/support/pages/system/files/inline-files/i-mysterious_application-pdf.pdf.   It appears to encourage the use of IBM i heap memory manager:  https://www.ibm.com/docs/en/i/7.3?topic=considerations-heap-memory.   There are 3 types of IBM i memory manager for different purposes.    I also attach the PDF file herewith.

    This blog post explains the use of IBM i debug memory manager: Debug Heap-Usage Problems at  https://dawnmayi.com/2010/08/02/debug-heap-usage-problems/       



    ------------------------------
    Satid S
    ------------------------------

    Attachment(s)

    pdf
    i-mysterious_application.pdf   197 KB 1 version


  • 7.  RE: Heap analyze on IBM i

    Posted 16 days ago

    Hello,

    thanks for the PDF. I know the debug Heap. But this is mostly used to check overwrites of allocated memory segments or the access of already freed memory segments.

    Excerpt from the PDF file:

    The debug memory manager does not detect memory leaks. Detecting memory leaks within the ILE applications is a topic to be covered in a future article.

    Do you know if this article already exists?



    ------------------------------
    Matthias Schatte
    ------------------------------



  • 8.  RE: Heap analyze on IBM i

    Posted 16 days ago

    Dear Matthias

    I Google the author name of the paper Scott Hanson and he has a profile on Twitter.. You may want to try your luck there. 



    ------------------------------
    Satid S
    ------------------------------