Heaptrack

Last update: 23 May 2024 [History] [Edit]

Introduction

Heaptrack is another memory profiler and leak checker with similar features to valgrind/massif but without its overhead. To profile an Athena job, it is necessary to directly launch it as a python script as Heaptrack seems to have problems with the exec used in the athena.py shell(!) script: heaptrack $(which python) yourCAJob.py The Heaptrack is included in the LCG releases, thus it will be available once asetup Athena,main,nightly is launched. To conveniently analyze the results, install the heaptrack_gui (which is not the part of LCG) on your development machine or use the builtin heaptrack_print. For example, assume the following named runHeapTrackReco.py

# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration

import sys

def _run():
    from AthenaConfiguration.AllConfigFlags import initConfigFlags
    flags = initConfigFlags()
    # input
    flags.Exec.MaxEvents = 100 #We need a few to not be dominated by input

    # SPOT input
    flags.Input.Files = [
        '/eos/atlas/atlascerngroupdisk/proj-spot/spot-job-inputs/data23_13p6TeV/data23_13p6TeV.00451569.physics_Main.daq.RAW._lb0260._SFO-14._0001.data']
    flags.IOVDb.GlobalTag = "CONDBR2-BLKPA-2023-01"
    flags.GeoModel.AtlasVersion = "ATLAS-R3S-2021-03-02-00"

    from AthenaConfiguration.Enums import ProductionStep
    flags.Common.ProductionStep = ProductionStep.Reconstruction
     
    # output
    flags.Output.ESDFileName = "myESD.pool.root"
    flags.Output.AODFileName = "myAOD.pool.root"
    flags.Output.HISTFileName = "myHist.root"

    # uncomment given something like export ATHENA_CORE_NUMBER=2
    # flags.Concurrency.NumThreads = 2

    # Setup detector flags
    from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
    setupDetectorFlags(flags, None, use_metadata=True,
                       toggle_geometry=True, keep_beampipe=True)

    flags.lock()

    from RecJobTransforms.RecoSteering import RecoSteering
    acc = RecoSteering(flags)

    # Special message service configuration
    from DigitizationConfig.DigitizationSteering import DigitizationMessageSvcCfg
    acc.merge(DigitizationMessageSvcCfg(flags))

    from AthenaConfiguration.Utils import setupLoggingLevels
    setupLoggingLevels(flags, acc)

    # Print reco domain status
    from RecJobTransforms.RecoConfigFlags import printRecoFlags
    printRecoFlags(flags)
    #acc.getService("StoreGateSvc").DumpArena = True 
    # running
    statusCode = acc.run()
    return statusCode


if __name__ == "__main__":
    statusCode = None
    statusCode = _run()
    assert statusCode is not None, "Issue while running"
    sys.exit(not statusCode.isSuccess())

One can then run: heaptrack python runHeapTrackReco.py > log 2>&1 &

will create a heaptrack.python.xx...xxx..zst file (where xxxxx will be a PID). From which you can create an analysis file heaptrack --analyze "path_to_file" > analysis.txt