Most (all?) recently made graphics cards have shunt resistors specifically for measuring power (current) consumption and it is actually real time consumption. One of the ways that extreme overclockers (think, liquid nitrogen cooling) push cards harder is by 'power modding' them, by switching out the shunt resistors for smaller value resistors to trick the graphics card into thinking it is using less current than it actually is.
It's similar on CPUs, but the monitoring circuitry is internal, I think.
Turbostat uses RAPL data, as you can see by reading the source code you linked.
I mention this because as far as I'm aware it's impractical to actually measure energy directly. I'm fairly certain that all of these types of systems use estimate models - whether it's in software or firmware.