CGA Profiling / Performance tuning: how to?

561
4
07-17-2020 04:54 AM
DaveLajoie
New Contributor

Hello Guys! 

I was wondering if there is a way to profile our CGA code, is there a way to determine the number of calls for specific function, time spent in each function, etc.

For example:

Also I came across something that I am not sure if the call is being done one or three time

getScopeInWorld =

     [ convert( x, scope, world, pos, 0,0,0 ) ,

       convert( y, scope, world, pos, 0,0,0 ) ,

       convert( z, scope, world, pos, 0,0,0 ) ]

print( [ getScopeInWorld[0], getScopeInWorld[1], getScopeInWorld[2] ] )

is getScopeInWorld evaluated three time or one time?

0 Kudos
4 Replies
CherylLau
Esri Regular Contributor

No, sorry, we don't have any built-in profiling tools for cga.

In your particular example, getScopeInWorld is considered a function, which is evaluated in every call.  So, it is evaluated 3 times, meaning convert is evaluated 9 times.  Putting a const in front of it will ensure that it is only evaluated once.

CGA functions—ArcGIS CityEngine Resources | Documentation 

const keyword—ArcGIS CityEngine Resources | Documentation 

Debugging tip:  You can put a print statement around the array in the getScopeInWorld definition, and you will see it is printed 3 times (plus a fourth time for the final print statement in your code above).

getScopeInWorld = 
print(
[convert(x, scope, world, pos, 0, 0, 0),
convert(y, scope, world, pos, 0, 0, 0),
convert(z, scope, world, pos, 0, 0, 0)]
)
‍‍‍‍‍‍‍‍‍‍‍‍‍
print( [getScopeInWorld[0], getScopeInWorld[1], getScopeInWorld[2]] )‍‍‍‍‍‍‍‍
0 Kudos
DaveLajoie
New Contributor

Tx!

Using a const might help indeed, however will it be constant per shape or for the entire rule evaluation? I guess I should be able to test this myself know that I know that I can put a print statement in a function.

will test and let you know.

0 Kudos
DaveLajoie
New Contributor

somehow the const statement prevents print statement...

getScopeInWorld = 

print(
[convert(x, scope, world, pos, 0, 0, 0),
convert(y, scope, world, pos, 0, 0, 0),
convert(z, scope, world, pos, 0, 0, 0)]
)

const getConstScopeInWorld =
print(
[convert(x, scope, world, pos, 0, 0, 0),
convert(y, scope, world, pos, 0, 0, 0),
convert(z, scope, world, pos, 0, 0, 0)]
)

SplitXZ-->
alignScopeToAxes(y)
split( x, noAdjust ){ 10 : SplitZ }*

SplitZ-->
split( z, noAdjust ){ 10 : Cell( getConstScopeInWorld ) }*

Cell( point )-->
point
color( rand(), rand(), rand() )
X.

0 Kudos
CherylLau
Esri Regular Contributor

In a future release (2020.1), printing a const will work, but it doesn't work yet in 2020.0.

0 Kudos