Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added inline function analyzer #11

Merged
merged 3 commits into from
Nov 14, 2024
Merged

Added inline function analyzer #11

merged 3 commits into from
Nov 14, 2024

Conversation

alexcekay
Copy link
Member

Added an inline function analyzer to identify potential FLASH savings.

@alexcekay alexcekay requested a review from niklaut November 5, 2024 09:53
Copy link
Collaborator

@niklaut niklaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool tool!

Added my (cosmetic) review as a fixup commit:

  • Added dataclasses
  • Unprivated the __functions otherwise they wouldn't show in the docs.
  • Made all paths render as relative to CWD.

As a functional improvement I would recommend to add an integer (or float?) argument that describes the storage overhead of converting an inlined function into a non-inlined function. It would need at least a 16-bit branch instruction and probably also require moving around some registers. Perhaps best we just measure it for the largest candidate and then use that as an average number. I would assume that this gives a more realistic and smaller list of candidates (and filters out very small inlined functions).

Copy link
Collaborator

@niklaut niklaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is epic!

@niklaut
Copy link
Collaborator

niklaut commented Nov 14, 2024

Example output:

 $ python -m emdbg.analyze.inline -f build/px4_fmu-v6x_default/px4_fmu-v6x_default.elf --overhead 16

src/lib/conversion/rotation.h:161 -- Total Size: 4248 (3.55%) -- Total Size without instruction overhead: 4120 (14.85%)
                                                                  ╷                               ╷           ╷      ╷                           ╷
  Translation unit                                                │ File name                     │ File line │ Size │ Call instruction overhead │ %
 ═════════════════════════════════════════════════════════════════╪═══════════════════════════════╪═══════════╪══════╪═══════════════════════════╪═══════
  src/drivers/optical_flow/pmw3901/PMW3901.cpp                    │ src/lib/conversion/rotation.h │ 396       │ 482  │ 16                        │ 11.35
  src/modules/commander/mag_calibration.cpp                       │ src/lib/conversion/rotation.h │ 396       │ 274  │ 16                        │ 6.45
  src/modules/sensors/vehicle_optical_flow/VehicleOpticalFlow.cpp │ src/lib/conversion/rotation.h │ 396       │ 242  │ 16                        │ 5.70
  src/lib/drivers/magnetometer/PX4Magnetometer.cpp                │ src/lib/conversion/rotation.h │ 396       │ 298  │ 16                        │ 7.02
  src/lib/drivers/accelerometer/PX4Accelerometer.cpp              │ src/lib/conversion/rotation.h │ 380       │ 1046 │ 16                        │ 24.62
  src/lib/drivers/accelerometer/PX4Accelerometer.cpp              │ src/lib/conversion/rotation.h │ 396       │ 430  │ 16                        │ 10.12
  src/lib/drivers/gyroscope/PX4Gyroscope.cpp                      │ src/lib/conversion/rotation.h │ 380       │ 1046 │ 16                        │ 24.62
  src/lib/drivers/gyroscope/PX4Gyroscope.cpp                      │ src/lib/conversion/rotation.h │ 396       │ 430  │ 16                        │ 10.12
                                                                  ╵                               ╵           ╵      ╵                           ╵

src/lib/conversion/rotation.h:378 -- Total Size: 2672 (2.23%) -- Total Size without instruction overhead: 2640 (9.52%)
                                                     ╷                                                    ╷           ╷      ╷                           ╷
  Translation unit                                   │ File name                                          │ File line │ Size │ Call instruction overhead │ %
 ════════════════════════════════════════════════════╪════════════════════════════════════════════════════╪═══════════╪══════╪═══════════════════════════╪═══════
  src/lib/drivers/accelerometer/PX4Accelerometer.cpp │ src/lib/drivers/accelerometer/PX4Accelerometer.cpp │ 144       │ 1336 │ 16                        │ 50.00
  src/lib/drivers/gyroscope/PX4Gyroscope.cpp         │ src/lib/drivers/gyroscope/PX4Gyroscope.cpp         │ 143       │ 1336 │ 16                        │ 50.00
                                                     ╵                                                    ╵           ╵      ╵                           ╵

src/lib/world_magnetic_model/geo_mag_declination.cpp:69 -- Total Size: 2068 (1.73%) -- Total Size without instruction overhead: 2004 (7.22%)
                                                       ╷                                                      ╷           ╷      ╷                           ╷
  Translation unit                                     │ File name                                            │ File line │ Size │ Call instruction overhead │ %
 ══════════════════════════════════════════════════════╪══════════════════════════════════════════════════════╪═══════════╪══════╪═══════════════════════════╪═══════
  src/lib/world_magnetic_model/geo_mag_declination.cpp │ src/lib/world_magnetic_model/geo_mag_declination.cpp │ 125       │ 522  │ 16                        │ 25.24
  src/lib/world_magnetic_model/geo_mag_declination.cpp │ src/lib/world_magnetic_model/geo_mag_declination.cpp │ 113       │ 514  │ 16                        │ 24.85
  src/lib/world_magnetic_model/geo_mag_declination.cpp │ src/lib/world_magnetic_model/geo_mag_declination.cpp │ 107       │ 514  │ 16                        │ 24.85
  src/lib/world_magnetic_model/geo_mag_declination.cpp │ src/lib/world_magnetic_model/geo_mag_declination.cpp │ 125       │ 518  │ 16                        │ 25.05
                                                       ╵                                                      ╵           ╵      ╵                           ╵

src/lib/conversion/rotation.h:394 -- Total Size: 2016 (1.69%) -- Total Size without instruction overhead: 1936 (6.98%)
                                                                  ╷                                                                 ╷           ╷      ╷                           ╷
  Translation unit                                                │ File name                                                       │ File line │ Size │ Call instruction overhead │ %
 ═════════════════════════════════════════════════════════════════╪═════════════════════════════════════════════════════════════════╪═══════════╪══════╪═══════════════════════════╪═══════
  src/modules/commander/mag_calibration.cpp                       │ src/modules/commander/mag_calibration.cpp                       │ 785       │ 330  │ 16                        │ 16.37
  src/modules/sensors/vehicle_optical_flow/VehicleOpticalFlow.cpp │ src/modules/sensors/vehicle_optical_flow/VehicleOpticalFlow.cpp │ 276       │ 304  │ 16                        │ 15.08
  src/lib/drivers/magnetometer/PX4Magnetometer.cpp                │ src/lib/drivers/magnetometer/PX4Magnetometer.cpp                │ 72        │ 374  │ 16                        │ 18.55
  src/lib/drivers/accelerometer/PX4Accelerometer.cpp              │ src/lib/drivers/accelerometer/PX4Accelerometer.cpp              │ 117       │ 504  │ 16                        │ 25.00
  src/lib/drivers/gyroscope/PX4Gyroscope.cpp                      │ src/lib/drivers/gyroscope/PX4Gyroscope.cpp                      │ 117       │ 504  │ 16                        │ 25.00
                                                                  ╵                                                                 ╵           ╵      ╵                           ╵

@niklaut niklaut merged commit 677e7ef into main Nov 14, 2024
3 checks passed
@niklaut niklaut deleted the pr-inline-analyzer branch November 14, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants