how to count the revolution of motor

For whole rotations a simple magnet and hall sensor can count them. Or it can be done optically.