By means of a time-of-flight technique, we measured the longitudinal profile of prompt $gamma$-rays emitted by 73 MeV/u $^{13}$C ions irradiating a PMMA target. This technique allowed us to minimize the shielding against neutrons and scattered $gamma$-rays, and to correlate prompt gamma emission to the ion path. This correlation, together with a high counting rate, paves the way toward real-time monitoring of the longitudinal dose profile during ion therapy treatments. Moreover, the time correlation between the prompt gamma detection and the transverse position of the incident ions measured by a beam monitor can provide real-time 3D control of the irradiation.