From de3a487895630021a3054dd3b810c050dbede943 Mon Sep 17 00:00:00 2001 From: Adrian Pop Date: Wed, 18 Apr 2018 12:34:20 +0200 Subject: [PATCH] add GC_get_prof_stats as OMC API, ticket:4889 Belonging to [master]: - OpenModelica/OMCompiler#2381 --- Compiler/FrontEnd/ModelicaBuiltin.mo | 22 +++++++++++++ Compiler/NFFrontEnd/NFModelicaBuiltin.mo | 32 +++++++++++++++++++ Compiler/Script/CevalScript.mo | 39 +++++++++++++++++++++++- 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/Compiler/FrontEnd/ModelicaBuiltin.mo b/Compiler/FrontEnd/ModelicaBuiltin.mo index 8a60f1f1ba7..0e1d1c6ca7c 100644 --- a/Compiler/FrontEnd/ModelicaBuiltin.mo +++ b/Compiler/FrontEnd/ModelicaBuiltin.mo @@ -3889,6 +3889,28 @@ annotation( ")); end GC_set_max_heap_size; +record GC_PROFSTATS + Integer heapsize_full; + Integer free_bytes_full; + Integer unmapped_bytes; + Integer bytes_allocd_since_gc; + Integer allocd_bytes_before_gc; + Integer non_gc_bytes; + Integer gc_no; + Integer markers_m1; + Integer bytes_reclaimed_since_gc; + Integer reclaimed_bytes_before_gc; +end GC_PROFSTATS; + +function GC_get_prof_stats + output GC_PROFSTATS gcStats; +external "builtin"; +annotation( + Documentation(info=" +

Returns a record with the GC statistics.

+")); +end GC_get_prof_stats; + function checkInterfaceOfPackages input TypeName cl; input String dependencyMatrix[:,:]; diff --git a/Compiler/NFFrontEnd/NFModelicaBuiltin.mo b/Compiler/NFFrontEnd/NFModelicaBuiltin.mo index 04b1d9bf063..2a89e2efa65 100644 --- a/Compiler/NFFrontEnd/NFModelicaBuiltin.mo +++ b/Compiler/NFFrontEnd/NFModelicaBuiltin.mo @@ -3955,6 +3955,38 @@ annotation( ")); end GC_expand_hp; +function GC_set_max_heap_size + input Integer size; + output Boolean success; +external "builtin"; +annotation( + Documentation(info=" +

Forces the GC to limit the maximum heap size.

+")); +end GC_set_max_heap_size; + +record GC_PROFSTATS + Integer heapsize_full; + Integer free_bytes_full; + Integer unmapped_bytes; + Integer bytes_allocd_since_gc; + Integer allocd_bytes_before_gc; + Integer non_gc_bytes; + Integer gc_no; + Integer markers_m1; + Integer bytes_reclaimed_since_gc; + Integer reclaimed_bytes_before_gc; +end GC_PROFSTATS; + +function GC_get_prof_stats + output GC_PROFSTATS gcStats; +external "builtin"; +annotation( + Documentation(info=" +

Returns a record with the GC statistics.

+")); +end GC_get_prof_stats; + function checkInterfaceOfPackages input TypeName cl; input String dependencyMatrix[:,:]; diff --git a/Compiler/Script/CevalScript.mo b/Compiler/Script/CevalScript.mo index 55069ae9252..215d0ea6793 100644 --- a/Compiler/Script/CevalScript.mo +++ b/Compiler/Script/CevalScript.mo @@ -549,7 +549,7 @@ algorithm Absyn.Exp aexp; DAE.DAElist dae; array> m,mt; - Values.Value ret_val,simValue,value,v,cvar,cvar2,v1,v2,v3; + Values.Value ret_val,simValue,value,v,cvar,cvar2,v1,v2,v3,gcStatRec; Absyn.ComponentRef cr,cr_1; Integer size,resI,i,i1,i2,i3,n,curveStyle,numberOfIntervals, status; list is; @@ -589,6 +589,7 @@ algorithm list> valsLst; Boolean new_inst; SymbolTable interactiveSymbolTable, interactiveSymbolTable2; + GC.ProfStats gcStats; case (cache,_,"parseString",{Values.STRING(str1),Values.STRING(str2)},_) equation @@ -676,6 +677,42 @@ algorithm GC.setMaxHeapSize(i); then (cache,Values.BOOL(true)); + case (cache,_,"GC_get_prof_stats",{},_) + equation + gcStats = GC.getProfStats(); + gcStatRec = match gcStats + case GC.PROFSTATS() then + Values.RECORD(Absyn.IDENT("GC_PROFSTATS"), + { + Values.INTEGER(gcStats.heapsize_full), + Values.INTEGER(gcStats.free_bytes_full), + Values.INTEGER(gcStats.unmapped_bytes), + Values.INTEGER(gcStats.bytes_allocd_since_gc), + Values.INTEGER(gcStats.allocd_bytes_before_gc), + Values.INTEGER(gcStats.bytes_allocd_since_gc+gcStats.allocd_bytes_before_gc), + Values.INTEGER(gcStats.non_gc_bytes), + Values.INTEGER(gcStats.gc_no), + Values.INTEGER(gcStats.markers_m1), + Values.INTEGER(gcStats.bytes_reclaimed_since_gc), + Values.INTEGER(gcStats.reclaimed_bytes_before_gc) + }, + { + "heapsize_full", + "free_bytes_full", + "unmapped_bytes: ", + "bytes_allocd_since_gc", + "allocd_bytes_before_gc", + "total_allocd_bytes", + "non_gc_bytes", + "gc_no", + "markers_m1", + "bytes_reclaimed_since_gc", + "reclaimed_bytes_before_gc" + }, + -1); + end match; + then (cache, gcStatRec); + case (cache,_,"clear",{},_) algorithm SymbolTable.reset();