Resource Profiling and FPS Tracking
Kano provides classes for monitoring system resource usage (CPU and RAM) and tracking frames per second (FPS). The following classes are included:
- FPSCounter: A class that tracks frames per second (FPS) for a given application.
- ResourceProfiler: A class that monitors system resource usage (CPU and RAM) at regular intervals and optionally logs the data to a CSV file.
- FPSProfiler: A subclass of
ResourceProfiler
that also tracks FPS and logs it along with CPU and RAM usage.
kano.lab.profiler.FPSCounter
Source code in kano\lab\profiler.py
__init__(start_when_init=True, fps_print_cycle=None, prefix_fps_print='')
Initializes the FPSCounter instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_when_init |
bool
|
Whether to start counting FPS immediately upon initialization. |
True
|
fps_print_cycle |
float or None
|
The interval (in seconds) at which FPS will be printed. |
None
|
prefix_fps_print |
str
|
A prefix string to include in the FPS print statement. |
''
|
Source code in kano\lab\profiler.py
get_fps()
Get the current FPS (frames per second).
Calculates FPS as the total number of frames divided by the elapsed time.
Returns:
Name | Type | Description |
---|---|---|
float |
The calculated FPS, or 0 if the counter has not started. |
Source code in kano\lab\profiler.py
keep_target_fps(target_fps)
Ensure the FPS stays below or at the target FPS by adjusting the sleep time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_fps |
float
|
The target FPS to maintain. |
required |
Source code in kano\lab\profiler.py
start()
Resets the FPS counter and starts the time tracking.
Initializes the start time and sets the total frame count to 0.
update()
Updates the FPS counter by incrementing the frame count and optionally printing the FPS.
If the frame count exceeds 1,000,000, the counter is reset.
If fps_print_cycle
is set, the FPS is printed at the specified interval.
Source code in kano\lab\profiler.py
kano.lab.profiler.ResourceProfiler
Source code in kano\lab\profiler.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
__init__(interval_seconds, pid=None, csv_path=None, csv_minutes=5)
Initializes the ResourceProfiler instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval_seconds |
float
|
The interval in seconds between each resource update. |
required |
pid |
int or None
|
The process ID to monitor, or None to monitor the current process. |
None
|
csv_path |
str or None
|
Path to a CSV file to save resource data, or None to skip saving. |
None
|
csv_minutes |
int
|
The number of minutes of data to retain in the CSV file. |
5
|
Source code in kano\lab\profiler.py
get_current_info()
Get the current process resource usage (CPU and RAM).
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing the current timestamp, CPU usage percentage, and RAM usage in MiB. |
Source code in kano\lab\profiler.py
start_profiling_thread()
Start a separate thread for continuous resource profiling.
The thread runs the _profiling
method to collect and display resource usage.
Source code in kano\lab\profiler.py
update()
Update the resource usage information and optionally print it.
If the interval has elapsed, the current CPU and RAM usage will be printed. If a CSV path is specified, the data will be written to the CSV file.
Source code in kano\lab\profiler.py
update_csv(current_time, cpu_percent, ram_mib)
Update the CSV file with the current resource usage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_time |
float
|
The current timestamp. |
required |
cpu_percent |
float
|
The current CPU usage as a percentage. |
required |
ram_mib |
float
|
The current RAM usage in MiB. |
required |
Source code in kano\lab\profiler.py
kano.lab.profiler.FPSProfiler
Bases: ResourceProfiler
Source code in kano\lab\profiler.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
__init__(interval_seconds, pid=None, csv_path=None, csv_minutes=5, target_fps=None)
Initializes the FPSProfiler instance, extending ResourceProfiler to track FPS.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval_seconds |
float
|
The interval in seconds between each resource update. |
required |
pid |
int or None
|
The process ID to monitor, or None to monitor the current process. |
None
|
csv_path |
str or None
|
Path to a CSV file to save resource and FPS data. |
None
|
csv_minutes |
int
|
The number of minutes of data to retain in the CSV file. |
5
|
target_fps |
float or None
|
The target FPS to maintain. |
None
|
Source code in kano\lab\profiler.py
get_current_info()
Get the current resource usage and FPS.
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing the current timestamp, CPU usage percentage, RAM usage in MiB, and FPS. |
Source code in kano\lab\profiler.py
update()
Update the resource usage and FPS information, printing and saving to CSV if applicable.
If the interval has elapsed, the current CPU, RAM, and FPS usage will be printed. If a CSV path is specified, the data will be written to the CSV file. If a target FPS is defined, attempts to maintain the target FPS.
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing CPU usage percentage, RAM usage in MiB, and FPS. |
Source code in kano\lab\profiler.py
update_csv(current_time, cpu_percent, ram_mib, fps)
Update the CSV file with the current resource usage and FPS.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_time |
float
|
The current timestamp. |
required |
cpu_percent |
float
|
The current CPU usage as a percentage. |
required |
ram_mib |
float
|
The current RAM usage in MiB. |
required |
fps |
int
|
The current frames per second. |
required |