I prefer to give you some context for the problem as well as a source you can consult. [Since this is not an "answer" I expect few votes.]
Let $f:[a,b]\to[m,M]$ be a continuous function and, for each $m\leq y\leq M$ define $N_f(y)$ to be the number of elements in the level set $\{x\in [a,b]: f(x)=y\}$ [take $\infty$ if this set is not finite].
This function $N_f$ is called the Banach indicatrix of $f$.
Theorem [Banach] The Banach indicatix of a continuous function $f$ is measurable [even Borel measurable, in Baire class 2] and moreover $\int_m^M
N_f(y)\,dy$ is exactly equal to the total variation of $f$ on $[a,b]$.
In particular $N_f$ is integrable if and only if $f$ has bounded
variation.
Most real analysis texts will prove or mention this at least. I like this source for the theorem and its proof: Natanson, Theory of Functions of a Real Variable, Vol. I, p.225. See also Saks, Theory of the Integral, p. 280 for a simliar proof.
The original source: S. Banach, Sur les lignes rectifiables et les surfaces dont l'aire et finie. Fund. Math. 7, 225-237 (1925)