Taken by a sort of generalisation frenzy I produced the following; I tried to make it as readable as I could. Recall that the upper and lower Dini derivatives are respectively :
$$D^*f(x):=\limsup_{y\to x}\frac{f(y)-f(x)}{y-x}$$
$$D_*f(x):=\liminf_{y\to x}\frac{f(y)-f(x)}{y-x}.$$

**Theorem.** *Let $f:[a,b]\to \mathbb R$ be a continuous function with $D_*f\le0$ a.e. Then $$ f(b)-f(a)\le \big|f(\{D^*f=+\infty\})\big|$$*

In particular, if $D_*f\le0$ *a.e.* and $D^*f<\infty$ *everywhere*, applying this to every sub-interval one has that $f$ is decreasing.

The archeotypical example for this situation is the Cantor function, that has $f'(x)=0$ a.e. and $f(\{D^*f=+\infty\})=[f(0), f(1)]=[0,1]$, because $\{D^*f =+\infty\}$ is exactly the triadic Cantor set $C$. In general, the situation is slightly more complicated, but keeping this example in mind, we can construct, for given $\epsilon>0$, a Cantor set
$K= \bigcap_{n\ge0} K_n\subset \{D^*f=+\infty\}$ such that $\big|[f(a),f(b)]\setminus f(K)\big|\le \epsilon$. Here the sets $K_n$ are finite unions of closed intervals, or *pluriintervals*, inductively defined.

It is convenient to denote, for a pluriinterval $K\subset[a,b]$ with connected components $\big\{[\alpha_j,\beta_j]\big\}_{1\le j\le p}$, that is a disjoint union
$\displaystyle K:=\bigsqcup_{1\le j\le p} [\alpha_j,\beta_j]$, $$K^f: =\bigcup_{1\le j\le p} [f(\alpha_j),f(\beta_j)].$$ (Here $[x,y]=\emptyset$ if $x>y$). Note that $K^f\subset f(K)$ by continuity of $f$.

**Rmk.** In what follows it may be useful to recall the elementary $A\setminus C\subset B\Leftrightarrow A\subset B\cup C$.

For the proof we need a Lemma. In the same hypotheses of the Theorem we have

**Lemma.** *For every $\eta>0$, and for every pluriinterval $K\subset[a,b]$ there exists a pluriinterval $L \subset K $ such that $\big|K^f \setminus {L}^f\big|\le\eta$, and $\frac{f(\beta)-f(\alpha )}{\beta -\alpha }\ge\frac1\eta$ for every component $[\alpha,\beta]$ of $L$.*

**Proof of the Theorem.** We define inductively a nested sequence of pluriintervals $K_n$ where $K_0=[a,b]$ and for all $n\ge1$, $K_n$ is the pluriinterval $L$ given by the Lemma, corresponding to $K:=K_{n-1}$, and to the number $\eta:=\epsilon 2^{-n}$. We then define $K:=\bigcap_{n\ge0}K_n$ and $S:= \bigcup_{n\ge1} (K_{n-1}^f\setminus K_n^f)$, which is a set of measure $|S|\le\epsilon$ because for all $n$ we have $|K_{n-1}^f\setminus K_n^f|\le \epsilon 2^{-n}$ .

For every $n$ we have
$[f(a),f(b)]\setminus K_n^f= K_0^f\setminus K_n^f \subset S$, so $[f(a),f(b)]\setminus S\subset K_n^f\subset f(K_n)$ and then $[f(a),f(b)]\setminus S\subset \bigcap_{n\ge0} f(K_n)$ ; finally since $K_n$ is a decreasing sequence of compact sets and $f$ is continuous, $\bigcap_{n\ge0} f(K_n)= f\big( \bigcap_{n\ge0} K_n\big)=f(K)$. We thus have $[f(a),f(b)]\subset f(K)\cup S$ whence $$f(b)-f(a)\le |f(K)|+\epsilon$$

Note that each component interval of $K_n$ has length at most $ 2^{-n+1}\epsilon\|f\|_\infty $. So if $x\in K$, there is a sequence $x_n\in K_n$ of endpoints of components, such that $x_n\to x$ with $\frac{f(x)-f(x_n)}{x-x_n}\ge \frac{2^n}{\epsilon}$, that is $$K\subset \{D^*f=+\infty\}.$$

Since $\epsilon>0$ is arbitrary, the thesis follows.

**Rmk.** More precisely we have shown the inequality w.r.to the *inner* measure of the set $f( \{ D^*f=+\infty\})$, without addressing the issue of measurability of it. Incidentally, this is sufficient for the OP's needs. In fact $ \{ D^*f=+\infty\}$ is a $G_\delta$ set, and a continuous image of a $G_\delta$ set is even a Borel set, by a non-trivial result in Analytic Set Theory (I think for this case there is a direct simpler proof).

**Proof of the Lemma.** We first do the case $p=1$ and $K:=[a,b]$. The family of intervals $[\alpha,\beta]\subset(a,b)$ such that $\frac{f(\beta )-f(\alpha )}{\beta -\alpha }<\frac{\eta}{2(b-a)}$ cover the set $\{D_*f\le0\}$ in the Vitali sense, that is, every point of $\{D_*f\le0\}$ belongs to arbitrarily small such intervals. By the Vitali covering theorem, there is a finite disjoint family of these intervals whose sum of lengths is larger than $b-a -\frac{\eta^2}2$. Thus, labelling these intervals $[c_{2k-1},c_{2k}]$ for $k=1\dots n$, with a finite sequence $$c_0:=a<c_1<\dots <c_{2n+1}:=b$$ we have , for $k=1,\dots,n$

$$f(c_{2k})-f(c_{2k-1})\le \frac{\eta}{2(b-a)}(c_{2k}-c_{2k-1}) $$ and $$\sum_{k=0}^n(c_{2k+1}-c_{2k})=(b-a)- \sum_{k=1}^n(c_{2k}-c_{2k-1})\le \frac{\eta^2}2.$$
Let $$J:=\Big\{k\in \mathbb N:0\le k\le n,\, \frac{f(c_{2k+1})-f(c_{2k})}{c_{2k+1}-c_{2k}} \ge\frac1\eta\Big\}$$ and
$$L:=\bigcup_{k\in J} [c_{2k},c_{2k+1}]$$
Then we have

$$ [a,b]^f \setminus {L}^f\subset \bigcup_{ k\notin J}[c_{2k} , c_{2k+1}]^f\cup \bigcup_{1\le k\le n} [c_{2k-1} , c_{2k}]^f $$
so
$$\bigg|[a,b]^f \setminus {L}^f\bigg|\le \sum_{ k\not\in J}\big( f(c_{2k+1})-f(c_{2k})\big)_+ +\sum_{k=1}^{n}\big( f(c_{2k})-f(c_{2k-1})\big)_+ \le$$
$$ \le\sum_{ k=0}^n \frac1\eta \big( c_{2k+1}-c_{2k})+ \sum_{k=1}^{n}\frac{\eta}{2(b-a)}(c_{2k}-c_{2k-1})\le $$

$$\le \frac1\eta \frac{\eta^2}2+\frac{\eta}{2(b-a)}(b-a)=\eta,$$
so $L$ enjoyes the property we wished, for the case $K:=[a,b]$.

For the case of a general pluri-interval $\displaystyle K:=\bigsqcup_{1\le j\le p} [\alpha_j,\beta_j]$, we apply the preceding case $n=1$ to each component interval $ [\alpha_j,\beta_j]$ w.r.to the number $2^{-j}\eta$ and take $L$ to be the union of the corresponding pluriintervals $L_j\subset [\alpha_j,\beta_j]$, for $j=1,\dots p$. Then $$ K^f \setminus {L}^f = \bigcup_{1\le j\le p} \big([\alpha_j,\beta_j]^f \setminus {L}^f\big) \subset \bigcup_{1\le j\le p} \big( [\alpha_j,\beta_j] ^f\setminus {L_j}^f\big) $$ has measure
$$\bigg|K^f \setminus {L}^f\bigg|\le\sum_{1\le j\le p} \big| [\alpha_j,\beta_j] ^f\setminus {L_j}^f\big| \le \sum_{j=1}^p 2^{-j}\eta<\eta,$$
completing the proof.

6more comments