set categories "ssialloc hoops_allocated hoops_used WorkingSetSize"
set iterations 5
set regressionTestScriptName "test.tcl"
proc getMemoryUsageArray { variableName } {
upvar $variableName memory
set memoryUsage [SclMemoryUsage]
foreach value $memoryUsage {
set value [string trim $value ", "]
set valuelist [split $value "="]
set key [lindex $valuelist 0]
set value [lindex $valuelist 1]
set memory($key) $value
}
}
proc copyArrayInto2DArray { destArrayName destIndex srcArrayName } {
upvar $destArrayName destArray
upvar $srcArrayName srcArray
foreach id [array names srcArray] {
set destArray($destIndex,$id) $srcArray($id)
}
}
proc printResultsToMessageWindow { memoryUsageName categoriesName iterations } {
upvar $memoryUsageName memoryUsage
upvar $categoriesName categories
set tempString [join $categories ","]
puts "We will display memory for $tempString"
for { set i 0 } { $i <= $iterations } { incr i }  {
set memoryUsed ""
foreach category $categories {
lappend memoryUsed $memoryUsage($i,$category)
}
set tempString [join $memoryUsed ","]
puts "memory measured for iteration $i:  $tempString"
}
for { set i 1 } { $i <= $iterations } { incr i }  {
set memoryUsed ""
foreach category $categories {
lappend memoryUsed [expr $memoryUsage($i,$category) - $memoryUsage([expr $i-1],$category)]
}
set tempString [join $memoryUsed ","]
puts "memory difference for iteration $i:  $tempString"
}
set totalMemoryUsed ""
set averageMemoryUsed ""
foreach category $categories {
set memUsed [expr $memoryUsage($iterations,$category) - $memoryUsage(0,$category)]
lappend totalMemoryUsed $memUsed
lappend averageMemoryUsed [expr $memUsed / $iterations]
}
set tempString [join $totalMemoryUsed ","]
puts "total memory used:  $tempString"
set tempString [join $averageMemoryUsed ","]
puts "average memory used:  $tempString"
}
proc drawMemoryPlot { memoryUsageName categoriesName iterations } {
upvar $memoryUsageName memoryUsage
upvar $categoriesName categories
set xIncr 10
set stringNumber 0
foreach category $categories {
incr stringNumber
puts "String $stringNumber is $category"
set xCoord 0
for {set i 0} {$i <= $iterations} {incr i} {
set status [ SclFunction "CREATE POINT" {
frm00474={
{
istr="$stringNumber"
ynew="$memoryUsage($i,$category)"
xnew="$xCoord"
znew="0"
desc="$memoryUsage($i,$category)"
}
}
}]
set xCoord [expr $xCoord + $xIncr]
}
}
set status [ SclFunction "SAVE FILE" {
frm00287={
{
location="memory_usage"
rid="1"
ftype="S"
purpose=""
range=""
format="text"
}
}
}]
set status [ SclFunction "STR MATHS" {
frm00700={
{
file_loc="memory_usage"
file_id="1"
result_loc="memory_usage"
main=table { str_range constraint field expr } {
{ "" "" "y" "y/1048576" }
{ "" "" "d1" "nint(d1/1048576)" }
{ "" "" "" "" }
{ "" "" "" "" }
{ "" "" "" "" }
{ "" "" "" "" }
{ "" "" "" "" }
{ "" "" "" "" }
{ "" "" "" "" }
{ "" "" "" "" }
}
}
}
frm00701={
{
_action="apply"
}
}
frm00121={
{
_action="apply"
}
}
}]
set status [ SclFunction "EXIT GRAPHICS" {
frm00108={
{
exit_mode="E"
}
}
}]
set status [ SclFunction "RECALL ANY FILE" {
file="memory_usage1.str"
mode="openInNewLayer"
}]
set status [ SclFunction "DRAW DESC" {
frm00089={
{
range1=""
range2=""
range3=""
ifld_num="d1"
textalignment="v"
position="All points"
legend_location="no legend"
}
}
}]
set status [ SclFunction "ZOOM FACTOR" {
frm00326={
{
zoom_factor="1.1"
}
}
}]
set status [ SclFunction "ZOOM OUT" {} ]
set status [ SclFunction "ZOOM FACTOR" {
frm00326={
{
zoom_factor="2"
}
}
}]
set status [ SclFunction "2D GRID" {
frm00140={
{
}
}
}]
}
getMemoryUsageArray memoryUsageStart
copyArrayInto2DArray memoryUsage 0 memoryUsageStart
for {set i 1} {$i<=$iterations} {incr i} {
set status [ SclFunction "EXIT GRAPHICS" {
frm00108={ {	exit_mode="E"	}	}
}]
source $regressionTestScriptName
getMemoryUsageArray memoryUsageAfter
copyArrayInto2DArray memoryUsage $i memoryUsageAfter
}
set status [ SclFunction "EXIT GRAPHICS" {
frm00108={ {	exit_mode="E"	}	}
}]
printResultsToMessageWindow memoryUsage categories $iterations
drawMemoryPlot memoryUsage categories $iterations
