Skip to content

Commit

Permalink
Add basic memory profiling to execstat
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Mar 4, 2016
1 parent cfa27e9 commit bcd948c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions Compiler/Global/Global.mo
Expand Up @@ -56,6 +56,7 @@ constant Integer flagsIndex = 16;
constant Integer builtinGraphIndex = 17;
constant Integer rewriteRulesIndex = 18;
constant Integer stackoverFlowIndex = 19;
constant Integer gcProfilingIndex = 20;

// indexes in System.tick
// ----------------------
Expand Down
17 changes: 15 additions & 2 deletions Compiler/SimCode/SimCodeFunctionUtil.mo
Expand Up @@ -56,6 +56,7 @@ import List;
import Mod;
import Patternm;
import SCode;
import StringUtil;

public

Expand Down Expand Up @@ -2852,6 +2853,7 @@ public function execStatReset
algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_EXECSTAT);
System.realtimeTick(ClockIndexes.RT_CLOCK_EXECSTAT_CUMULATIVE);
setGlobalRoot(Global.gcProfilingIndex, GC.getProfStats());
end execStatReset;

public function execStat
Expand All @@ -2865,19 +2867,30 @@ public function execStat
protected
Real t, total;
String timeStr, totalTimeStr, gcStr;
Integer memory, oldMemory, since, before;
GC.ProfStats stats, oldStats;
algorithm
if Flags.isSet(Flags.EXEC_STAT) then
(stats as GC.PROFSTATS(bytes_allocd_since_gc=since, allocd_bytes_before_gc=before)) := GC.getProfStats();
memory := since+before;
oldStats := getGlobalRoot(Global.gcProfilingIndex);
(oldStats as GC.PROFSTATS(bytes_allocd_since_gc=since, allocd_bytes_before_gc=before)) := oldStats;
oldMemory := since+before;
t := System.realtimeTock(ClockIndexes.RT_CLOCK_EXECSTAT);
total := System.realtimeTock(ClockIndexes.RT_CLOCK_EXECSTAT_CUMULATIVE);
gcStr := GC.profStatsStr(GC.getProfStats(), head="", delimiter=" / ");
timeStr := System.snprintff("%.4g", 20, t);
totalTimeStr := System.snprintff("%.4g", 20, total);
if Flags.isSet(Flags.GC_PROF) then
gcStr := GC.profStatsStr(stats, head="", delimiter=" / ");
Error.addMessage(Error.EXEC_STAT_GC, {name, timeStr, totalTimeStr, gcStr});
else
Error.addMessage(Error.EXEC_STAT, {name, timeStr, totalTimeStr});
Error.addMessage(Error.EXEC_STAT, {name, timeStr, totalTimeStr,
StringUtil.bytesToReadableUnit(memory-oldMemory, maxSizeInUnit=500, significantDigits=4),
StringUtil.bytesToReadableUnit(memory, maxSizeInUnit=500, significantDigits=4)
});
end if;
System.realtimeTick(ClockIndexes.RT_CLOCK_EXECSTAT);
setGlobalRoot(Global.gcProfilingIndex, stats);
end if;
end execStat;

Expand Down
3 changes: 1 addition & 2 deletions Compiler/Util/Error.mo
Expand Up @@ -832,11 +832,10 @@ public constant Message SUBCLOCK_CONFLICT = MESSAGE(570, TRANSLATION(), ERROR(),
public constant Message CLOCK_CONFLICT = MESSAGE(571, TRANSLATION(), ERROR(),
Util.gettext("Partitions have different base clocks."));
public constant Message EXEC_STAT = MESSAGE(572, TRANSLATION(), NOTIFICATION(),
Util.gettext("Performance of %s: time %s/%s"));
Util.gettext("Performance of %s: time %s/%s, memory: %s / %s"));
public constant Message EXEC_STAT_GC = MESSAGE(573, TRANSLATION(), NOTIFICATION(),
Util.gettext("Performance of %s: time %s/%s, GC stats:%s"));


public constant Message MATCH_SHADOWING = MESSAGE(5001, TRANSLATION(), ERROR(),
Util.gettext("Local variable '%s' shadows another variable."));
public constant Message META_POLYMORPHIC = MESSAGE(5002, TRANSLATION(), ERROR(),
Expand Down
3 changes: 2 additions & 1 deletion Compiler/Util/GC.mo
Expand Up @@ -70,7 +70,7 @@ function setForceUnmapOnGcollect
external "C" GC_set_force_unmap_on_gcollect(forceUnmap) annotation(Library = {"omcgc"});
end setForceUnmapOnGcollect;

uniontype ProfStats // TODO: Support regular records in the bootstrapped compiler to avoid allocation to return the stats in the GC...
uniontype ProfStats "TODO: Support regular records in the bootstrapped compiler to avoid allocation to return the stats in the GC..."
record PROFSTATS
Integer heapsize_full, free_bytes_full, unmapped_bytes, bytes_allocd_since_gc, allocd_bytes_before_gc, non_gc_bytes, gc_no, markers_m1, bytes_reclaimed_since_gc, reclaimed_bytes_before_gc;
end PROFSTATS;
Expand All @@ -90,6 +90,7 @@ algorithm
"unmapped_bytes: " + intString(stats.unmapped_bytes) + delimiter +
"bytes_allocd_since_gc: " + intString(stats.bytes_allocd_since_gc) + delimiter +
"allocd_bytes_before_gc: " + intString(stats.allocd_bytes_before_gc) + delimiter +
"total_allocd_bytes: " + intString(stats.bytes_allocd_since_gc+stats.allocd_bytes_before_gc) + delimiter +
"non_gc_bytes: " + intString(stats.non_gc_bytes) + delimiter +
"gc_no: " + intString(stats.gc_no) + delimiter +
"markers_m1: " + intString(stats.markers_m1) + delimiter +
Expand Down
21 changes: 21 additions & 0 deletions Compiler/Util/StringUtil.mo
Expand Up @@ -317,5 +317,26 @@ algorithm
end for;
end equalIgnoreSpace;

function bytesToReadableUnit
input Integer bytes;
input Integer significantDigits=4;
input Real maxSizeInUnit=500 "If it is 1000, we print up to 1000GB before changing to X TB";
output String str;
protected
constant Real TB = 1024^4, GB=1024^3, MB=1024^2, kB=1024;
algorithm
if bytes > maxSizeInUnit*GB then
str := String(bytes/TB, significantDigits=significantDigits)+" TB";
elseif bytes > maxSizeInUnit*MB then
str := String(bytes/GB, significantDigits=significantDigits)+" GB";
elseif bytes > maxSizeInUnit*kB then
str := String(bytes/MB, significantDigits=significantDigits)+" MB";
elseif bytes > maxSizeInUnit then
str := String(bytes/kB, significantDigits=significantDigits)+" kB";
else
str := String(bytes);
end if;
end bytesToReadableUnit;

annotation(__OpenModelica_Interface="util");
end StringUtil;

0 comments on commit bcd948c

Please sign in to comment.