In a modern car with electronic engine control, fuel injection, etc, the amount of engine power is always dependent on what the ECU is doing in response to the driver's control inputs like throttle position, brake pressure, etc. If the ECU also knows what gear you are in, it is straightforward to calculate whether you could produce the same amount of power more efficiently (i.e. with lower fuel burn) in a different gear. Automatic transmission cars have been doing that "calculation" for decades (originally with a simple mechanical "computer" instead of electronics), to decide when to shift gear.
The big thing that is missing from the systems I'm seen is the lack of situational awareness of what is going on outside the car, which is a severe limitation on the usefulness of the systems. You probably already know that following a line of traffic at a steady 30 mph on a level road is more fuel-efficient in 5th gear than in 2nd or 3rd, but what you can see through the windows might be telling you that 2nd or 3rd is a much better choice in the real world situation.