@@ -351,29 +351,47 @@ Refer to script canvas example below:
351
351
This gem provides a tool to collect statistics in the game mode of the FPS, CPU and GPU into ` csv ` file.
352
352
353
353
The Profiler has a EBus which can control profiling in runtime (start/stop/reset), save profiled data, change save path, access current frame memory data or fps (avg, min, max).
354
- It is also provided with a set of notification functions, making it highly customizable for end user.
354
+ It is also provided with a set of notification functions, making it highly customizable for end user.
355
+ This functionality can be accessed in c++, lua and script canvas.
356
+
357
+ > * To start using the tool, add a ` FPSProfiler ` to the ** Level** entity.*
355
358
356
359
![ FpsProfiler Editor] ( doc/FpsProfiler.png )
357
360
358
- | Variable Name | Description |
359
- | ----------------------------| ----------------------------------------------------------------------------------------------------|
360
- | ** Csv Save Path** | Path where collected data will be saved. |
361
- | ** Auto Save** | Enable to auto save. Auto save is performed when target defined variable is reached. |
362
- | ** Auto Save At Frame** | Auto saves collected data at selected frame occurrence. |
363
- | ** Timestamp** | Applies timestamp Year-Month-Day-Hour-Minutes to file name. Let's you save multiple files at once. |
364
- | ** Near Zero Precision** | Floating point precision when comparing to 0. |
365
- | ** Save FPS Data** | Save collected FPS statistics. |
366
- | ** Save CPU Data** | Save collected CPU statistics. |
367
- | ** Save GPU Data** | Save collected GPU statistics. |
368
- | ** Show FPS** | Show the FPS value in the left-top corner. |
369
- | ** Profile On Game Start** | Start profiling data at once into csv file, after entering game mode. |
370
-
371
- ## Setup
372
- To start using the tool, add a ` FPSProfiler ` to the ** Level** entity.
373
-
374
- ### Profiling data using API Interface:
361
+ | File Save Settings | Description |
362
+ | ----------------------| ----------------------------------------------------------------------------------------------------------------|
363
+ | Select Csv File Path | Button that opens a File Dialog. |
364
+ | Csv Save Path | A path where * .csv will be saved. |
365
+ | Auto Save | Enables automatic saving of FPS logs per frame. |
366
+ | Auto Save At Frame | Specifies the frame interval for auto-saving. |
367
+ | Timestamp | Includes timestamps in the FPS log file name.</br >Allows to save automatically without manual input each time. |
368
+
369
+ | Recording Settings | Description |
370
+ | ------------------------| ----------------------------------------------------------------------------------------------------------------------|
371
+ | Record Type | Specify when to start recording:</br >- at game start</br >- selected frame</br >- await for other system to call start |
372
+ | Frames To Skip | Number of frames to skip before recording. Only enabled when type is ` SelectFrame ` . |
373
+ | Frames To Record | Total number of frames to record. If set to 0 - unlimited. |
374
+ | Record Stats | Specifies what type of stats to record (FPS data, CPU and GPU). |
375
+
376
+ | Precision Settings | Description |
377
+ | ------------------------| --------------------------------------------------------------------------------------------------------|
378
+ | Near Zero Precision | Precision threshold for near-zero values. |
379
+ | Moving Average Type | Type of moving average used for smoothing average FPS:</br >- Simple</br >- Exponential |
380
+ | Alpha Smoothing Factor | Factor applied to control smoothing effect when ` Exponential ` enabled. |
381
+ | Keep History | Keeps a history of recorded FPS data or clear after every auto-save. For better effect - keep enabled. |
382
+
383
+ | Debug Settings | Description |
384
+ | ------------------------| -----------------------------------------|
385
+ | Print Debug Info | Displays debug information in the logs. |
386
+ | Show FPS | Enables FPS display on screen. |
387
+ | Debug Color | Color used for debugging FPS display. |
388
+
389
+ ## API Access
390
+ Example workflows how to access and use a Fps Profiler Events and Notifications.
391
+
392
+ ### In C++:
375
393
``` c++
376
- // Get Interface and validate it
394
+ // Example with Interface
377
395
auto profiler = FPSProfiler::FPSProfilerInterface::Get();
378
396
if (!profiler)
379
397
{
@@ -382,24 +400,92 @@ if (!profiler)
382
400
383
401
profiler->StartProfiling ();
384
402
float currentFps = profiler->GetCurrentFps ();
385
- ```
386
403
387
- ### Profiling data using API Broadcast:
388
- ``` c++
389
- // Start profiling
390
- FPSProfilerRequestBus::Broadcast (&FPSProfilerRequests::StartProfiling);
404
+ // Example with Broadcast
405
+ float avgFPS = 0 .0f ;
406
+ FPSProfilerRequestBus::BroadcastResult (avgFPS, &FPSProfilerRequests::GetAvgFps);
407
+ FPSProfilerRequestBus::Broadcast(&FPSProfilerRequests::StopProfiling);
408
+
409
+ // Notification Bus - override from FPSProfilerNotificationBus::Handler
410
+ // class YourClass : protected FPSProfilerNotificationBus::Handler
391
411
392
- // Retrieve FPS using the request bus
393
- float currentFps = 0.0f;
394
- FPSProfilerRequestBus::BroadcastResult(currentFps, &FPSProfilerRequests::GetCurrentFps);
412
+ void OnProfileStart(const Configs::FileSaveSettings& config) override
413
+ {
414
+ // Your logic ...
415
+ }
395
416
```
396
417
397
- ## CSV File Example
398
- | Frame | FrameTime | CurrentFPS | MinFPS | MaxFPS | AvgFPS | CpuMemoryUsed | CpuMemoryReserved | GpuMemoryUsed | GpuMemoryReserved |
399
- |-------|-----------|------------|--------|--------|--------|---------------|-------------------|---------------|--------------------|
400
- | 1 | 0.3943 | 2.54 | 2.54 | 2.54 | 2.54 | 2166.44 | 237568 | 3756.19 | 6930.19 |
401
- | 2 | 0.1643 | 6.09 | 2.54 | 6.09 | 4.31 | 2182.99 | 237568 | 4126.19 | 6928.12 |
402
- | 3 | 0.1150 | 8.69 | 2.54 | 8.69 | 5.77 | 2183.49 | 237568 | 3134.19 | 6928.69 |
403
- | 4 | 0.0203 | 49.33 | 2.54 | 49.33 | 16.66 | 2181.58 | 237568 | 2654.19 | 6928.69 |
404
- | 5 | 0.0282 | 35.46 | 2.54 | 49.33 | 20.42 | 2181.20 | 237568 | 2654.19 | 6928.69 |
418
+ ### In Lua
419
+ ```shell
420
+ -- Table to hold our script functions
421
+ local profilerScript = {}
422
+
423
+ -- Function called when profiling starts
424
+ function profilerScript:OnProfileStart(config)
425
+ Debug.Log("Profiling started. Stopping in 60 seconds...")
426
+
427
+ -- Start a 60-second timer before stopping profiling
428
+ self:StartTimer(60, function()
429
+ Debug.Log("Stopping profiling now...")
430
+ FPSProfilerRequestBus.Broadcast.StopProfiling()
431
+ end)
432
+ end
433
+
434
+ -- Function to start a timer
435
+ function profilerScript:StartTimer(delay, callback)
436
+ if self.timerEventId then
437
+ -- Prevent multiple timers from stacking
438
+ TickBus.Disconnect(self, self.timerEventId)
439
+ end
440
+
441
+ self.timerTimeRemaining = delay
442
+ self.timerCallback = callback
443
+ self.timerEventId = TickBus.Connect(self)
444
+ end
445
+
446
+ -- Tick event to track time
447
+ function profilerScript:OnTick(deltaTime, timePoint)
448
+ if self.timerTimeRemaining then
449
+ self.timerTimeRemaining = self.timerTimeRemaining - deltaTime
450
+ if self.timerTimeRemaining <= 0 then
451
+ -- Time is up, trigger callback and disconnect
452
+ if self.timerCallback then
453
+ self.timerCallback()
454
+ end
455
+ TickBus.Disconnect(self, self.timerEventId)
456
+ self.timerEventId = nil
457
+ end
458
+ end
459
+ end
460
+
461
+ -- Register as an FPSProfilerNotificationBus listener
462
+ function profilerScript:OnActivate()
463
+ FPSProfilerNotificationBus.Connect(self)
464
+ end
465
+
466
+ -- Cleanup when script is deactivated
467
+ function profilerScript:OnDeactivate()
468
+ FPSProfilerNotificationBus.Disconnect(self)
469
+
470
+ -- Disconnect timer if still active
471
+ if self.timerEventId then
472
+ TickBus.Disconnect(self, self.timerEventId)
473
+ end
474
+ end
475
+
476
+ -- Return the table so O3DE can use it
477
+ return profilerScript
478
+ ```
405
479
480
+ ### In Script Canvas
481
+ Example how to stop profiling after 60 seconds have passed in Script Canvas.
482
+ ![ FpsProfiler Editor] ( doc/FpsProfiler_ScriptCanvas.png )
483
+
484
+ ## Csv Output File - Example
485
+ | Frame | FrameTime | CurrentFPS | MinFPS | MaxFPS | AvgFPS | CpuMemoryUsed | CpuMemoryReserved | GpuMemoryUsed | GpuMemoryReserved |
486
+ | -------| -----------| -------------| --------| ---------| ---------| ----------------| --------------------| ----------------| --------------------|
487
+ | 1 | 0.0293 | 34.12 | 34.12 | 34.12 | 34.12 | 231.91 | 237568 | 691.44 | 7214 |
488
+ | 2 | 0.0054 | 185.53 | 34.12 | 185.53 | 37.11 | 232 | 237568 | 691.44 | 7214 |
489
+ | 3 | 0.005 | 199.2 | 34.12 | 199.2 | 40.32 | 231.95 | 237568 | 691.44 | 7214 |
490
+ | 4 | 0.0038 | 259.88 | 34.12 | 259.88 | 44.67 | 231.64 | 237568 | 691.44 | 7214 |
491
+ | 5 | 0.004 | 247.65 | 34.12 | 259.88 | 48.69 | 231.64 | 237568 | 691.44 | 7214 |
0 commit comments