|
DigiPara Liftdesigner LDX API
|
API method: ILDXDocument5.GetPerformanceProfileStats
2 code examples follow.
' from Samples/Src/LDXAPIExamples/Example_LDXDocument.vb
Private Const PerformanceFormatString = "{0,-20} {1,10} {2,15:F3} {3,15:F3}"
Public Shared Sub PerformanceCounterLine(builder As StringBuilder,
ldxDocument As DigiPara.LDX.LDXDocument,
description As String,
stats As DigiPara.LDX.PerformanceProfileStatsType,
Timer As DigiPara.LDX.PerformanceProfileDocumentTimer)
Dim timeSelf, timeTotal As Double
Dim callCount As ULong
' this is how you get performance counter stats from document related sources
ldxDocument.GetPerformanceProfileStats(stats, Timer, timeSelf, timeTotal, callCount)
' callCount is then the number of total calls to the function (recursive calls included)
' timeSelf is the total time used by this function itself, nested calls to other functions excluded
' timeTotal is the total time used with this function in the callstack
If (callCount > 0) Then
builder.AppendFormat(PerformanceFormatString, description, callCount, timeSelf, timeTotal - timeSelf)
builder.AppendLine()
End If
End Sub
Public Shared Sub PerformanceCounterLine(builder As StringBuilder,
ldxSheet As DigiPara.LDX.LDXSheet,
description As String,
stats As DigiPara.LDX.PerformanceProfileStatsType,
timer As DigiPara.LDX.PerformanceProfileFrameTimer)
Dim timeSelf, timeTotal As Double
Dim callCount As ULong
' this is how you get performance counter stats from drawing related sources
' an equivalent function also exists on LDXSheetFrame.
ldxSheet.GetPerformanceProfileStats(stats, timer, timeSelf, timeTotal, callCount)
' callCount is then the number of total calls to the function (recursive calls included)
' timeSelf is the total time used by this function itself, nested calls to other functions excluded
' timeTotal is the total time used with this function in the callstack
If (callCount > 0) Then
builder.AppendFormat(PerformanceFormatString, description, callCount, timeSelf, timeTotal - timeSelf)
builder.AppendLine()
End If
End Sub
Public Shared Sub PerformanceCounterLine(builder As StringBuilder,
ldxApplication As DigiPara.LDX.LDXApplication,
description As String,
stats As DigiPara.LDX.PerformanceProfileStatsType,
Timer As DigiPara.LDX.PerformanceProfileApplicationTimer)
Dim timeSelf, timeTotal As Double
Dim callCount As ULong
' this is how you get performance counter stats from application related sources
ldxApplication.GetPerformanceProfileStats(stats, Timer, timeSelf, timeTotal, callCount)
' callCount is then the number of total calls to the function (recursive calls included)
' timeSelf is the total time used by this function itself, nested calls to other functions excluded
' timeTotal is the total time used with this function in the callstack
If (callCount > 0) Then
builder.AppendFormat(PerformanceFormatString, description, callCount, timeSelf, timeTotal - timeSelf)
builder.AppendLine()
End If
End Sub
' Show a message box with the most important performance stats
Public Shared Sub ShowPerformanceCounters(ldxDocument As DigiPara.LDX.LDXDocument, header As String)
Dim statsToShow = DigiPara.LDX.PerformanceProfileStatsType.ppstSinceLastReset
' since we manually manage stats reset in the examples, this is the most useful
' stat to show. The other options would be
' show the stats of the last user triggered actions; timers are reset as the user
' presses a UI button that modifies the document
' Dim statsToShow = DigiPara.LDX.PerformanceProfileStatsType.ppstSinceLastUserAction
' show the last run for each stat; these timers are reset at every opportunity
' so that the call count they return is minimal (usually 1, for recursive functions it can be more)
' Dim statsToShow = DigiPara.LDX.PerformanceProfileStatsType.ppstLastInvocation
Dim builder As New StringBuilder
builder.AppendLine(String.Format(PerformanceFormatString, "Function", "Count", "Self Time", "Children Time"))
PerformanceCounterLine(builder, ldxDocument.Application, "Total", statsToShow, DigiPara.LDX.PerformanceProfileApplicationTimer.ppatTopLevel)
PerformanceCounterLine(builder, ldxDocument, "CalculateModel", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtCalculateModel)
PerformanceCounterLine(builder, ldxDocument, "ChangePartRID", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtChangePartRID)
PerformanceCounterLine(builder, ldxDocument, "ModelCalculating", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtModelCalculating)
PerformanceCounterLine(builder, ldxDocument, "XML Rules", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtRules)
PerformanceCounterLine(builder, ldxDocument, "SaveUndo", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtSaveUndo)
PerformanceCounterLine(builder, ldxDocument, "ModelCalculated", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtModelCalculated)
PerformanceCounterLine(builder, ldxDocument, "DataTreeBuild", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtDockingDataTreeFill)
PerformanceCounterLine(builder, ldxDocument, "DataTreeRefresh", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtDockingDataTreeChanged)
PerformanceCounterLine(builder, ldxDocument, "CAD Occurrences", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtDockingCADOccurrences)
PerformanceCounterLine(builder, ldxDocument, "Property Grid", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtDockingPropertyGrid)
PerformanceCounterLine(builder, ldxDocument, "3D View", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtDocking3DView)
PerformanceCounterLine(builder, ldxDocument.Application, "Document Creation", statsToShow, DigiPara.LDX.PerformanceProfileApplicationTimer.ppatCreateModel)
PerformanceCounterLine(builder, ldxDocument, "Custom1", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtCustom1)
PerformanceCounterLine(builder, ldxDocument, "Custom2", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtCustom2)
PerformanceCounterLine(builder, ldxDocument, "Custom3", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtCustom3)
PerformanceCounterLine(builder, ldxDocument, "Custom4", statsToShow, DigiPara.LDX.PerformanceProfileDocumentTimer.ppdtCustom4)
PerformanceCounterLine(builder, ldxDocument.Sheets.ActiveSheet, "Frame Draw", statsToShow, DigiPara.LDX.PerformanceProfileFrameTimer.ppftFullBuild)
PerformanceCounterLine(builder, ldxDocument.Sheets.ActiveSheet, "Frame Refresh", statsToShow, DigiPara.LDX.PerformanceProfileFrameTimer.ppftRefresh)
PerformanceCounterLine(builder, ldxDocument.Sheets.ActiveSheet, "SheetFrameBuilding", statsToShow, DigiPara.LDX.PerformanceProfileFrameTimer.ppftSheetFrameBuilding)
Helpers.ShowMonospaceText(header, builder.ToString())
End Sub
<APIHelpAttribute(APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "", "LDXDocument~GetPerformanceProfileStats", "Retrieve Simple Performance Stats")>
Public Shared Sub BasicPerformanceCounters(ldxDocument As DigiPara.LDX.LDXDocument)
If ldxDocument Is Nothing Then
MsgBox("Active document not found!")
Exit Sub
End If
' this resets all timers reported via DigiPara.LDX.PerformanceProfileStatsType.ppstSinceLastReset
ldxDocument.Application.ResetTimers()
' so some work
ldxDocument.CalculateModelAndBuildSheet(DigiPara.LDX.CalculateModelModes.rcmCalc, Nothing)
' display result
ShowPerformanceCounters(ldxDocument, "Simple CalculateModelAndBuildSheet")
' see the PerformanceCounterLine subroutines for how to actually get the performance stats
' The output might look something like this (all times are in seconds):
' Simple CalculateModelAndBuildSheet
' Function Count Self Time Children Time
' Total 5 0.000 0.288
' CalculateModel 1 0.232 0.003
' ModelCalculating 3 0.003 0.000
' Frame Draw 4 0.054 0.000
' SheetFrameBuilding 8 0.000 0.000
' Interpretation
' Total's Children Time will always be the total of all time measurements taken.
' The main calls here are the one CalculateModel and four frame draws; the sheet
' in this case has four view frames, so that adds up. Also, each frame build and the
' CalculateModel contribute to the Total count.
' Each view frame draw triggers two SheetFrameBuilding events, one before and one after;
' they usually do nothing, as can be seen by the two timers showing zero.
' Most time is spent in CalculateModel, with just 3 ms by calls to other functions;
' we can find these 3 ms again in ModelCalculating, which is responsible for running .NET
' client code. It is usually called three times for every CalculateModel. There is
' a tiny bit of .NET client code active here at all times, hence 3ms spent.
' You may see a Total count of 6 or more here; the additional unaccounted timer runs
' can be 3D view or UI window updates. In that case, the Total Children Time may also
' not be the sum of the listed self times.
' If you add DigiPara.LDX.CalculateModelModes.rcmFireCalculatedEvent to the first argument of
' ldxDocument.CalculateModelAndBuildSheet, you should see the ModelCalculated and various docking
' windows appear in the stats.
End Sub
' from Samples/Src/LDXAPIExamples/Example_LDXDocument.vb
<APIHelpAttribute(APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "", "LDXDocument~GetPerformanceProfileStats", "Retrieve .NET Client Code Performance Stats")>
Public Shared Sub PerformanceCountersWithUserCode(ldxDocument As DigiPara.LDX.LDXDocument)
If ldxDocument Is Nothing Then
MsgBox("Active document not found!")
Exit Sub
End If
' this resets all timers reported via DigiPara.LDX.PerformanceProfileStatsType.ppstSinceLastReset
ldxDocument.Application.ResetTimers()
' register our test client code
AddHandler ldxDocument.Application.ModelCalculating, AddressOf LDXDocument_ModelCalculating_ForPerformanceStats
' so some work
ldxDocument.CalculateModelAndBuildSheet(DigiPara.LDX.CalculateModelModes.rcmCalc, Nothing)
' display result
ShowPerformanceCounters(ldxDocument, ".NET Client Code")
' see the PerformanceCounterLine subroutines for how to actually get the performance stats
' Sample output:
' .NET Client Code
' Function Count Self Time Children Time
' Total 5 0.000 0.729
' CalculateModel 2 0.627 0.050
' ModelCalculating 3 0.002 0.449
' Custom1 3 0.047 0.000
' Custom2 3 0.000 0.401
' Custom3 1 0.000 0.401
' Frame Draw 4 0.053 0.000
' SheetFrameBuilding 8 0.000 0.000
' "Frame Draw" and "SheetFrameBuilding" are like in BasicPerformanceCounters above.
' New are the custom timers:
' Custom1 has a self time of 47ms, that means it is using that much time all on its own.
' It is calculating prime numbers, crudely, so this should come as no surprise.
' Custom2 and Custom3 are nested; neither of them takes any significant time on its own.
' But the inner one is calling the document's CalculateModel recursively, that shows up
' in two places: its Children Time (mirrored by the outer Custom2 timer) contains
' the time taken by the recursive CalculateModel, and compared to BasicPerformanceCounters,
' the CalculateModel Count is up to 2.
' You may see a Total count of 6 or more here; the additional unaccounted timer runs
' can be 3D view or UI window updates. In that case, the Total Children Time may also
' not be the sum of the listed self times.
' If you add DigiPara.LDX.CalculateModelModes.rcmFireCalculatedEvent to the first argument of
' ldxDocument.CalculateModelAndBuildSheet, you should see the ModelCalculated and various docking
' windows appear in the stats.
RemoveHandler ldxDocument.Application.ModelCalculating, AddressOf LDXDocument_ModelCalculating_ForPerformanceStats
End Sub