Introduction

msLeaks provides open APIs to help users analyze memory and identify memory problems.

The analyzer is the new offline analysis module of msLeaks and is responsible for all offline analysis functions. You can import the analyzer from msLeaks to implement memory leak analysis and custom inefficient memory identification.

msLeaks provides two methods for offline analysis: quick analysis APIs and analyzer. The quick analysis APIs are recommended.

  • Quick analysis APIs

    msLeaks provides quick analysis APIs for offline analysis. The following Table 1 lists the APIs.

    Table 1 API list

    API

    Description

    list_analyzers

    This API outputs all memory analysis types supported by msLeaks.

    get_analyzer_config

    This API views the parameters required for running the corresponding memory analysis type.

    analyze

    The quick analysis API provided by msLeaks, which supports memory leak analysis and custom inefficient memory identification.

    check_leaks

    The quick analysis API provided by msLeaks for memory leak analysis.

    check_inefficient

    The quick analysis API provided by msLeaks for custom inefficient memory identification.

  • analyzer

    You can import analyzer from msLeaks to perform offline analysis. Table 2 describes the involved APIs. Since the code implementation is complex, this mode is not recommended.

    The example code is as follows:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    # Import the analyzer and the corresponding config from msLeaks.
    from msleaks.analyzer import LeaksAnalyzer, LeaksConfig
    # Declare parameters and generate config.
    leaks_config = LeaksConfig(
        input_path="user/leaks.csv", # Use the actual path for input_path.
        mstx_info="test",
        start_index=0
    )
    # Generate an analyzer instance for analysis.
    leaks_analyzer=LeaksAnalyzer()
    leaks_analyzer.analyze(leaks_config)
    
    # Import the analyzer of inefficient memory and the corresponding config.
    from msleaks.analyzer import InefficientConfig, InefficientAnalyzer
    # Declare parameters and generate config.
    ineff_config = InefficientConfig(
        input_path="user/ineff.csv", # Use the actual path for input_path.
        mem_size=0,
        inefficient_type=["early_allocation","late_deallocation","temporary_idleness"],
        idle_threshold=3000
    )
    # Generate an analyzer instance for analysis.
    ineff_analyzer=InefficientAnalyzer()
    ineff_analyzer.analyze(ineff_config)
    
    Table 2 analyzer interface description

    API

    Description

    LeaksAnalyzer

    Memory leak analyzer.

    LeaksConfig

    Memory leak analysis parameters.

    InefficientConfig

    Inefficiency memory analysis parameters.

    InefficientAnalyzer

    Inefficiency memory analyzer.