For $f: \mathbb R^n \to \mathbb R$ a locally integrable function, $\varepsilon \in (0, \infty)$, and $x \in \mathbb R^n$, define $I(f, \varepsilon, x)$ to be the averaged integral of $f$ over $B\_{\varepsilon} (x)$, the ball of radius $\varepsilon$ around $x$. That is,


$$I(f, \varepsilon, x) := \frac{1}{\mu(B\_\varepsilon (x))} \int\_{B\_\varepsilon (x)} f(y) \, dy$$


Define
$$
K(f, \varepsilon, x) :=
\begin{cases}
1 & \text{if }\; I(f, \varepsilon, x) > f(x),\\
-1 & \text{if }\; I(f, \varepsilon, x) < f(x),\\
0, &\text{if }\; I(f, \varepsilon, x) = f(x).\\
\end{cases}
$$


Finally, let
$$
H(f, \varepsilon, x) = \dfrac{1}{\varepsilon} \int\limits\_{(0, \varepsilon]} K(f, s, x) ds
$$


Intuitively, $H$ is the weighted average amount of time a function spends greater than (resp. less than) its value at a point, in an infinitesimal neighbourhood of said point.


**Question:** Let $f$ be a $C^2$ function. Is it true that $\lim\_{\varepsilon \to 0} H(f, \varepsilon, x)$ exists for almost every $x \in \mathbb R^n$?


**Remarks:**


1. A sample path of Brownian motion provides a counterexample in the $C^0$ case, as shown [here](https://mathoverflow.net/questions/358653/how-much-time-does-a-function-spend-above-or-below-its-average-value-around-a-po?rq=1). So $C^2$ is in some sense sharp.
2. The existence of the limit is immediate on the regions on which $f$ is super/sub-harmonic, as well as on the interior of the region on which $f$ is harmonic.



Does this "local time" type limit exist a.e. for $C^2$ functions?
Even $C^\infty$ isn't enough and even on $\mathbb R$. Take any nowhere dense compact set $A\subset\mathbb R$ of positive measure and set $f=0$ on $A$. Now let $I\_k$ be the complementary intervals to $A$ (ignore the two rays). Draw some positive bumps on the middle halves of $I\_1, I\_2,\dots I\_n$. If $n$ is large enough, then $K(f,s,x)$ will be $1$ on $[1/10,1]$ for all $x\in A$ and no sufficiently small in $C^0$ perturbation of $f$ will change that. However, the function is still identically $0$ in some small $\delta\_1$-neighborhood of $A$. Now draw some much smaller negative bumps still deep inside $I\_k$'s but closer to the endpoints on both sides. Then, using finitely many (but sufficiently many) intervals, you'll achieve that $K(f,s,x)=-1$ on $[\delta\_1/10,\delta\_1]$ for all $x\in A$ and, again, the property is stable and we still have $f=0$ in some $\delta\_2$-neighborhood of $A$. Then do it again and again alternating between positive and negative bumps.


