#!/usr/bin/env python
#
# Copyright (C) 2023 CERN for the benefit of the ATLAS collaboration
#
# Necessary import(s).
import os
import sys
# why do we need this
import ROOT
#
#
import gc
from multiprocessing import Process
#  
def print_memory(tag=""):
    cn='print_memory: '
    print(cn,"print_memory ",tag)
    
    gc.collect()

    info = ROOT.ProcInfo_t()     # create the struct    
    ROOT.gSystem.GetProcInfo(info)

    print(cn,"Resident memory:", info.fMemResident / 1024, "MB")
    print(cn,"Virtual memory :", info.fMemVirtual / 1024, "MB")    

    return info.fMemVirtual / 1024
    
#
#@profile  # to run profiler
def main():
   '''C(++) style main function'''
   #    
   ROOT.gInterpreter.Declare(
   """
//
""")   
#
   if len(sys.argv)>1:
    filename=sys.argv[1] 
    print ('Input file ', filename)
   #
   print_memory(tag="Starting: Print memory consumption: ")   
   

# Execute the main function, when in "script mode".
if __name__ == "__main__":
  sys.exit(main())
