-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic profiler to the scene editor
- Loading branch information
Showing
10 changed files
with
314 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
newIDE/app/src/InstancesEditor/InstancesRenderer/BasicProfilingCounters.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// @flow | ||
|
||
type InstanceCounter = { | ||
updateCount: number, | ||
totalUpdateTime: number, | ||
}; | ||
|
||
export type BasicProfilingCounters = { | ||
instanceCounters: { [string]: InstanceCounter }, | ||
totalInstancesUpdateCount: number, | ||
totalInstancesUpdateTime: number, | ||
totalPixiRenderingTime: number, | ||
totalPixiUiRenderingTime: number, | ||
totalThreeRenderingTime: number, | ||
}; | ||
|
||
export const makeBasicProfilingCounters = (): BasicProfilingCounters => { | ||
return { | ||
instanceCounters: {}, | ||
totalInstancesUpdateCount: 0, | ||
totalInstancesUpdateTime: 0, | ||
totalPixiRenderingTime: 0, | ||
totalPixiUiRenderingTime: 0, | ||
totalThreeRenderingTime: 0, | ||
}; | ||
}; | ||
|
||
export const resetBasicProfilingCounters = ( | ||
basicProfilingCounters: BasicProfilingCounters | ||
): BasicProfilingCounters => { | ||
basicProfilingCounters.instanceCounters = {}; | ||
basicProfilingCounters.totalInstancesUpdateCount = 0; | ||
basicProfilingCounters.totalInstancesUpdateTime = 0; | ||
basicProfilingCounters.totalPixiRenderingTime = 0; | ||
basicProfilingCounters.totalPixiUiRenderingTime = 0; | ||
basicProfilingCounters.totalThreeRenderingTime = 0; | ||
return basicProfilingCounters; | ||
}; | ||
|
||
export const increaseInstanceUpdate = ( | ||
basicProfilingCounters: BasicProfilingCounters, | ||
objectName: string, | ||
updateDuration: number | ||
) => { | ||
let instanceCounter = basicProfilingCounters.instanceCounters[objectName]; | ||
if (!instanceCounter) { | ||
basicProfilingCounters.instanceCounters[objectName] = { | ||
updateCount: 1, | ||
totalUpdateTime: updateDuration, | ||
}; | ||
} else { | ||
instanceCounter.updateCount++; | ||
instanceCounter.totalUpdateTime += updateDuration; | ||
} | ||
basicProfilingCounters.totalInstancesUpdateCount++; | ||
basicProfilingCounters.totalInstancesUpdateTime += updateDuration; | ||
}; | ||
|
||
export const increasePixiRenderingTime = ( | ||
basicProfilingCounters: BasicProfilingCounters, | ||
pixiRenderingTime: number | ||
) => { | ||
basicProfilingCounters.totalPixiRenderingTime += pixiRenderingTime; | ||
}; | ||
|
||
export const increasePixiUiRenderingTime = ( | ||
basicProfilingCounters: BasicProfilingCounters, | ||
pixiUiRenderingTime: number | ||
) => { | ||
basicProfilingCounters.totalPixiUiRenderingTime += pixiUiRenderingTime; | ||
}; | ||
|
||
export const increaseThreeRenderingTime = ( | ||
basicProfilingCounters: BasicProfilingCounters, | ||
threeRenderingTime: number | ||
) => { | ||
basicProfilingCounters.totalThreeRenderingTime += threeRenderingTime; | ||
}; | ||
|
||
export const mergeBasicProfilingCounters = ( | ||
destination: BasicProfilingCounters, | ||
source: BasicProfilingCounters | ||
): BasicProfilingCounters => { | ||
for (const objectName in source.instanceCounters) { | ||
if (source.instanceCounters.hasOwnProperty(objectName)) { | ||
const instanceCounter = source.instanceCounters[objectName]; | ||
let destinationInstanceCounter = destination.instanceCounters[objectName]; | ||
if (!destinationInstanceCounter) { | ||
destinationInstanceCounter = destination.instanceCounters[ | ||
objectName | ||
] = { | ||
updateCount: 0, | ||
totalUpdateTime: 0, | ||
}; | ||
} | ||
destinationInstanceCounter.updateCount += instanceCounter.updateCount; | ||
destinationInstanceCounter.totalUpdateTime += | ||
instanceCounter.totalUpdateTime; | ||
} | ||
} | ||
destination.totalInstancesUpdateCount += source.totalInstancesUpdateCount; | ||
destination.totalInstancesUpdateTime += source.totalInstancesUpdateTime; | ||
destination.totalPixiRenderingTime += source.totalPixiRenderingTime; | ||
destination.totalPixiUiRenderingTime += source.totalPixiUiRenderingTime; | ||
destination.totalThreeRenderingTime += source.totalThreeRenderingTime; | ||
return destination; | ||
}; | ||
|
||
export const getBasicProfilingCountersText = ( | ||
basicProfilingCounters: BasicProfilingCounters | ||
): string => { | ||
const texts = []; | ||
texts.push( | ||
`Instances update count: ${ | ||
basicProfilingCounters.totalInstancesUpdateCount | ||
}` | ||
); | ||
texts.push( | ||
`Instances update time: ${basicProfilingCounters.totalInstancesUpdateTime.toFixed( | ||
2 | ||
)}ms` | ||
); | ||
texts.push( | ||
`Pixi rendering time: ${basicProfilingCounters.totalPixiRenderingTime.toFixed( | ||
2 | ||
)}ms` | ||
); | ||
texts.push( | ||
`Three rendering time: ${basicProfilingCounters.totalThreeRenderingTime.toFixed( | ||
2 | ||
)}ms` | ||
); | ||
texts.push( | ||
`Pixi UI rendering time: ${basicProfilingCounters.totalPixiUiRenderingTime.toFixed( | ||
2 | ||
)}ms` | ||
); | ||
texts.push(' '); | ||
for (const objectName in basicProfilingCounters.instanceCounters) { | ||
const instanceCounters = | ||
basicProfilingCounters.instanceCounters[objectName]; | ||
texts.push( | ||
`${objectName}: ${ | ||
instanceCounters.updateCount | ||
} updates, ${instanceCounters.totalUpdateTime.toFixed(2)}ms` | ||
); | ||
} | ||
|
||
return texts.join('\n'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// @flow | ||
import * as PIXI from 'pixi.js-legacy'; | ||
import { | ||
getBasicProfilingCountersText, | ||
type BasicProfilingCounters, | ||
} from './InstancesRenderer/BasicProfilingCounters'; | ||
|
||
export default class ProfilerBar { | ||
_profilerBarContainer: PIXI.Container; | ||
_profilerBarBackground: PIXI.Graphics; | ||
_profilerBarText: PIXI.Text; | ||
|
||
constructor() { | ||
this._profilerBarContainer = new PIXI.Container(); | ||
this._profilerBarContainer.alpha = 0.8; | ||
this._profilerBarContainer.hitArea = new PIXI.Rectangle(0, 0, 0, 0); | ||
this._profilerBarBackground = new PIXI.Graphics(); | ||
this._profilerBarText = new PIXI.Text('', { | ||
fontSize: 12, | ||
fill: 0xffffff, | ||
align: 'left', | ||
}); | ||
this._profilerBarContainer.addChild(this._profilerBarBackground); | ||
this._profilerBarContainer.addChild(this._profilerBarText); | ||
} | ||
|
||
getPixiObject(): PIXI.Container { | ||
return this._profilerBarContainer; | ||
} | ||
|
||
render({ | ||
basicProfilingCounters, | ||
display, | ||
}: {| | ||
basicProfilingCounters: BasicProfilingCounters, | ||
display: boolean, | ||
|}) { | ||
if (!display) { | ||
this._profilerBarContainer.visible = false; | ||
return; | ||
} | ||
|
||
this._profilerBarContainer.visible = true; | ||
const textPadding = 5; | ||
const profilerBarPadding = 15; | ||
const borderRadius = 6; | ||
const textXPosition = profilerBarPadding + textPadding; | ||
const textYPosition = profilerBarPadding + textPadding; | ||
|
||
this._profilerBarText.text = getBasicProfilingCountersText( | ||
basicProfilingCounters | ||
); | ||
this._profilerBarText.position.x = textXPosition; | ||
this._profilerBarText.position.y = textYPosition; | ||
|
||
const profilerBarXPosition = profilerBarPadding; | ||
const profilerBarYPosition = profilerBarPadding; | ||
const profilerBarWidth = this._profilerBarText.width + textPadding * 2; | ||
const profilerBarHeight = this._profilerBarText.height + textPadding * 2; | ||
|
||
this._profilerBarBackground.clear(); | ||
this._profilerBarBackground.beginFill(0x000000, 0.8); | ||
this._profilerBarBackground.drawRoundedRect( | ||
profilerBarXPosition, | ||
profilerBarYPosition, | ||
profilerBarWidth, | ||
profilerBarHeight, | ||
borderRadius | ||
); | ||
this._profilerBarBackground.endFill(); | ||
} | ||
} |
Oops, something went wrong.