\section{Introduction}

\medskip

This paper aims at investigating traces of $BV$ functions and integration
by parts formulæ in metric measure spaces. The setting is given by a complete and separable metric measure  space $(\mathbb{X},d,\mu)$ endowed with a doubling measure $\mu$ and supporting a weak $(1,1)$--Poincar\'e inequality. We prove an integration by parts formula on sets of finite perimeter with some regularity; the idea is to use the notion of essential boundary and to define the rough trace of a $BV$ function on such boundary using its super-level sets.

Sets with finite perimeter in metric measure spaces were defined for instance in \cite{Mir} and studied by L. Ambrosio in \cite{A,A1}. The main fact we use is that for a set with finite perimeter, the perimeter
measure is a Hausdorff measure concentrated on its essential boundary, \cite{A1}. The notion of essential boundary
is good enough to perform the strategy given by V. Maz'ya in his book~\cite{Ma}; in the Euclidean case, the notion of reduced boundary was used and an integration by parts formula was proven. Also, the
continuity of the trace operator was investigated and equivalent conditions for such continuity were given. In the metric space setting we have so far no good notion of reduced boundary (except for the case of non-collapsed $\mathsf{RCD}(K,N)$ spaces, \cite{abs}), but for our aims the essential boundary suffices.

Properties of the trace operator have been recently investigated in \cite{LS} and sufficient conditions for the continuity of such operator were given in terms of a ``measure-density condition'' on the
boundary of the selected domain. We compare this notion of trace with the rough trace proving almost-everywhere equality of the two functions on the boundary.
In this way, two different characterizations of the trace values of a function with bounded variation are available, the two being equivalent.

\bigskip

The paper is organized as follows:

\medskip

In Section \ref{preliminaries} we review the basic tools of our analysis, namely the concept of a metric measure space $(\mathbb{X},d,\mu)$ equipped with a doubling measure and supporting a weak Poincar\'e inequality, the notions of $BV$ function and of Caccioppoli set, along with the fundamental results related to them, such as the Coarea Formula, the Isoperimetric Inequality and of course the remarkable Theorem by L. Ambrosio on the Hausdorff representation of the perimeter measure, \cite[Theorem 5.3]{A1}.

\smallskip

In Section \ref{roughtrace} we rewrite, after \cite{Ma}, the notion and the properties of the rough trace of $BV$ functions defined on an open domain $\Omega\subset\mathbb{X}$; in particular, we re-investigate the conditions under which a $BV$ function admits a summable rough trace and we consider the issue of the extendability of $u\in BV(\Omega)$ to the whole of $\mathbb{X}$. The latter part of the Section is then devoted to an integration by parts formula for functions of bounded variation in terms of a suitable class of vector fields, a formula which, as shown in Theorem \ref{gauss-green}, features implicitly the rough trace of $u\in BV(\Omega)$.

The topic of integration by parts formulæ, especially in connection with $BV$ functions and sets of finite perimeter, has been an object of interest for quite a few decades now. After the pioneering work of G. Anzellotti \cite{anz} in 1983, who introduced the class of \textit{divergence-measure vector fields} - namely, those vector fields whose distributional divergence is a finite Radon measure - to prove an integration by parts formula for $BV$ functions on domains with Lipschitz boundary, such research area has been flourishing again since the early 2000's, when several authors started devoting considerable attention to the subject, leading to notable applications to sets of finite perimeter in the Euclidean setting, namely, the validity of (generalized) Gauss-Green formulæ in terms of the normal traces of divergence-measure fields (see \cite{sil}, \cite{ctz}, and also the latest developments given in \cite{cp}).
More recently, the issue has been attacked also in less regular settings, like metric measure spaces, \cite{bps,bu,bcm,mms}, and stratified groups, \cite{cm}. In particular, in \cite{mms} the authors operated in the context of a doubling metric measure space equipped with Cheeger's differential structure \cite{ch} and satisfying a Poincar\'e inequality; in their analysis, they found the so-called \textit{regular balls} to be the appropriate class of domains where a certain integration by parts formula holds. The results of \cite{mms} were then reprised by \cite{bu} and later refined in \cite{bcm}; both these works rely on the differential structure developed in \cite{gi}, which allows to extend the previous analysis of \cite{mms} to the very abstract context of a metric measure space satisfying no specific structural assumptions, where \textit{regular domains}\footnote{See Remark \ref{rmk-gauss} for the definition of regular domains.} serve as a generalization of regular balls. In particular, \cite{bcm} specializes the discussion for $\mathsf{RCD}(K,\infty)$ spaces and $BV$ functions. Lastly, in the very recent paper \cite{bps}, a Gauss-Green formula for sets of finite perimeter was proven in the context of an $\mathsf{RCD}(K,N)$ space by means of Sobolev vector fields in the sense of \cite{gi}.

\smallskip

In Section \ref{comparison}, finally, we compare our approach with the results recently obtained in \cite{LS} about the trace operator for $BV$ functions defined by means of Lebesgue points. Our analysis eventually allows to find the optimal conditions to impose on the domain $\Omega$ in order to ensure the coincidence in the $\mathcal{S}^h$-almost everywhere sense - Theorem \ref{u-star-aplim} -  between the rough and the ``classical'' traces, $u^*(x)=\text{T}u(x)$.

\smallskip

Sections \ref{roughtrace} and \ref{comparison} extend and refine the results contained in \cite[Section 7.2]{bu}.

\bigskip

\section{Preliminaries}\label{preliminaries}

Throughout this paper, $(\mathbb{X},d,\mu)$ will be a complete and separable metric measure space equipped with a non-atomic, non-negative Borel measure $\mu$ such that $0<\mu\left(B_\rho(x)\right)<\infty$ for any ball $B_\rho(x)\subset\mathbb{X}$ with radius $\rho>0$ centered at $x\in\mathbb{X}$. By \textit{non-atomic} we mean that for every $x\in\mathbb{X}$ one has $\mu(\{x\})=0$.

We shall assume $\mu$ to be \textit{doubling}:
in other words, there exists a constant $c\ge1$ such that
\begin{equation}\label{doubling}
\mu(B_{2\rho}(x))\leq c \mu\left(B_\rho(x)\right),
\qquad \forall\, x\in \mathbb{X}, \forall \,\rho>0.
\end{equation}

The minimal constant appearing in \eqref{doubling} is called \textit{doubling constant} and will be denoted by $c_D$; $s\coloneqq\ln_2 c_D$ is the \textit{homogeneous
dimension} of the metric space $\mathbb{X}$
and it is known that the following
property holds,

\begin{equation}\label{hom-dim}
\frac{\mu(B_r(x))}{\mu(B_R(y))}
\geq \frac{1}{c^2_D} \left(
\frac{r}{R}\right)^s,
\end{equation}

for every $y\in\mathbb{X}$, $x\in B_R(y)$, and for every $0<r\le R<\infty$ (see for example \cite[Lemma 3.3]{bjorn}).

The Lebesgue spaces $L^p(\mathbb{X},\mu)$, $1\leq
p\leq \infty$ are defined in the obvious way, \cite{hkst};
since in a complete doubling metric measure space
balls are totally bounded, we can equivalently
set $L^p_{\rm loc}(\mathbb{X},\mu)$ to denote
the space of functions that belong to
$L^p(K,\mu)$ for any compact set $K$ or that
belong to $L^p(B_\rho(x_0),\mu)$ for any
$x_0\in \mathbb{X}$ and any $\rho>0$.

Given a Lipschitz function $f:\mathbb{X}\to \mathbb{R}$,
we define its \textit{pointwise Lipschitz constant} as

\[
{\rm Lip}(f)(x)=\limsup_{r\to 0}
\sup_{B_r(x)} \frac{|f(x)-f(y)|}{d(x,y)}.
\]

We assume that the space supports
a weak $(1,1)$--Poincar\'e inequality,
which means that there exist constants
$c_P>0, \lambda\geq1$ such that for any Lipschitz
function $f$
\begin{equation}\label{poincare}
\int_{B_\rho(x)} |f(y)-f_{B_\rho(x)}|
\mathrm{d}\mu(y)
\leq
c_P \rho \int_{B_{\lambda \rho}(x)}
|{\rm Lip}(f)(y)| \mathrm{d}\mu(y),
\end{equation}
where $f_E$ is the mean value
of $f$ over the set $E$, i.e. if
$\mu(E)\neq 0$
\[
f_E =\frac{1}{\mu(E)} \int_E f(y)\mathrm{d}\mu(y).
\]

We recall also the definition
of upper gradient; we say that
a Borel function $g:\mathbb{X}\to [0,+\infty]$
is an \textit{upper gradient} for a measurable
function $f$ if for any rectifiable Lipschitz
curve
$\gamma:[0,1]\to \mathbb{X}$ with endpoints $x,y\in\mathbb{X}$ we have that
\[
|f(x)-f(y)|\leq \int_\gamma g =
\int_0^1 g(\gamma(t)) \|\gamma'(t)\|
\mathrm{d}t
\]
where $\|\gamma'(t)\|={\rm Lip}(\gamma)(t)$.

\medskip

In what follows, we shall also need to quantify how ``dense'' is a set at a certain point of the space; then, the \textit{upper and lower $\mu$-densities}
of $E\subset\mathbb{X}$ at $x\in \mathbb{X}$ are given by

\[
\Theta^{*}_\mu(E,x)\coloneqq\limsup_{\rho\to 0}
\frac{\mu(E\cap B_\rho(x))}{\mu(B_\rho(x))},
\]
and
\[
\Theta_{*,\mu}(E,x)\coloneqq\liminf_{\rho\to 0}
\frac{\mu(E\cap B_\rho(x))}{\mu(B_\rho(x))}
\]

respectively. The common value between the two limits will be called the \textit{$\mu$-density} of $E$ at $x\in\mathbb{X}$, denoted by

\[
 \Theta_\mu(E,x)\coloneqq\underset{\rho\to 0}{\lim}\frac{\mu\left(E\cap B_\rho(x)\right)}{\mu\left(B_\rho(x)\right)}.
\]

When we work with the reference measure $\mu$ only and there is no ambiguity, we shall drop the suffix from the notation and the above will be simply referred to as the (upper, lower) \textit{density} of $E$ at $x$.

The left continuity of the maps $\rho\mapsto \mu(E\cap B_\rho(x))$
for any Borel set $E$ implies that the maps $x\mapsto \mu(E\cap B_\rho(x))$ are lower semicontinuous.
From this, one deduces that functions $\Theta^*(E,x)$ and
$\Theta_*(E,x)$ are Borel.

\medskip
Following the characterization given for instance in \cite[Definition 3.60]{afp}, for a Borel set $E\subset \mathbb{X}$ we shall denote by $E^{(t)}$, $t\in [0,1]$, the set of points where $E$ has density $t$, namely
\[
 E^{(t)}\coloneqq\left\{x\in\mathbb{X};\;\Theta(E,x)=\underset{\rho\to 0}{\lim}\frac{\mu\left(B_\rho (x)\cap E\right)}{\mu\left(B_\rho(x)\right)}=t\right\}.
\]

In particular, the sets $E^{(0)}$ and $E^{(1)}$ will be called the \textit{measure-theoretic} (or, \textit{essential}) \textit{exterior} and \textit{interior} of $E$, respectively.

\smallskip

The \textit{measure-theoretic} (or, \textit{essential}) \textit{boundary} of $E$ is then defined as

\begin{equation}\label{dstar}
\partial^*E \coloneqq \mathbb{X}
\setminus(E^{(0)}\cup E^{(1)}).
\end{equation}

Note that we could equivalently characterize $\partial^*E$ as the set of points $x\in\mathbb{X}$ where both $E$ and its complement $E^c$ have positive upper density.

\smallskip

The \textit{lower and upper approximate limits} of any measurable function $u:\mathbb{X}\to\mathbb{R}$ at $x\in\mathbb{X}$ are defined by

\begin{equation}\label{low-aplim}
u^{\wedge}(x)\coloneqq\sup\left\{t\in\overline{\mathbb{R}};\;\underset{\rho\to 0}{\lim}\frac{\mu\left(B_\rho(x)\cap E_t\right)}{\mu\left(B_\rho(x)\right)}=1\right\}
\end{equation}

and

\begin{equation}\label{up-aplim}
 u^{\vee}(x)\coloneqq\inf\left\{t\in\overline{\mathbb{R}};\;\underset{\rho\to 0}{\lim}\frac{\mu\left(B_\rho(x)\cap E_t\right)}{\mu\left(B_\rho(x)\right)}=0\right\}
\end{equation}

respectively, where for $t\in\mathbb{R}$, $E_t$ denotes the \textit{super-level sets} of the function $u$, namely
\[
 E_t\coloneqq\left\{x;\;u(x)\ge t\right\}.
\]
We observe that the density condition in \eqref{low-aplim}  is of course equivalent to ask that $\Theta(E_t^c,x)=0$.
The notion of approximate limits allows for the characterization of a \textit{jump set} of the function $u$:
\begin{equation}\label{jump}
 S_u\coloneqq\left\{x\in\mathbb{X};\;u^{\wedge}(x)<u^{\vee}(x)\right\}.
\end{equation}

So in particular, when $u=\mathds1_E$, one gets $S_u=\partial^*E$.

We also notice that if $u$ is bounded above and
$t>{\rm ess}\sup u$, then $\mu(E_t)=0$, hence
$u^\vee(x)\leq {\rm ess}\sup u$. In the same way, if
$u$ is bounded below, $u^\wedge(x)\geq{\rm ess} \inf u$.

\bigskip

Following \cite{A1,amp,Mir}, we now briefly recall the basic notions and properties of functions of bounded variation on metric measure spaces.
Given an open set $\Omega\subset\mathbb{X}$, we
define the \textit{total variation} of a measurable function
$u:\Omega\to \mathbb{R}$ by setting
\[
\|Du\|(\Omega)
=\underset{\mathcal{A}_u}{\inf}\left\{
\liminf_{j\to +\infty}
\int_{\Omega} {\rm Lip}(u_j)(y) \mathrm{d}\mu(y)
\right\},
\]
where
\[
 \mathcal{A}_u\coloneqq\left\{\left(u_j\right)_{j\in\mathbb{N}}\subset\mathrm{Lip}_{\mathrm{loc}}(\Omega),\;u_j\to u\:\mathrm{in}\:L^1_{\mathrm{loc}}(\Omega)\right\}.
\]

\medskip

\begin{definition}
Given $u\in L^1(\Omega)$, we say that
$u$ has bounded variation in $\Omega$, $u\in BV(\Omega)$,
if $\|Du\|(\Omega)<+\infty$. A set $E\subset \mathbb{X}$
is said to have finite perimeter in $\mathbb{X}$ if $\mathds1_E\in
BV(\mathbb{X})$, and similarly to have finite perimeter in $\Omega$ if $\mathds1_E\in BV(\Omega)$.
\end{definition}

\medskip

Sets of finite perimeter will be also referred to as \textit{Caccioppoli sets}.

A function $u\in BV(\Omega)$ defines a non-negative
Radon measure $\|Du\|$, the \textit{total variation measure}; when $u$ is the characteristic
function of some set $E$, $u=\mathds1_E$, then $\|D\mathds1_E\|$ is called \textit{perimeter measure}.

A very important tool for our work will be the \textit{Coarea
Formula}, \cite{Mir}; it asserts that for $u\in BV(\Omega)$, then
for almost every $t\in \mathbb{R}$ the set $E_t$ has
finite perimeter in $\Omega$ and for any Borel set $A$
\[
\|Du\|(A)=\int_\mathbb{R} \|D\mathds1_{E_t}\|(A)
\text{d}t.
\]

\medskip

The Poincar\'e inequality together with
the Sobolev embedding Theorem (see for
instance \cite{A1}, \cite{HK} or \cite{Mir}) imply the
following local isoperimetric inequality:
for any set $E$ with finite perimeter
and for any ball $B_\rho(x)$, we
have that

\begin{equation}\label{isoper}
\min\left\{
\mu(E\cap B_\rho),\mu(B_\rho\backslash E)
\right\}
\leq
c_I \left(
\frac{\rho^s}{\mu(B_\rho(x))}
\right)^{\frac{1}{s-1}}
\|D\mathds1_E\|\left(B_{\lambda\rho}(x)\right)^{\frac{s}{s-1}},
\end{equation}

where $c_I>0$ is known as the \textit{isoperimetric constant}.

\medskip

We also mention that a weaker version of the Poincar\'e inequality holds for $BV$ functions as well: given any ball $B_\rho(x)\subset\mathbb{X}$, for every $u\in BV(\mathbb{X})$ it holds

\begin{equation}\label{poincarebv}
 \int_{B_\rho(x)} \left|u-u_B\right|\text{d}\mu\le c_P\rho\|Du\|\!\left(B_{\lambda\rho}(x)\right).
\end{equation}

Of course, both in \eqref{isoper} and \eqref{poincarebv} the notation is the same as in \eqref{poincare}.

\medskip

Two important properties of the perimeter measure of Caccioppoli sets, which we shall use extensively, are its absolute continuity with respect to the spherical Hausdorff measure and its localization inside the essential boundary, \cite{A1}.

Let us denote by ${\cal S}^h$ the spherical Hausdorff measure defined in terms of the doubling function

\[
h(B_\rho(x))=\frac{\mu(B_\rho(x))}{{\rm diam} (B_\rho(x))}.
\]

\medskip

If $E\subset\mathbb{X}$ is a Caccioppoli set in $\mathbb{X}$, then we have the following

\medskip

\begin{thm}\label{locality}{\normalfont{\cite[Theorem 5.3]{A1}}} The measure $\|D\mathds1_E\|$ is concentrated on the set

\[
 \Sigma_\gamma = \left\{x:\;\underset{\rho\to 0}{\lim\sup}\min \left\{\frac{\mu\left(E\cap B_\rho(x)\right)}{\mu\left(B_\rho(x)\right)},\frac{\mu\left(E^c\cap B_\rho(x)\right)}{\mu\left(B_\rho(x)\right)}\right\}\ge\gamma\right\}\subset\partial^{*}E,
\]

where $\gamma=\gamma\left(c_D,c_I,\lambda\right)$. Moreover, $\mathcal{S}^h\left(\partial^{*}E\backslash\Sigma_\gamma\right)=0$, $\mathcal{S}^h\left(\partial^{*}E\right)<\infty$  and

\[
 \|D\mathds1_E\|(B)=\int_{B\cap\partial^{*}E}\theta_E\mathrm{d}\mathcal{S}^h
\]

for any Borel set $B\subset\mathbb{X}$ and for some Borel map $\theta_E:\mathbb{X}\to[\alpha,\infty)$ with $\alpha=\alpha\left(c_P,c_I,\lambda\right)>0$.

\end{thm}
\begin{flushright}
 $\square$
\end{flushright}

\begin{remark}\label{per-bound}
 We explicitly observe that by \cite[Theorem 4.6]{amp} one actually has $\theta_E\in [\alpha,c_D]$; thus, with the same notation as in Theorem \ref{locality}, we are given the bounds
\begin{equation*}
 \alpha\mathcal{S}^h(B\cap\partial^* E)\le \|D\mathds1_E\|(B)\le c_D\mathcal{S}^h(B\cap\partial^* E).
\end{equation*}
\end{remark}
\begin{flushright}
 $\blacksquare$
\end{flushright}

\begin{definition}\label{local-space}{\normalfont{\cite{amp}}} The space $(\mathbb{X},d,\mu)$ will be called \textit{local} if, given any two Caccioppoli sets $E,\Omega\subset\mathbb{X}$ with $E\subset\Omega$, one has that the maps arising from Theorem \ref{locality}, $\theta_E$ and $\theta_\Omega$, coincide $\mathcal{S}^h$-almost everywhere on $\partial^*\Omega\cap\partial^*E$.
 \end{definition}

\smallskip

\begin{remark}\label{bv-decomp}
 In \cite[Theorem 5.3]{amp}, it was proven that for any function $u\in BV(\Omega)$, $\Omega\subset\mathbb{X}$ open set, the total variation measure $\|Du\|$ admits a decomposition into an ``absolutely continuous'' and a ``singular'' part, and that the latter is decomposable into a ``Cantor'' and a ``jump'' part. In other words, the following holds:
 \begin{align*}
  \|Du\|(\Omega) & = \|Du\|^{\text{a}}(\Omega)+\|Du\|^{\text{s}}(\Omega) \\
  & = \|Du\|^{\text{a}}(\Omega)+\|Du\|^{\text{c}}(\Omega)+\|Du\|^{\text{j}}(\Omega) \\
  & = \int_{\Omega} \mathfrak{a}\, \text{d}\mu + \|Du\|^{\text{c}}(\Omega)+ \int_{\Omega\cap S_u}\int_{u^\wedge(x)}^{u^\vee(x)}\theta_{\{u\ge t\}}(x)\text{d}t\text{d}\mathcal{S}^h(x),
 \end{align*}
where $\mathfrak{a}\in L^1(\Omega)$ is the density of the absolutely continuous part, $\theta_{\{u\ge t\}}$ is given as in Theorem \ref{locality} and $S_u$ is the jump set as in \eqref{jump}.
\end{remark}
\begin{flushright}
 $\blacksquare$
\end{flushright}

\medskip

A further fact we shall use is the following
localization property: if $E\subset \Omega$ has finite
perimeter in an open set $\Omega$, then the function

\begin{equation}\label{defmE}
m_E(x,\rho):=\mu(E\cap B_\rho(x))
\end{equation}

is monotone non-decreasing as a function of $\rho$.
If it is differentiable at $\rho>0$, then

\begin{equation}\label{localization}
 \|D\mathds1_{E\cap B_\rho(x)}\|(\Omega)\le m'_E(x,\rho)+\|D\mathds1_E\|\left(\Omega\cap\overline{B}_\rho(x)\right).
\end{equation}

\medskip

The proof of \eqref{localization} follows by considering
a cut--off function
\[
\eta_h(y)=\frac{1}{h} \min\{\max\{\rho+h-d(x,y),0\},1\}
\]
and defining $u_h=\eta_h \mathds1_E$. Since

\[
\|Du_h\|(\Omega)\leq \frac{1}{h}\int_{
B_{\rho+h}(x)\backslash B_\rho(x)\cap \Omega}
\mathds1_E(y)\mathrm{d}\mu(y)
+\|D\mathds1_E\|\left(B_{\rho+h}(x)\cap \Omega\right),
\]

passing to the limit as $h\to 0$ and using the
lower semicontinuity of the total variation,
we get
\[
\|D\mathds1_{E\cap B_\rho(x)}\|(\Omega)\leq m'_E(x,\rho)+
\|D\mathds1_E\|\left(\overline{B}_\rho(x)\cap \Omega\right).
\]

If in particular $\|D\mathds1_E\|\left(\Omega\cap \partial
B_\rho(x)\right)=0$, we then get
\[
\|D\mathds1_{E\cap B_\rho(x)}\|\left(\partial B_\rho(x)\cap \Omega\right)
\leq m'_E(x,\rho).
\]

\bigskip

\section{Rough Trace}\label{roughtrace}
\medskip
In this section we extend the notion of
rough trace of a $BV$
function to the metric measure space setting.
The discussion will closely follow
the monograph by V. Maz'ya \cite[Section 9.5]{Ma}, whose results will be rephrased and re-proven accordingly;
in particular, we shall focus on the
issue of the integrability of rough
trace with respect to the perimeter measure
of the domain. We shall relate this issue
with some geometric properties
of the domain.

Below, $\Omega\subset\mathbb{X}$ shall always denote an open set.

We always write $\|D\mathds1_\Omega\|(\mathbb{X})<\infty$ to intend $\mathds1_\Omega\in BV(\mathbb{X})$, and similarly, when $E\subset\Omega$, $\|D\mathds1_E\|(\Omega)<\infty$ to intend $\mathds1_E\in BV(\Omega)$, that is, to signify that the sets are of finite perimeter in $\mathbb{X}$ and $\Omega$, respectively.

\medskip

\begin{definition}\label{rough-def}{\normalfont{(Rough Trace)}}
Given $u\in BV(\Omega)$, we
define its \textit{rough trace} at $x\in \partial \Omega$
as the quantity
\begin{equation}\label{rgh-tr}
u^{*}(x):=
\sup\Big\{ t\in\mathbb{R}:
\|D\mathds1_{E_t}\|(\mathbb{X})<\infty,\:x\in\partial^{*}E_{t}
\Big\}.
\end{equation}
\end{definition}

Of course, when $u$ has a limit value inside
$\Omega$ at $x\in\partial^{*}\Omega$, then

\[
u^{*}(x)=\lim_{\Omega\ni y\to x} u(y).
\]

\bigskip

\begin{remark} We esplicitly observe that according to \eqref{rgh-tr}, it might occur that $u^*(x)=-\infty$, which obviously corresponds to the case when
\[
\Big\{ t\in\mathbb{R}:
\|D\mathds1_{E_t}\|(\mathbb{X})<\infty,\:x\in\partial^{*}E_{t}
\Big\}=\emptyset.
\]

Moreover,  when we write $\partial^*E_t$
we shall always intend the essential boundary of $E_t$ in $\mathbb{X}$, not the relative essential boundary of $E_t$ in $\Omega$.
\end{remark}
\begin{flushright}
 $\blacksquare$
\end{flushright}

We start with the following result:

\smallskip

\begin{lemma}\label{Lemma31}
If $\|D\mathds1_\Omega\|(\mathbb{X})<\infty$ and $u\in BV(\Omega)$, then $u^{*}$ is ${\cal S}^{h}$-
measurable on $\partial^{*}\Omega$ and
\begin{equation}
{\cal S}^{h}\left(\left\{ x\in\partial^{*}\Omega;\:u^{*}(x)\ge t\right\} \right)={\cal S}^{h}\left(\partial^{*}\Omega\cap\partial^{*}E_{t}\right)\label{eq:2.1}
\end{equation}
for almost every $t\in\mathbb{R}$.
\end{lemma}

\begin{proof}
We fix a measurable set $I\subset \mathbb{R}$ such
that $|I|=0$ and $E_t$ has finite perimeter
for any $t\in \mathbb{R}\backslash I$. Let us also
fix $D\subset \mathbb{R}\backslash I$ countable and dense.
Then the set
\[
A_t=\{ x\in\partial^*\Omega: u^*(x)\ge t\}
=\bigcup_{t<s\in D} B_s
\]
with $B_s=\partial^*E_s\cap \partial^*\Omega$. Since
the sets $B_s$ and $\partial^*\Omega$
are Borel, $A_t$ is Borel and then $u^*$ is
a Borel function.

Now instead of \eqref{eq:2.1}, we shall prove
that for every $t\in\mathbb{R}\backslash I$ - except at most a countable set - it holds

\[
{\cal S}^{h}\Big(\left\{ x\in\partial^{*}\Omega;\:u^{*}(x)\ge t\right\} \triangle
(\partial^{*}E_{t}\cap \partial^*\Omega)\Big)=0,
\]

where $\triangle$ denotes the symmetric difference between two sets, $A\triangle B\coloneqq (A\backslash B)\cup(B\backslash A)$.

We define the Borel set $F_{t}\coloneqq
A_{t}\backslash B_{t}$.
If $x\in B_t$, the definition of $u^*$ implies that
$u^*(x)\ge t$ and then the inclusion
$B_t\subset A_t$ holds.
We then reduce ourselves to prove that ${\cal S}^{h}\left(F_{t}\right)=0$.
Since for $s<t$ we have that $E_t\subset E_s\subset \Omega$,
we also have that
\[
\frac{\mu(E_t\cap B_\rho(x))}{\mu(B_\rho(x))}
\leq
\frac{\mu(E_s\cap B_\rho(x))}{\mu(B_\rho(x))}
\leq
\frac{\mu(\Omega\cap B_\rho(x))}{\mu(B_\rho(x))},
\]
whence
\[
\Theta_*(E_t,x)\leq\Theta_*(E_s,x)\leq
\Theta^*(E_s,x)\leq \Theta^*(\Omega,x)
\]
and so the inclusion $B_t\subset B_s$ holds
true. From this we deduce that the sets $F_t$ are
disjoint; indeed if $s<t$,
\[
F_t\cap F_s=(A_t\backslash B_t)\cap
(A_s\backslash B_s)
=A_t\cap A_s \cap B_t^c\cap B_s^c
=A_t\cap B_s^c=A_t\backslash B_s=\emptyset
\]
since if $x\in A_t$ then there exists $\tau\in (t,u^*(x)]$ such that $x\in \partial^*E_\tau\cap \partial^*\Omega=B_\tau\subset B_s$.
The inclusion
$F_t\subset \partial^*\Omega$ then
implies that the set
\[
 \left\{t\in\mathbb{R}\backslash I;\:\mathcal{S}^h\left(F_t\right)>0\right\}
\]
is at most countable, and this concludes the proof.

\end{proof}

\medskip

The result below is simply a combination of Lemma~4 and Corollary~2 in \cite[Section 9.5]{Ma}, so we just state it with no proof:

\medskip

\begin{proposition}
For any $u\in BV(\Omega)$ and for ${\cal S}^{h}$-almost
every $x\in\partial^{*}\Omega$, one has
\[
-u^{*}(x)=\left(-u\right)^{*}(x).
\]
Consequently if we decompose $u=u^+-u^-$ in its positive
and negative part, then
\[
\left(u^{*}\right)^{+}=
\left(u^{+}\right)^{*},\qquad
\left(u^{*}\right)^{-}=\left(u^{-}\right)^{*}
\]
and then
\[
u^{*}=\left(u^{+}\right)^{*}-\left(u^{-}
\right)^{*}.
\]
\end{proposition}
\begin{flushright}
 $\square$
\end{flushright}

\smallskip

\begin{remark}\label{per-global}
Throughout the remainder of the paper, we shall always work in the hypothesis that $\Omega\subset\mathbb{X}$ is an open set with finite perimeter in $\mathbb{X}$, $\|D\mathds1_{\Omega}\|(\mathbb{X})<\infty$.

Moreover, $E\subset\Omega$ will always be a Caccioppoli set in $\Omega$, $\|D\mathds1_E\|(\Omega)<\infty$. We observe that, since in each of the next statements we shall assume $\partial\Omega\backslash\partial^*\Omega$ to be $\mathcal{S}^h$-negligible, this will imply that $\|D\mathds1_E\|(\mathbb{X})<\infty$ as well. Indeed, by Theorem \ref{locality}, $\|D\mathds1_\Omega\|(\mathbb{X})<\infty$ implies $\mathcal{S}^h(\partial^*\Omega)<\infty$, and therefore the condition $\mathcal{S}^h(\partial\Omega\backslash\partial^*\Omega)=0$ forces $\mathcal{S}^h(\partial\Omega)<\infty$; therefore, as $\|D\mathds1_E\|(\Omega)<\infty$, an application of \cite[Proposition 6.3]{kkst1} yields $\|D\mathds1_E\|(\mathbb{X})<\infty$ as claimed.

For the sake of clarity, we observe that we will always operate in the situation where $\partial^*E$ intersects $\partial^*\Omega$ and $\partial^*\Omega\backslash\partial^*E$ is non-empty.
\end{remark}
\begin{flushright}
 $\blacksquare$
\end{flushright}

In the next results, we will often make use of the following simple property of the rough trace:

\medskip

\begin{remark}\label{rough-bdry}
 Let $\Omega\subset\mathbb{X}$ be such that $\|D\mathds1_\Omega\|(\mathbb{X})<\infty$. If $E\subset\Omega$ is a Caccioppoli set in $\Omega$, then $\mathds1_E^*(x)=0$ for all $x\in\partial^*\Omega\backslash\partial^*E$ and $\mathds1_E^*(x)=1$ for all $x\in\partial^*\Omega\cap\partial^*E$.

Indeed, when considering the characteristic function of $E$ one of course has

\[
E_{t}=\left\{ x\in\Omega,\:\mathds1_{E}\ge t\right\} =\begin{cases}
\emptyset, & t>1\\
\Omega, & t\le0\\
\Omega\cap E=E, & t\in (0,1].
\end{cases}
\]
This means, obviously,
\[
\partial^{*}E_{t}=\begin{cases}
\emptyset, & t>1\\
\partial^{*}\Omega, & t\le0\\
\partial^{*}\left(\Omega\cap E\right)=\partial^{*}E, & t\in (0,1].
\end{cases}
\]

So, when $t\in(0,1]$, the definition of rough trace \eqref{rgh-tr} forces $\mathds1_E^*(x)=1$ for every $x\in\partial^*E$.

Let us then assume $t\le0$; again by \eqref{rgh-tr}, in order to have $x\in\partial^*E_t=\partial^*\Omega$, it must be $\mathds1_E^*(x)=0$ for every $x$ therein. Thus, combining with the conclusion right above, as $\partial^*E$ intersects $\partial^*\Omega$, we infer that $\mathds1_E^*(x)=0$ for all $x\in\partial^*\Omega\backslash\partial^*E$ and $\mathds1_E^*(x)=1$ for all $x\in\partial^*\Omega\cap\partial^*E$, proving the claim.
\begin{flushright}
 $\blacksquare$
\end{flushright}
\end{remark}

\smallskip

With these preliminary facts at our disposal, we can start discussing the summability of the rough trace.

\medskip

\begin{thm}
Let $\left\Vert D\mathds1_{\Omega}\right\Vert ({\mathbb{X}})<\infty$
and assume ${\cal S}^{h}\left(\partial\Omega\backslash\partial^{*}\Omega\right)=0$.
In order for any $u\in BV(\Omega)$ to satisfy

\begin{equation}\label{inf-l1-rough}
\inf_{c\in \mathbb{R}}
\int_{\partial\Omega}\left|u^{*}(x)-c\right|\mathrm{d}{\cal S}^{h}(x)\le k\left\Vert Du\right\Vert (\Omega)
\end{equation}

with $k>0$ independent of $u$, it is necessary and sufficient that the inequality

\begin{equation}\label{min-per}
\min\left\{\|D\mathds1_E\|\left(\Omega^c\right), \|D\mathds1_{\Omega\backslash E}\|\left(\Omega^c\right)\right\}
\le
k \|D\mathds1_E\|\left(\Omega\right)
\end{equation}

holds for any $E\subset\Omega$ with finite perimeter in $\Omega$.
\end{thm}

\begin{proof}
We first observe that the constants $k$ in \eqref{inf-l1-rough} and \eqref{min-per} respectively need not be the same.

Let us start with necessity. Let $E\subset\Omega$ be
such that ${\displaystyle \left\Vert D\mathds1_{E}\right\Vert (\Omega)}<\infty$,
and apply Remark \ref{per-global}
to infer that $\|D\mathds1_E\|(\mathbb{X})<\infty$.
Then, since $\mathcal{S}^h (\partial\Omega\backslash\partial^*\Omega)=0$, by Remark \ref{rough-bdry} we get
\begin{equation*}
\underset{c\in\mathbb{R}}{\inf}\int_{\partial^{*}\Omega}\left|\mathds1_{E}^{*}(x)-c\right|\mathrm{d}{\cal S}^{h}(x) =\underset{c\in\mathbb{R}}{\min}\left\{ |1-c|{\cal S}^{h}\!\left(\partial^{*}E\cap\partial^{*}\Omega\right)+|c|{\cal S}^{h}\!\left(\partial^{*}\Omega\backslash\partial^{*}E\right)\right\}.
\end{equation*}
Now observe that the function
\begin{equation*}
 \Phi(c)\coloneqq |1-c|\mathcal{S}^h(\partial^*E\cap\partial^*\Omega)+|c|\mathcal{S}^h(\partial^*\Omega\backslash\partial^*E),
\end{equation*}
$c\in\mathbb{R}$, clearly attains its minima when $c=0$ and $c=1$ respectively, so we actually have
\begin{align*}
\underset{c\in\mathbb{R}}{\inf}\int_{\partial^*\Omega}\left|\mathds1_E^*(x)-c\right|\text{d} \mathcal{S}^h(x) & =\mathrm{min} \left\{ \mathcal{S}^h(\partial^{*}\Omega\cap\partial^*E), \mathcal{S}^h(\partial^{*}\Omega\backslash\partial^{*}E)\right\} \\
&\ge \frac{1}{c_D}\,\mathrm{min}\left\{\|D\mathds1_E\|(\Omega^c),\|D\mathds1_{\Omega\backslash E}\|(\Omega^c)\right\}
\end{align*}

by Remark \ref{per-bound}.

Since by hypothesis
\[
{\displaystyle \underset{c\in\mathbb{R}}{\inf}\int_{\partial\Omega}\left|\mathds1_{E}^{*}(x)-c\right|\mathrm{d}{\cal S}^{h}(x)\le k\left\Vert D\mathds1_E\right\Vert (\Omega),}
\]
we then obtain our claim.

We now pass to sufficiency.
Let $u\in BV(\Omega)$;
then for every $t$, ${\cal S}^{h}\left(\partial\Omega\cap\partial^{*}E_{t}\right)$
is a non-increasing function of $t$. In fact, if ${\displaystyle x\in\partial^{*}\Omega\cap\partial^{*}E_{t}}$
and $\tau<t$, then ${\displaystyle \Omega\supset E_{\tau}\supset E_{t}}$
and the same holds as well for the essential boundaries; moreover,
\[
\Theta^*(E_t,x)\le\Theta^*(E_\tau,x)\le\Theta^*(\Omega,x).
\]
This means, by hypothesis and by the definition of
essential boundary \eqref{dstar}, that ${\displaystyle x\in\partial^{*}\Omega\cap\partial^{*}E_{\tau}}$.
In a similar manner we can show that ${\displaystyle {\cal S}^{h}\left(\partial\Omega\backslash\partial^{*}E_{t}\right)}$
is a non-decreasing function of $t$.
By the Coarea Formula and by Remark \ref{per-bound},
\begin{align*}
k\left\Vert Du\right\Vert (\Omega)=&
k\int_{\mathbb{R}}\left\Vert D\mathds1_{E_{t}}\right\Vert (\Omega)\text{d}t\\
\ge&
k\alpha\int_{\mathbb{R}}\min\left\{ {\cal S}^{h}\left(\partial\Omega\cap\partial^{*}E_{t}\right),{\cal S}^{h}\left(\partial\Omega\backslash\partial^{*}E_{t}\right)\right\} \text{d}t.
\end{align*}
If we now set

\[\displaystyle t_{0}\coloneqq\sup\left\{ t;\:\left\Vert D\mathds1_{E_{t}}\right\Vert ({\mathbb{X}})<\infty,\:{\cal S}^{h}\left(\partial\Omega\cap\partial^{*}E_{t}\right)\geq{\cal S}^{h}\left(\partial\Omega\backslash\partial^{*}E_{t}\right)\right\},
\]

then we get, by recalling Lemma \ref{Lemma31},
\begin{align*}
k\left\Vert Du\right\Vert (\Omega) & \ge k\alpha\left(\int_{t_{0}}^{+\infty}{\cal S}^{h}\left(\partial\Omega\cap\partial^{*}E_{t}\right)\text{d}t+\int_{-\infty}^{t_{0}}{\cal S}^{h}\left(\partial\Omega\backslash\partial^{*}E_{t}\right)\text{d}t\right) \\
 & =k\alpha\left(\int_{t_{0}}^{+\infty}{\cal S}^{h}\left(\left\{ x;\:u^{*}(x)\ge t\right\} \right)\text{d}t+\int_{-\infty}^{t_{0}}{\cal S}^{h}\left(\left\{ x;\:u^{*}(x)\le t\right\} \right)\text{d}t\right) \\
{\displaystyle } & =k\alpha\left(\int_{\partial\Omega}\left[u^{*}(x)-t_{0}\right]^{+}\mathrm{d}{\cal S}^{h}(x)+\int_{\partial\Omega}\left[u^{*}(x)-t_{0}\right]^{-}\mathrm{d}{\cal S}^{h}(x)\right)\\
&=k\alpha\int_{\partial\Omega}\left|u^{*}(x)-t_{0}\right|\mathrm{d}{\cal S}^{h}(x).
\end{align*}
In other words,
\[
\frac{k}{\alpha}\left\Vert Du\right\Vert (\Omega)=k'\|Du\|(\Omega)\ge\underset{c\in\mathbb{R}}{\inf}\int_{\partial\Omega}\left|u^{*}(x)-c\right|\mathrm{d}{\cal S}^{h}(x).
\]
\end{proof}

\medskip

\begin{definition}\label{zeta-mazya}
Let ${\displaystyle A\subset\overline{\Omega}}$.
We shall denote by ${\displaystyle \zeta_{A}^{(\alpha)}}$ the infimum
of those $k>0$ such that ${\displaystyle \left[\left\Vert D\mathds1_{E}\right\Vert \left(\Omega^{c}\right)\right]^{\alpha}\le k\left\Vert D\mathds1_{E}\right\Vert (\Omega)}$
for all sets $E\subset\Omega$ which satisfy
the condition $\mu\left(E\cap A\right)+{\displaystyle \mathcal{S}^{h}\left(A\cap\partial^{*}E\right)}=0$.
\end{definition}

\medskip

\begin{thm}\label{rough-zeta}
Let $\left\Vert D\mathds1_{\Omega}\right\Vert ({\mathbb{X}})
<\infty$ and assume ${\cal S}^{h}\left(\partial\Omega
\backslash\partial^{*}\Omega\right)=0$.
Then, if $A$ is as in Definition \ref{zeta-mazya}, for every $u\in
BV(\Omega)$ such that ${\displaystyle u|
_{A\cap\Omega}=0}$ and ${\displaystyle u^{*}|_{A\cap
\partial^{*}\Omega}=0}$, then there is a constant $c>0$, depending on $\zeta^{(1)}_A$ and on $c_D$, such that
\[
{\displaystyle \int_{\partial\Omega}\left|u^{*}(x)\right|\mathrm{d}{\cal S}^{h}(x)\le c\left\Vert Du\right\Vert (\Omega)}.
\]
\end{thm}

\begin{proof}
We know that

\[
{\displaystyle \int_{\partial\Omega}\left|u^{*}(x)\right|
\mathrm{d}{\cal S}^{h}(x)=\int_{0}^{+\infty}
\left[{\cal S}^{h}\left(\left\{ x;\:u^{*}(x)\ge t\right\}
\right)+{\cal S}^{h}\left(\left\{ x;\:-u^{*}(x)\ge t
\right\} \right)\right]\text{d}t.}
\]

Notice that, by Lemma \ref{Lemma31} and Remark \ref{per-bound},

\begin{align*}
\int_{0}^{+\infty}{\cal S}^{h}\left(\{x;\;u^*(x)\ge t\}\right)
\text{d}t & = \int_0^{+\infty}\mathcal{S}^h(\partial^*\Omega\cap\partial^*E_t)\text{d}t \\ &\le \frac{1}{\alpha}\int_{0}^{+\infty}\left\Vert D\mathds1_{E_{t}}
\right\Vert \left(\Omega^{c}\right)\text{d}t \\ & \le \frac{\zeta^{(1)}_A}{\alpha}\int_0^{+\infty}\|D\mathds1_{E_t}\|(\Omega)\text{d}t,
\end{align*}

where we used the definition of $\zeta^{(1)}_A$ and the fact that, by our hypotheses, we get ${\displaystyle \mu\left(A\cap
E_{t}\right)+\mathcal{S}^{h}\left(A\cap\partial^{*}E_{t}
\right)}=0$
for almost every $t$.

Similarly, we find

\begin{align*}
\int_{0}^{+\infty}{\cal S}^{h}\left(
\left\{
x;\:-u^{*}(x)\ge t\right\} \right)\text{d}t
&\le
\frac{1}{\alpha}\int_{-\infty}^{0}
\left\Vert D\mathds1_{\Omega\backslash E_{t}}
\right\Vert \left(\Omega^{c}\right)\text{d}t\\
&\le
\frac{\zeta_{A}
^{(1)}}{\alpha}\int_{-\infty}^{0}\left\Vert D\mathds1_{E_{t}}
\right\Vert (\Omega)\text{d}t.
\end{align*}

Therefore, letting $c\coloneqq \dfrac{\zeta^{(1)}_A}{\alpha}$ gives the assertion.

\end{proof}

\medskip

\begin{remark}
 In particular, if we substitute $u$ with $\mathds1_{E}$, taking $E$ as in Definition \ref{zeta-mazya}, by Remark \ref{rough-bdry} we would simply have

\begin{align*}
 \|\mathds1_E^*(x)\|_{L^1(\partial\Omega,\mathcal{S}^h)}& =\int_{\partial\Omega}|\mathds1_E^*(x)|\text{d}\mathcal{S}^h(x) \\ & =\mathcal{S}^h(\partial^*\Omega\cap\partial^*E)\le \frac{1}{\alpha}\|D\mathds1_E\|(\Omega^c) \\ & \le \frac{\zeta^{(1)}_A}{\alpha}\|D\mathds1_E\|(\Omega)=c\|D\mathds1_E\|(\Omega),
\end{align*}

where we explicitly used the assumption $\mathcal{S}^h(\partial\Omega\backslash\partial^*\Omega)=0$.

\end{remark}
\begin{flushright}
 $\blacksquare$
\end{flushright}

The most important result of the present section is the following re-adaptation of \cite[Theorem 9.5.4]{Ma}:

\medskip

\begin{thm}\label{mazyathm}
Let $\Omega\subset\mathbb{X}$ be a bounded open set such that $\left\Vert D\mathds1_{\Omega}\right\Vert ({\mathbb{X}})<\infty$
and assume ${\cal S}^{h}\left(\partial\Omega\backslash\partial^{*}\Omega\right)=0$.
Then, every $u\in BV(\Omega)$ satisfies
\[
\left\Vert u^{*}\right\Vert _{L^{1}(\partial\Omega
,\mathcal{S}^h)}\le c\left\Vert u\right\Vert _{BV(\Omega)}
\]
with a constant $c>0$ independent of $u$,
if and only if there exists $\delta>0$ such that for
every $E\subset\Omega$ with $\mathrm{diam}(E)\le\delta$ and with $\left\Vert D\mathds1_{E}
\right\Vert (\Omega)<\infty$
there holds
\begin{equation}\label{per-compl}
\left\Vert D\mathds1_{E}\right\Vert \left(\Omega^{c}
\right)\le c'\left\Vert D\mathds1_{\text{E}}\right\Vert
(\Omega)
\end{equation}
for some constant $c'>0$ independent of $E$.
\end{thm}

\begin{proof}
We start by recalling that by Remark \ref{rough-bdry}, one has $\mathds1_E^*(x)=1$ on $\partial^*\Omega\cap\partial^*E$ and $\mathds1_E^*(x)=0$ on $\partial^*\Omega\backslash\partial^*E$. Therefore,
\[
\left\Vert \mathds1_{E}^{*}\right\Vert _{L^{1}(\partial\Omega)}=\int_{\partial\Omega}\mathds1_{E}^{*}(x)\mathrm{d}{\cal S}^{h}(x)={\cal S}^{h}\left(\partial^{*}\Omega\cap\partial^{*}E\right),
\]
since by hypothesis ${\cal S}^{h}\left(\partial\Omega\backslash\partial^{*}\Omega\right)=0$.

\medskip

Now, let $\rho>0$ to be fixed in the sequel; we claim that
there exists $0<\delta<\rho$ such that  for any $x_0\in \overline{\Omega}$
\[
\mu(B_\rho(x_0)\setminus B_\delta(x_0))
\ge \mu(B_\delta(x_0)).
\]
Assume  by contradiction that for any $\delta>0$
there exists $x_\delta\in  \overline{\Omega}$ such that
\[
\mu(B_\rho(x_\delta)\setminus B_\delta(x_\delta))
< \mu(B_\delta(x_\delta)).
\]
By taking $\delta=1/j$ we construct a  sequence
$(x_j)\subset  \overline{\Omega}$ such that
\[
\mu(B_\rho(x_j)\setminus B_{1/j}(x_j))
< \mu(B_{1/j}(x_j)).
\]
By the compactness of $\overline{\Omega}$, up to subsequences we
may assume $x_j\to x_0$. If we set
\[
\varepsilon_j=d(x_j,x_0),
\]
by the inclusions $B_{\rho-\varepsilon_j}(x_0)\setminus
B_{1/j+\varepsilon_j}(x_0)\subset B_\rho(x_j)\setminus B_{1/j}(x_j)$
and $B_{1/j}(x_j)\subset B_{1/j+\varepsilon_j}(x_0)$
we would find that
\[
\mu(B_{\rho-\varepsilon_j}(x_0)\setminus
B_{1/j+\varepsilon_j}(x_0))< \mu(B_{1/j+\varepsilon_j}(x_0)).
\]
Passing to the limit $j\to +\infty$
\[
\mu(B_\rho(x_0)\setminus\{x_0\})<\mu(\{x_0\}).
\]
Since $\mu$ is   non-atomic we  get a contradiction.

Let now $E\subset \Omega\cap B_\delta(x_0)$ be a
set with finite perimeter; then
\[
\mu(E)=\mu(E\cap B_\delta(x_0))
=\mu(E\cap B_\rho(x_0))
=\min\{ \mu(E\cap B_\rho(x_0)),\mu(B_\rho(x_0)\setminus E)\}.
\]
If we consider the estimate
\[
\| u^*\|_{L^1(\partial\Omega)}
\leq  c\| u\|_{BV(\Omega)}
\]
with $u=\mathds1_E$  we get
\[
\|\mathds1_E^*\|_{L^1(\partial\Omega)}
\leq c \Big(
\mu(E)+\|D\mathds1_E\|(\Omega)
\Big)
\]
Recall that under our hypotheses, $E$ has finite perimeter
also in $\mathbb{X}$ by Remark \ref{per-global}; therefore,
we also have the estimate
\[
\|D\mathds1_E\|(\Omega^c)=
\|D\mathds1_E\|(\partial \Omega)
\leq c_D \mathcal{S}^h(\partial^*\Omega\cap \partial^*E)
=c_D \|\mathds1_E^*\|_{L^1(\partial\Omega)}.
\]

Applying the Poincar\'e inequality for $BV$ functions,

\begin{align*}
\int_{B_{\rho}\left(x_{0}\right)}\left|\mathds1_{E}-\left(\mathds1_{E}\right)_{B_{\rho}\left(x_{0}\right)}\right|\text{d}\mu=&
\int_{B_{\rho}\left(x_{0}\right)}\left|\mathds1_{E}-\frac{\mu\left(E\cap B_{\rho}\left(x_{0}\right)\right)}{\mu\left(B_{\rho}\left(x_{0}\right)\right)}\right|\text{d}\mu \\
&\le c\rho\left\Vert D\mathds1_{E}\right\Vert \left(B_{\lambda\rho}\left(x_{0}\right)\right).
\end{align*}

Since $B_{\rho}\left(x_{0}\right)=E\cup\left(B_{\rho}\left(x_{0}\right)\backslash E\right)$,
computing the integral gives

\medskip{}

${\displaystyle \mu\left(E\cap B_{\rho}\left(x_{0}\right)\right)\left(1-\frac{\mu\left(E\cap B_{\rho}\left(x_{0}\right)\right)}{\mu\left(B_{\rho}\left(x_{0}\right)\right)}\right)+\frac{\mu\left(E\cap B_{\rho}\left(x_{0}\right)\right)}{\mu\left(B_{\rho}\left(x_{0}\right)\right)}\mu\left(B_{\rho}\left(x_{0}\right)\backslash E\right)=}$

\begin{align*}
 & =\frac{\mu\left(E\cap B_{\rho}\left(x_{0}\right)\right)}{\mu\left(B_{\rho}\left(x_{0}\right)\right)}\mu\left(B_{\rho}\left(x_{0}\right)\backslash E\right)+\frac{\mu\left(E\cap B_{\rho}\left(x_{0}\right)\right)}{\mu\left(B_{\rho}\left(x_{0}\right)\right)}\mu\left(B_{\rho}\left(x_{0}\right)\backslash E\right)\\
 & =2{\displaystyle \frac{\mu\left(E\cap B_{\rho}\left(x_{0}\right)\right)}{\mu\left(B_{\rho}\left(x_{0}\right)\right)}\mu\left(B_{\rho}\left(x_{0}\right)\backslash E\right)}\\
 & =2\mu\left(E\cap B_{\rho}\left(x_{0}\right)\right)\left(1-\frac{\mu\left(B_{\rho}\left(x_{0}\right)\cap E\right)}{\mu\left(B_{\rho}\left(x_{0}\right)\right)}\right).
\end{align*}

As $\mu\left(B_{\delta}\left(x_{0}\right)\right)\le\mu\left(B_{\rho}\left(x_{0}\right)\backslash B_{\delta}\left(x_{0}\right)\right)$,
again by the Poincar\'e inequality we get

\begin{align*}
\mu\left(E\cap B_{\rho}\left(x_{0}\right)\right) & \le2\mu\left(E\cap B_{\rho}\left(x_{0}\right)\right)\left(1-\frac{\mu\left(B_{\rho}\left(x_{0}\right)\cap E\right)}{\mu\left(B_{\rho}\left(x_{0}\right)\right)}\right)\\
 & \le c\rho\left\Vert D\mathds1_{E}\right\Vert \left(B_{\lambda\rho}\left(x_{0}\right)\right)\\
 & =c\rho\left\Vert D\mathds1_{E}\right\Vert ({\mathbb{X}})\\
 & =c\rho\left(\left\Vert D\mathds1_{E}\right\Vert (\Omega)+\left\Vert D\mathds1_{E}\right\Vert \left(\partial\Omega\right)\right)\\
 & =c\rho\left(\left\Vert D\mathds1_{E}\right\Vert (\Omega)+\left\Vert D\mathds1_{E}\right\Vert \left(\Omega^{c}\right)\right),
\end{align*}

which, by the estimate $\left\Vert D\mathds1_{E}\right\Vert \left(\Omega^{c}\right)\le c_D\left(\left\Vert D\mathds1_{E}\right\Vert \left(\Omega\right)+\mu(E)\right)$
previously found, entails

\begin{align*}
\left\Vert D\mathds1_{E}\right\Vert \left(\Omega^{c}\right) & \le c_D\left(\left\Vert D\mathds1_{E}\right\Vert (\Omega)+\mu\left(E\cap B_{\rho}\left(x_{0}\right)\right)\right)\\
 & \le c_D\left(\left\Vert D\mathds1_{E}\right\Vert (\Omega)+c\rho\left\Vert D\mathds1_{E}\right\Vert (\Omega)+c\rho\left\Vert D\mathds1_{E}\right\Vert \left(\Omega^{c}\right)\right)\\
 & =c_D\left(1+c\rho\right)\left\Vert D\mathds1_{E}\right\Vert \left(\Omega\right)+c_D\cdot c\rho\left\Vert D\mathds1_{E}\right\Vert \left(\Omega^{c}\right),
\end{align*}

whence

\[
\left\Vert D\mathds1_{E}\right\Vert \left(\Omega^{c}\right)\le c_D\frac{1+\rho}{1-c_D\cdot c\rho}\left\Vert D\mathds1_{E}\right\Vert (\Omega)=c'\left\Vert D\mathds1_{E}\right\Vert (\Omega),
\]

where we of course require $\rho<\frac{1}{c_D\cdot c}$.

Let us now show the reverse
implication; assume then that \eqref{per-compl} holds
for any finite perimeter set $E\subset\Omega$
with diameter less then $\delta$.
This in particular implies that, by Remark \ref{per-bound},
\begin{align*}
{\cal{S}}^h(\partial^*E\cap \partial^*\Omega)
\leq&\frac{1}{\alpha}\|D\mathds1_E\|\left(\partial^*\Omega\right)
=\frac{1}{\alpha}\|D\mathds1_E\|(\partial\Omega) \\
=&\frac{1}{\alpha}\|D\mathds1_E\|\left(\Omega^c\right)
\leq \frac{c'}{\alpha}\|D\mathds1_E\|(\Omega).
\end{align*}
Let us fix then $u\in BV(\mathbb{X})$ and assume
$u\geq 0$; by Lemma~\ref{Lemma31} and Cavalieri's Principle, we obtain that
\begin{equation}\label{firstEst}
\| u^*\|_{L^1(\partial\Omega,{\cal S}^h)}
=\int_0^\infty {\cal S}^h(\{x\in \partial^*\Omega:
u^*(x)\geq t\}) \mathrm{d}t
=\int_0^\infty
{\cal S}^h(\partial^* E_t\cap \partial^*\Omega) \mathrm{d}t.
\end{equation}

Take $t\in [0,\infty)$ such that $E_t$
has finite perimeter in $\Omega$ and set
$E=E_t$. We fix $r>0$ such that $2r<\delta$ and consider a covering of $\mathbb{X}$ made of balls of the type
$B_r(x_i)$, $i\in I\subset \mathbb{N}$
such that $B_{2r}(x_i)$ have
overlapping bounded by $c_o>0$.
We also select $r_i\in (r,2r)$
such that $m_E(x,\cdot)$ is differentiable at
$r_i$ and
\[
m_E'(x,r_i) \leq \frac{2 m_E(x,2r)}{r}.
\]
This is possible since
$\rho\mapsto m_E(x,\rho)$ is monotone non decreasing and
\[
\int_r^{2r} m'_E(x,\rho) \mathrm{d}\rho
\leq m_E(x,2r)-m_E(x,r)
\leq m_E(x,2r),
\]
so that

\[
\left\vert\left\{ t\in (r,2r): m'_E(x,t)>2\frac{m_E(x,2r)}{r}\right\}\right\vert
<\frac{r}{2}.
\]

We shall denote $B_i:=B_{r_i}(x_i)$.
Notice that for any set $E$, $\partial^*E \cap B_i
\subset \partial^*(E\cap B_i)$; indeed for any
$x\in E\cap B_i$, there exists $\rho_0>0$
such that $B_\rho(x)\subset B_i$ for any
$\rho<\rho_0$, hence

\[
\frac{\mu(E\cap B_i\cap B_\rho(x))}{
\mu(B_\rho(x))} =
\frac{\mu(E\cap B_\rho(x))}{
\mu(B_\rho(x))}.
\]

So, we have that

\[
{\cal S}^h(\partial^* E\cap \partial^*\Omega)
\leq \sum_{i\in I}
{\cal S}^h(\partial^* E\cap \partial^*\Omega\cap B_i)
\leq
\sum_{i\in I}
{\cal S}^h(\partial^* (E\cap B_i) \cap
\partial^*\Omega).
\]
From this, using \eqref{localization} and the fact that $r_i<\delta$,
by assumption,
\begin{align*}
\mathcal{S}^h(\partial^*E\cap \partial^*\Omega) &
\leq
\sum_{i\in I} \mathcal{S}^h
(\partial^*(E\cap B_i)\cap \partial^*\Omega)
\leq \frac{1}{\alpha}
\sum_{i\in I}\|D\mathds1_{E\cap B_i}\|\left(\partial^{*}\Omega\right)\\
& =
\frac{1}{\alpha}
\sum_{i\in I}\|D\mathds1_{E\cap B_i}\|\left(\Omega^c\right)
\leq
\frac{c'}{\alpha}
\sum_{i\in I}\|D\mathds1_{E\cap B_i}\|(\Omega)\\ &
\leq
\frac{c'}{\alpha}\sum_{i\in I}
\left(
m'_E(x_i,r_i)+\|D\mathds1_E\|(\Omega\cap\overline{B}_{r_i})
\right)\\ &
\leq
\frac{c'}{\alpha}
\sum_{i\in I}
\left(
\frac{m_E(x_i,2r)}{r}+\|D\mathds1_E\|(\Omega\cap B_{2r}(x_i))
\right) \\ &
\leq \frac{c'c_o}{\alpha} \left(
\mu(E\cap \Omega)+\|D\mathds1_E\|(\Omega)
\right).
\end{align*}
So, recalling that $E=E_t$, we have obtained the
estimate
\[
\mathcal{S}^h(\partial^* E_t\cap \partial^*\Omega)
\leq
\frac{c'c_o}{\alpha}
\left(
\mu(E_t\cap \Omega)+\|D\mathds1_{E_t}\|(\Omega)
\right).
\]
Integrating this inequality and using Coarea
formula we then conclude that
\[
\|u^*\|_{L^1(\partial\Omega, \mathcal{S}^h)}
\leq
\frac{c'c_o}{\alpha}
\Big(
\|u\|_{L^1(\Omega)}+\|Du\|(\Omega)
\Big).
\]
The general case $u\in BV(\Omega)$ can be
done by splitting $u=u^+-u^-$ into its
positive and negative part.

\end{proof}

\medskip

It is worth observing that the condition $\delta<\rho<\frac{1}{c_D\cdot c}$ found in the proof of Theorem \ref{mazyathm} tells us that the nature of this result is very local, as it holds at sufficiently small scales only.

\bigskip

We end this discussion by considering the issue of the extendability of a $BV$ function by a constant in terms of its rough trace; we first re-adapt the main arguments of \cite{Ma} and then discuss an alternative result for the zero-extension of a function $u\in BV(\Omega)$ to the whole of $\mathbb{X}$.

\medskip

\begin{definition}
Let $\Omega\subset\mathbb{X}$ be an open set and let $u\in BV(\Omega)$. We define its $\beta$\textit{-extension} to $\mathbb{X}$, $\beta\in\mathbb{R}$, by setting
\[
u_{\beta}(x)\coloneqq\begin{cases}
u(x), & x\in\Omega\\
\\
\beta, & x\in\Omega^{c}.
\end{cases}
\]
\end{definition}

We then have the following:

\medskip

\begin{lemma}\label{rough-ext} Assume $\Omega\subset\mathbb{X}$ is an open set such that $\|D\mathds1_{\Omega}\|(\mathbb{X})<\infty$ and $\mathcal{S}^h\left(\partial\Omega\backslash\partial^{*}\Omega\right)=0$. Let $\beta\in\mathbb{R}$ and $u\in BV(\Omega)$. Then, one has

\[
 \|Du_\beta\|(\mathbb{X})\le\|Du\|(\Omega)+c_D\|u^{*}-\beta\|_{L^1(\partial\Omega,\mathcal{S}^h)}.
\]

\end{lemma}

\begin{proof}
By Coarea, one obviously has
\[
 \|Du\|(\Omega)=\int_{\mathbb{R}} \|D\mathds1_{E_t}\|(\Omega)\text{d}t.
\]

Since any two functions differing by an additive constant have the same total variation, the following holds:
\begin{equation*}
 \|Du\|(\Omega)=\|D(u-\beta)\|(\Omega)=\int_\mathbb{R}\|D\mathds1_{\{u-\beta\ge t\}}(\Omega)\mathrm{d} t.
\end{equation*}
Therefore, when computing the total variation of $u_\beta$ on $\mathbb{X}$ one is obviously entitled to write
\begin{align*}
 \|Du_\beta\|(\mathbb{X}) & =\int_{\mathbb{R}}\|D\mathds1_{\{u_\beta -\beta\ge t\}}\|(\mathbb{X})\mathrm{d} t\\
 & =\int_\mathbb{R} \|D\mathds1_{\{u -\beta\ge t\}}\|(\Omega)\mathrm{d} t+\int_\mathbb{R}\|D\mathds1_{\{u -\beta\ge t\}}\|(\Omega^c)\mathrm{d} t\\
 & =\|Du\|(\Omega)+\int_\mathbb{R}\|D\mathds1_{\{u_{\beta} -\beta\ge t\}}\|(\partial\Omega)\mathrm{d} t\\&=\|Du\|(\Omega)+\int_\mathbb{R}\|D\mathds1_{\{u-\beta\ge t\}}\|(\partial\Omega)\mathrm{d} t.
\end{align*}
Let us then estimate the second term above; by the previous remarks we have

\medskip

$\displaystyle{\int_\mathbb{R} \|D\mathds1_{\{u -\beta\ge t\}}\|(\partial\Omega)\mathrm{d} t}$

$\displaystyle{=\int_{-\infty}^0\|D\mathds1_{\{u-\beta\le t\}}\|(\partial\Omega)\mathrm{d} t+\int_0^{+\infty}\|D\mathds1_{\{u-\beta\ge t\}}\|(\partial\Omega)}$

\smallskip

$\displaystyle{\le c_D\left(\int_{-\infty}^0\mathcal{S}^h(\{x,\:(u-\beta)^*(x)\le t\})\mathrm{d} t+\int_0^{+\infty}\mathcal{S}^h(\{x,\:(u-\beta)^*(x)\ge t)\})\mathrm{d} t\right)}$

\smallskip

$\displaystyle{=c_D\int_{\partial\Omega}|(u-\beta)^*|\mathrm{d}\mathcal{S}^h=c_D\int_{\partial\Omega}|u^*(x)-\beta|\mathrm{d}\mathcal{S}^h=c_D\|u^*-\beta\|_{L^1(\partial\Omega,\mathcal{S}^h)}},$

\bigskip

since of course $(u-\beta)^*(x)=u^*(x)-\beta$.

\end{proof}

\medskip

\begin{remark}
 It is clear that Lemma \ref{rough-ext} gives an upper bound for $\|Du_\beta\|(\mathbb{X})$, but without any further assumptions \textit{it does not allow to conclude that} $u_\beta \in BV(\mathbb{X})$. However, if we reformulate the statement in the hypotheses of Theorem \ref{mazyathm}, then it turns out that the zero-extension of $u\in BV(\Omega)$ to the whole of $\mathbb{X}$, $u_0$, has $BV$ norm $\|u_0\|_{BV(\mathbb{X})}$ bounded by the $BV$ norm of $u$ in $\Omega$. In other words, $u_0\in BV(\mathbb{X})$.
\end{remark}
\begin{flushright}
 $\blacksquare$
\end{flushright}

\smallskip

Actually, by assuming the function $u$ to be also essentially bounded, it is possible to get $u_0\in BV(\mathbb{X})$ under weaker hypotheses:

\medskip

\begin{proposition}\label{bv-ext} Assume $\Omega\subset\mathbb{X}$ is an open set such that $\|D\mathds1_\Omega\|(\mathbb{X})<\infty$ and
$\mathcal{S}^{h}\left(\partial\Omega\backslash\partial^{*}\Omega\right)$ $=0$;
let $E\subset\Omega$ be such that $\|D\mathds1_E\|(\Omega)<\infty$. Then, one has $\|D\mathds1_E\|(\mathbb{X})<\infty$.

Under the same assumptions, for any $u\in BV\cap L^\infty(\Omega)$
one has $u_0\in BV(\mathbb{X})$.
\end{proposition}

\begin{proof}

The first part of the statement can be actually seen as a particular case of \cite[Proposition 6.3]{kkst1}, so we refer to our previous Remark \ref{per-global} for more comments.

Let us take $u\in BV\cap L^\infty(\Omega)$ and let us start by first assuming
$u\geq 0$.
Then, since for any $t>0$
\[
\bar{E}_t\coloneqq\{ u_0\geq  t\} =\{x\in \Omega: u(x)\geq t\}=E_t,
\]
we obtain that
\begin{align*}
\left\Vert Du_0\right\Vert (\mathbb{X})=&
\int_0^\infty \|D\mathds1_{\{u_0\geq t\}}\| (\mathbb{X})\text{d}t=
\int_{0}^{+\infty}\left\Vert D{\mathds1}_{{E}_{t}}\right\Vert (\mathbb{X})\text{d}t\\
\le&
\int_{0}^{+\infty}\left[\left\Vert D\mathds1_{E_{t}}\right\Vert (\Omega)+c_D\,\mathcal{S}^{h}\left(\partial^{*}\Omega\cap\partial^{*}\bar{E}_{t}\right)\right]\text{d}t.
\end{align*}
Since $u\in L^\infty(\Omega)$, we can consider a Borel representative
of $u$ such that for any $t>\|u\|_\infty$, $E_t=\emptyset$; then
we obtain the estimate
\[
\|Du_0\|(\mathbb{X})\leq
\|Du\|(\Omega)+c_D  \mathcal{S}^h(\partial^* \Omega)  \|u\|_\infty,
\]
whence $u_0\in BV(\mathbb{X})$.

The general case $u\in BV\cap L^\infty(\Omega)$ follows by
considering the decomposition $u=u^+-u^-$ into its
positive and negative part.

\end{proof}

\smallskip

\begin{remark}\label{aplim-ext-bdd}
 We recall that in \cite[Lemma 3.2]{kkst2} it was proven that for any function $u\in BV(\mathbb{X})$ its approximate limits satisfy
 \[
  -\infty<u^\wedge(x)\le u^\vee(x)<\infty
 \]
for $\mathcal{S}^h$-almost every $x\in\mathbb{X}$.

Consequently, if we assume the hypotheses of Proposition \ref{bv-ext} to be satisfied, or if we re-state Lemma \ref{rough-ext} including the hypotheses of Theorem \ref{mazyathm}, we can conclude that
\[
-\infty<{u_0}^\wedge(x)\le{u_0}^\vee(x)<\infty
 \]
for $\mathcal{S}^h$-almost every $x\in\mathbb{X}$.
\end{remark}
\begin{flushright}
 $\blacksquare$
\end{flushright}

\subsection{An Integration by Parts Formula for
\texorpdfstring{$BV$}{BV} functions}

\bigskip

Summarizing the previous results, we can state that

\begin{equation*}
 \|D\mathds1_\Omega\|(\mathbb{X})<\infty\qquad\mathrm{and}\qquad\mathcal{S}^h\left(\partial\Omega\backslash\partial^*\Omega\right)=0
\end{equation*}

are the underlying conditions for the domain $\Omega$ which, thanks to Theorem \ref{mazyathm}, ensure that the rough trace $u^{*}(x)$
of any function $u\in BV(\Omega)$ is in $L^{1}\left(\partial\Omega,\mathcal{S}^h\right)$.

This conclusion motivates us, as already done in \cite{bu}, to proceed towards an integration by parts formula for functions of bounded variation by means of a suitable class of vector fields.

\smallskip

For the purpose, we shall refer to \cite{gi}, where the author constructs an $L^2$ theory of  \textit{differential forms} and \textit{vector fields} on metric measure spaces through the notions of $L^2$ \textit{cotangent and tangent modules}. These tools find their roots in the formalism of $L^p$\textit{-normed modules} also discussed in \cite{gi}, a class of objects which originates from the more abstract $L^\infty$\textit{ modules} previously considered by \cite{we}. We also mention that while \cite{gi} focuses on the $L^2$ theory only, a very straightforward generalization of this differential structure to any summability exponent $p\in [1,\infty]$ is contained in \cite{bu}.

This simple generalization allowed then in \cite{bcm} for a characterization of $BV$ functions by means of a familiar representation formula; namely, if $\Omega\subset\mathbb{X}$ is any open set and $u\in L^1(\Omega)$, then $u\in BV(\Omega)$ if its total variation

\begin{equation}\label{t-var-vec}
 \|Du\|(\Omega)\coloneqq\sup\left\{\int_{\Omega}u\div(F)\text{d}\mu;\;F\in\mathfrak{D}^\infty(\mathbb{X}),\:\text{supp}(F)\Subset\Omega,\:|F|\le1\right\}
\end{equation}

is finite. Here, by $\mathfrak{D}^\infty(\mathbb{X})$ we intend the class of vector fields $F\in L^\infty(T\mathbb{X})$ - the tangent module of essentially bounded vector fields - such that $\div(F)\in L^\infty(\mathbb{X})$. The idea behind this definition of $BV$ follows the same footsteps as the characterization given in \cite{di}, which relies on bounded Lipschitz derivations, and produces, however, a $BV$ space which a priori is larger than its analogous considered in \cite{di}, as $\mathfrak{D}^\infty(\mathbb{X})$ is into a one-to-one correspondence with a subset of the just-mentioned bounded Lipschitz derivations \cite[Section 3]{bcm}.

Of course, since in this sub-section we are going to deal with vector fields, it is more convenient to us to use the formalism of \cite{bcm}, whence the motivation of our choice.

We shall not discuss the tools and the ideas behind this characterization of $BV$ functions; in this respect, we limit ourselves to address the reader to the references already mentioned, namely \cite{ad,bu,bcm,ch,di,gi,we}.

\bigskip
\bigskip

The following Theorem was originally given in \cite{bu}; here we propose a refinement of that result.

Below, the notation $\text{d}u(F)$, $u\in BV(\Omega)$, is just the pairing measure which appears in the underlying definition of $BV$ functions we are currently using.

\bigskip

\begin{thm}\label{gauss-green}
Let $\Omega\subset\mathbb{X}$ be a bounded open
set such that $\left\Vert D\mathds1_{\Omega}\right\Vert ({\mathbb{X}})$ $<\infty$
and ${\cal S}^{h}\left(\partial\Omega\backslash\partial^{*}\Omega\right)=0$.
Then, for every $u\in BV(\Omega)$ and every $F\in\mathfrak{D}^\infty(\mathbb{X})$
one has

\[
\int_{\Omega}\mathrm{d}u(F)+\int_{\Omega}u\div(F)\mathrm{d}\mu=-\int_{{\partial^*\Omega}}\Theta^{F}(u^*(x))\mathrm{d}\mathcal{S}^h(x),
\]

where $\Theta^{F}(u^*(x))$ is clarified in \eqref{thetarough} below.
\end{thm}

\begin{proof}
To get things started, we remark that if $E\subset\Omega$ is a Caccioppoli set in $\Omega$,
then the pairing measure in the definition of $BV$ as given in \cite{bcm}, $\text{d}\mathds1_E(X)$, satisfies $\text{d}\mathds1_E(X)(\mathbb{X})=0$ (where $X$ is a vector field as in the definition of $BV$,  \eqref{t-var-vec}, and the claim holds as $X$ is compactly supported).

Now, observe that an integration by parts formula holds for the whole of ${\mathbb{X}}$,
namely

\[
\int_{{\mathbb{X}}}\text{d}u(F)=-\int_{{\mathbb{X}}}u\div(F)\text{d}\mu.
\]

Moreover, clearly,

\[
\int_{\Omega}\text{d}u(F)=\int_{\mathbb{X}}\text{d}u(F)-\int_{{\mathbb{X}}\backslash\Omega}\text{d}u(F)=-\int_{{\mathbb{X}}}u\div(F)\text{d}\mu-\int_{{\mathbb{X}}\backslash\Omega}\text{d}u(F).
\]

Suppose first that $u=\mathds1_E$ with $E\subset\Omega$ being a Caccioppoli set in $\Omega$. The previous
equalities become
\begin{align*}
\int_{\Omega}\text{d}\mathds1_{E}(F)= & -\int_{{\mathbb{X}}}\mathds1_{E}\div(F)\text{d}\mu-\int_{{\mathbb{X}}\backslash\Omega}\text{d}\mathds1_{E}(F) \\
& =-\int_{{\mathbb{X}}}\mathds1_{E}\div(F)\text{d}\mu-\int_{\partial\Omega\cap\partial^{*}E}\text{d}\mathds1_{E}(F).
\end{align*}

We used the locality property of the perimeter measure, which is concentrated on the essential boundary of $E$ by Theorem \ref{locality}; then,

\[
\text{d}\mathds1_E(F)(\Omega)=-\text{d}\mathds1_E(F)(\partial\Omega)=-\text{d}\mathds1_E(F)(\partial\Omega\cap\partial^*E).
\]

Let now $u\ge 0$ for simplicity; the proof for a general $u\in BV(\Omega)$ will follow by considering separately its positive and negative parts. Using Coarea Formula we obtain

\begin{align*}
\int_{\Omega}\text{d}u(F) & =\int_{0}^{+\infty}\text{d}t\int_{\Omega}\text{d}\mathds1_{E_{t}}(F)\\
 & =-\int_{0}^{+\infty}\text{d}t\left(\int_{{\mathbb{X}}}\mathds1_{E_{t}}\div(F)\text{d}\mu+\int_{\partial\Omega\cap\partial^{*}E_{t}}\text{d}\mathds1_{E_{t}}(F)\right).
\end{align*}

Above, we have used the fact that the pairing ${\displaystyle \text{d}\mathds1_{E}}(F)$ defines a measure which is absolutely continuous with respect to the perimeter
measure: indeed, setting

\[
\nu_{E}^{F}:\,A\mapsto\int_{A}\text{d}\mathds1_{E}(F)=\nu_{E}^{F}(A),
\]

one has ${\displaystyle \left|\nu_{E}^{F}\right|(A)\le\left\Vert F\right\Vert _{L^{\infty}(T{\mathbb{X}})}\left\Vert D\mathds1_{E}\right\Vert (A)}$
and then again by Theorem \ref{locality}

\[
\nu_{E}^{F}(A)=\int_{A}\sigma_{E}^{F}(x)\text{d}\left\Vert D\mathds1_{E}\right\Vert (x)=\int_{A\cap\partial^{*}E}\sigma_{E}^{F}\theta_{E}\text{d}\mathcal{S}^{h}(x).
\]

So, ${\displaystyle \text{d}\mathds1_{E}(F)=\sigma_{E}^{F}\theta_{E}\mathcal{S}^{h}\mrestr\partial^{*}E}$
and similarly ${\displaystyle \text{d}\mathds1_{\Omega}(F)=\sigma_{\Omega}^{F}\theta_{\Omega}\mathcal{S}^{h}\mrestr\,\partial^{*}\Omega}$.
Let us set

\begin{equation}\label{f-e-omega}
f_{E,\Omega}^F\coloneqq\frac{\sigma_{E}^{F}\theta_{E}}{\sigma_{\Omega}^{F}\theta_{\Omega}}=\frac{\lambda_{E}^{F}}{\lambda_{\Omega}^{F}}.
\end{equation}

Summing up, we find

$\displaystyle{\int_{\partial^{*}\Omega}\text{d}\mathds1_{E}(F)}$

\[
=\int_{\partial^{*}\Omega\cap\partial^{*}E}\lambda_{E}^{F}\text{d}\mathcal{S}^{h}(x)=\int_{\partial^{*}\Omega\cap\partial^{*}E}\lambda_{\Omega}^{F}\text{d}\mathcal{S}^{h}(x)=\int_{\partial^{*}E}f_{E,\Omega}^F\text{d}\mathcal{S}^{h}(x).
\]

\medskip

Applying the same argument to our case,

\begin{align*}
\int_{\Omega}\text{d}u(F) & =-\int_{0}^{+\infty}\text{d}t\left(\int_{{\mathbb{X}}}\mathds1_{E_{t}}\div(F)\text{d}\mu+\int_{\partial^{*}E_{t}}f_{E_{t},\Omega}^F\text{d}\mathcal{S}^h(x)\right)\\
 & =-\int_{0}^{+\infty}\text{d}t\left(\int_{\Omega}\mathds1_{E_{t}}\div(F)\text{d}\mu+\int_{\left\{ u^{*}\ge t\right\} }f_{E_{t},\Omega}^F\text{d}\mathcal{S}^h(x)\right)\\
 & =-\int_{\Omega}u\div(F)\text{d}\mu-\int_{\partial\Omega}\Theta^F (u^*(x))\text{d}\mathcal{S}^h(x),
\end{align*}

where

\begin{equation}\label{thetarough}\Theta^F (u^*(x))=\int_{0}^{u^{*}(x)}\mathds1_{E_{t}}f_{E_{t},\Omega}^F\text{d}t.
\end{equation}
\end{proof}

\medskip

\begin{remark}\label{rmk-gauss} Let us add some comments on Theorem \ref{gauss-green}.
 \begin{enumerate}
\item In the same spirit of Definition \ref{local-space}, we shall say that $({\mathbb{X}},d,\mu)$
is \textit{\textcolor{black}{strongly local }}\textcolor{black}{if,
besides the condition $\theta_{E}=\theta_{\Omega}$ ${\cal S}^{h}$}-almost
everywhere on $\partial^{*}\Omega\cap\partial^{*}E$, one also has
\begin{equation*}
 \sigma_E^F=\sigma_{\Omega}^F\qquad\mathcal{S}^h\mathrm{-almost\;everywhere\;on}\;\partial^*\Omega\cap\partial^*E.
\end{equation*}

Observe that if $({\mathbb{X}},d,\mu)$
is strongly local, then the function $f_{E,\Omega}^F$ in \eqref{f-e-omega} is identically equal to 1.

\item If we change the statement of Theorem \ref{gauss-green} assuming that
$\Omega$ is a regular domain in the sense of \cite{bu}, namely an open set of finite perimeter coinciding with the upper inner Minkowski content of its boundary,
\[
 \|D\mathds1_{\Omega}\|(\mathbb{X})=\mathfrak{M}^{*}_{\mathrm{in}}(\partial\Omega)\coloneqq\underset{t\to 0}{\lim\sup}\frac{\mu\left(\Omega\backslash\Omega_t\right)}{t},
\]
where for $t>0$ we set $\Omega_t\coloneqq\left\{x\in\Omega:\:\mathrm{dist}\left(x,\Omega^c\right)\ge t\right\}$, and we also require that ${\cal S}^{h}\left(\partial\Omega\backslash\partial^{*}\Omega\right)=0$,
then we can show that for every $u\in BV(\Omega)$ there exists a \textit{trace operator}
$\mathrm{T}:BV(\Omega)\rightarrow L^{1}\left(\partial\Omega,\left\Vert D\mathds1_{\Omega}\right\Vert \right)$
such that for every $F\in\mathfrak{D}^\infty(\mathbb{X})$ one has
\begin{align*}
\int_{\Omega}\mathrm{d}u(F)+\int_{\Omega}u\div(F)\mathrm{d}\mu\\& =-\int_{\partial\Omega}u^{*}(x)\left(F\cdot\nu\right)_{\partial\Omega}^{-}\mathrm{d}\left\Vert D\mathds1_{\Omega}\right\Vert (x)\\&\coloneqq\left\langle \mathrm{T}u,\left(F\cdot\nu\right)_{\partial\Omega}^{-}\right\rangle,
\end{align*}

where the map $(F\cdot\nu^-_{\partial\Omega})\in L^1(\partial\Omega,\|D\mathds1_\Omega\|)$ is the \textit{inner normal trace} of $F$ on $\partial\Omega$.
Indeed, in this case we can use the \textit{defining sequence} $\left(\varphi_{\varepsilon}\right)_{\varepsilon>0}\subset\text{Lip}_{c}(\Omega)$
of the regular domain $\Omega$, \cite[Remark 7.1.5]{bu}, and we are entitled to repeat the
proof of \cite[Theorem 7.1.7]{bu}. We refer also to \cite[Section 4]{bcm} for refined versions of the results of \cite{bu}.

As a concrete example, we observe that for all $x\in\mathbb{X}$ and for almost-every $\rho>0$, any ball $B_\rho(x)$ is a regular domain, \cite{bu,bcm}.
\end{enumerate}
\end{remark}
\begin{flushright}
 $\blacksquare$
\end{flushright}

\section{Trace comparison}\label{comparison}

\medskip

In this last section we compare the foregoing discussion on the rough trace with \cite{LS}, where the authors investigate the properties of the trace operator for $BV$ functions by means of the more classical Lebesgue-points characterization.

\medskip

We start by summarizing the salient definitions and results of \cite{LS} which will be of relevance to us.

\medskip

\begin{definition}\label{trace}Let $\Omega\subset{\mathbb{X}}$
be an open set and let $u$ be a $\mu$-measurable function on $\Omega$.
Then, we shall say that a function $\mathrm{T}u:\partial\Omega\rightarrow\mathbb{R}$
is a \textit{\textcolor{black}{trace }}of $u$ if for ${\cal S}^{h}$-almost
every $x\in\partial\Omega$ one has

\[
\underset{\rho\rightarrow0^{+}}{\lim}\mean{\Omega\cap B_{\rho}(x)}\left|u-\mathrm{T}u(x)\right|\mathrm{d}\mu=0.
\]
\end{definition}

\medskip

The \textit{zero extension} of $\mu$ from $\Omega$ to $\overline{\Omega}$,
$\bar{\mu}$, is given by $\bar{\mu}(A)\coloneqq\mu(A\cap\Omega)$
whenever $A\subset\overline{\Omega}$; in a similar fashion, we shall write $\overline{\mathcal{S}}^h$ to intend the spherical Hausdorff measure on $\partial\Omega$ corresponding to the measure $\bar{\mu}$ on $\overline{\Omega}$.

Accordingly, for any measurable function $u$ in $\Omega$, its zero-extension to $\overline{\Omega}$ will be written as $\bar{u}$; $\bar{u}^\vee$ and $\bar{u}^\wedge$ will therefore denote the approximate limits of $\bar{u}$ computed in terms of the extended measure $\bar{\mu}$.

\bigskip{}

\begin{proposition}\label{du-zero}
{\normalfont{\cite[Proposition 3.3]{LS}}}
\label{Du-bdry-zero}
Let $\Omega\subset{\mathbb{X}}$
be a bounded open set supporting a $(1,1)$-Poincar\'e inequality and
assume that $\mu$ is doubling on $\Omega$. Let $\overline{\Omega}$
be equipped with the extended measure $\bar{\mu}$. If $u\in BV(\Omega)$,
then its zero-extension $\bar{u}$ to
$\overline{\Omega}$ is such that $\left\Vert \bar{u}\right\Vert _{BV\left(\overline{\Omega}\right)}=\left\Vert u\right\Vert _{BV(\Omega)}$,
whence

\begin{equation*}
 \left\Vert D\bar{u}\right\Vert (\partial\Omega)=0.
\end{equation*}
\end{proposition}
\begin{flushright}$\square$\end{flushright}

\medskip

\begin{definition}
We say that an open set $\Omega$
satisfies a \textit{\textcolor{black}{measure-density condition }}\textcolor{black}{if
there exists a constant $C>0$ such that}
\begin{equation}\label{meas-dens}
\mu\left(B_{\rho}(x)\cap\Omega\right)\ge C\mu\left(B_{\rho}(x)\right)
\end{equation}
for ${\cal S}^{h}$-almost every $x\in\partial\Omega$ and for every
$\rho\in(0,\mathrm{diam}(\Omega))$.
\end{definition}

\bigskip

\begin{thm}\label{tracethm}{\normalfont{\cite[Theorem 3.4]{LS}}}
Let $\Omega\subset\mathbb{X}$ be a bounded open set that supports a $(1,1)$-Poincar\'e inequality, and assume that $\mu$ is doubling on $\Omega$. Then, there exist $q>1$ depending only on the doubling constant in $\Omega$ and a linear trace operator
$\mathrm{T}$ on $BV(\Omega)$ such that, given $u\in
BV(\Omega)$,
for $\overline{{\cal S}}^{h}$-almost every $x\in\partial
\Omega$ we have

\begin{equation}\label{trace-leb}
\underset{\rho\rightarrow0^{+}}{\lim}\mean{\Omega\cap
B_{\rho}(x)}\left|u-\mathrm{T}u(x)\right|^{\frac{q}{q-1}}
\mathrm{d}\mu=0.
\end{equation}

If $\Omega$ also satisfies the measure-density condition \eqref{meas-dens},
the above holds for ${\cal S}^{h}$-almost
every $x\in\partial\Omega$.
\end{thm}
\begin{flushright}
 $\square$
\end{flushright}

\medskip

\begin{remark}\label{eq-aplim}
In the proof of \cite[Theorem 3.4]{LS}, the authors used the condition $\|D\bar{u}\|(\partial\Omega)$ $=0$ found in   Proposition \cite[Proposition 3.3]{LS} to infer  that $\overline{\mathcal{S}}^h\!\left(S_{\bar{u}}\cap\partial\Omega\right)$ $=0$; this of course arises from the decomposition of the total variation measure given in Remark \ref{bv-decomp} and entails that the equality

\[
\bar{u}^{\wedge}(x)=\bar{u}^{\vee}(x)
\]

holds for $\overline{{\cal S}}^{h}$-almost every $x\in\partial\Omega$.

Always in the proof of \cite[Theorem 3.4]{LS},  \eqref{trace-leb} was actually found to hold in the form

\[
 \underset{\rho\to 0^+}{\lim}\mean{\Omega\cap B_\rho(x)} |u-\bar{u}^\wedge(x)|^{\frac{q}{q-1}}\text{d}\mu=0.
\]

Then, one sets $\mathrm{T}u(x)=\bar{u}^\wedge(x)$, which in turn equals $\bar{u}^\vee(x)$ for $\overline{\mathcal{S}}^h$-almost every $x\in\partial\Omega$ by the considerations right above.

So in particular, when $\Omega$ satisfies the measure-density condition \eqref{meas-dens}, such equalities are fulfilled for $\mathcal{S}^h$-almost every $x\in\partial\Omega$ as well.
\end{remark}
\begin{flushright}
 $\blacksquare$
\end{flushright}

Next, we prove that the rough trace of a $BV$ function is bounded by the approximate limits of its zero-extension to $\overline{\Omega}$, and that $\text{T}u=u^*$ on $\partial\Omega$.

\medskip

\begin{thm}
\label{u-star-aplim}
Let $\Omega\subset\mathbb{X}$
be an open set and let $u\in BV(\Omega)$.
Then, for every $x\in\partial^{*}\Omega$  such that
$u^*(x)>-\infty$, we have  that
\[
\bar{u}^{\wedge}(x)\le u^{*}(x)\le\bar{u}^{\vee}(x).
\]
In particular, if $\Omega$ is a bounded open set supporting a (1,1)-Poincar\'e inequality and $\mu$ is doubling on $\Omega$, then
\[
 \mathrm{T}u(x)=\bar{u}^\wedge(x)=\bar{u}^\vee(x)=u^*(x)
\]
for $\overline{\mathcal{S}}^h$-almost every $x\in\partial\Omega$.

If in addition the measure-density condition \eqref{meas-dens} is satisfied, then the above equality holds $\mathcal{S}^h$-almost everywhere on $\partial\Omega$.

Finally, assume also that $\|D\mathds1_\Omega\|(\mathbb{X})<\infty$ and $\mathcal{S}^h(\partial\Omega\backslash\partial^*\Omega)=0$. Then, one has
\[
 \|\mathrm{T}u\|_{L^1(\partial\Omega,\mathcal{S}^h)}\le c\|u\|_{BV(\Omega)}
\]
with a constant $c>0$ independent of $u$, if and only if there exists $\delta>0$ such that for every $E\subset\Omega$ with $\text{diam}(E)\le\delta$ and $\|D\mathds1_E\|(\Omega)<\infty$ there holds
\[
 \|D\mathds1_E\|(\Omega^c)\le c'\|D\mathds1_E\|(\Omega)
\]
with a constant $c'>0$ independent of $E$.
\end{thm}

\begin{proof}
Recall
that by definition, \eqref{rgh-tr}, $u^{*}(x)$ is the supremum of those $t\in\mathbb{R}$ for
which $\|D\mathds1_{E_t}\|(\mathbb{X})<\infty$ and $x\in\partial^{*}E_{t}$, which explains the requirement $u^*(x)>-\infty$ in our statement.

Recall also that by $\partial^*E_t$  we always intend the essential boundary of $E_t$ in $\mathbb{X}$, not its essential boundary relative to $\Omega$.

We have that
\[
\bar{u}^\vee(x)=\inf \left\{ t\in \mathbb{R}: \lim_{\rho\to 0}
\frac{\bar\mu(\{\bar  u>t\} \cap B_\rho(x))}{\bar\mu(B_\rho(x))}
=0\right\}.
\]
Here, the balls have to be understood as balls on the metric space $\overline{\Omega}$;
then, from the definition of $\bar\mu$ we get
\begin{align*}
\frac{\bar\mu(\{\bar  u>t\} \cap B_\rho(x))}{\bar\mu(B_\rho(x))}
=&
\frac{\bar\mu(\{\bar  u>t\} \cap B_\rho(x)
\cap \overline {\Omega})}{\bar\mu(B_\rho(x)\cap \overline{\Omega})}\\
=&
\frac{\mu(\{u>t\} \cap B_\rho(x))}{\mu(B_\rho(x)\cap \Omega)},
\end{align*}
where we have also taken into account that
$\{u>t\}\subset \Omega$.

If $\bar{u}^\vee(x)=+\infty$ there is nothing to prove;
otherwise, if $t>\bar{u}^\vee(x)$ and
$x\in \partial^*\Omega$ we obtain that
\begin{align*}
\limsup_{\rho\to 0}
\frac{\mu(\{u> t\}\cap B_\rho(x))}{\mu(B_\rho(x))}
=&
\limsup_{\rho\to 0}
\frac{\mu(\{u> t\}\cap B_\rho(x))}{\mu(B_\rho(x)\cap  \Omega)} \cdot
\frac{\mu(B_\rho(x)\cap  \Omega)}{\mu(B_\rho(x))}\\
\leq&
\lim_{\rho\to 0}
\frac{\mu(\{u> t\}\cap B_\rho(x))}{\mu(B_\rho(x)\cap  \Omega)}
=0.
\end{align*}
As  a consequence, noticing that for $t>s>\bar{u}^\vee(x)$,
$\{ u>t\} \subseteq\{ u\geq t\}\subseteq \{u>s\}$, we deduce
$x\in E_t^{(0)}$ for any $t>\bar{u}^\vee(x)$  and then
$x\not\in \partial^*E_t$. Then
$u^*(x)\leq t$ for  any $t>\bar{u}^\vee(x)$, and so
$u^*(x)\leq \bar{u}^\vee(x)$.

In the same way, if $\bar{u}^\wedge(x)=-\infty$
there is nothing to prove, otherwise
if $t<\bar{u}^\wedge(x)$ and
$x\in \partial^*\Omega$, we get that
\[
\limsup_{\rho\to 0}
\frac{\mu(\{u< t\}\cap B_\rho(x))}{\mu(B_\rho(x))}=0,
\]
and then $\Theta^*_\mu(\{u<t\},x)=0$ and  then
$x\in E_t^{(1)}$,  i.e.  $x\not\in \partial^*E_t$
for any $t<\bar{u}^\wedge(x)$.
Since $u^*(x)>-\infty$, we have that $x\in \partial^*E_t$ for some  $t\in \mathbb{R}$, and the previous computation implies that
$t\geq \bar{u}^\wedge(x)$.  So we can conclude that
$\bar{u}^\wedge(x)\leq u^*(x)$.

The other assertions in the Theorem follow from
Theorem \ref{mazyathm}, Proposition \ref{du-zero}
and Theorem \ref{tracethm}.

\end{proof}

\medskip

\begin{remark}\textbf{(Comments and Open Problems)}
In conclusion, our discussion allowed us to find the conditions to impose on a domain $\Omega\subset\mathbb{X}$ in order to ensure that the ``classical'' trace $\text{T}u$ and the rough trace $u^*$ of a $BV$ function coincide $\mathcal{S}^h$-almost everywhere on the boundary of such domain.

Actually, our results also address the $L^1$-summability of the trace $\text{T}u$; indeed, as we can see from Theorem \ref{u-star-aplim}, if we introduce the additional assumption that for some $\delta>0$ and for any set $E\subset\Omega$ with finite perimeter in $\Omega$ and $\text{diam}(E)\le\delta$ it holds
\[
 \|D\mathds1_E\|(\Omega^c)\le c\|D\mathds1_E\|(\Omega)
\]
for some constant $c>0$ independent of $E$, which is namely the fundamental condition \eqref{per-compl} of Theorem \ref{mazyathm}, then we get that $\text{T}u\in L^1(\partial\Omega,\mathcal{S}^h)$ as well.

In \cite[Section 5]{LS}, the authors attack the issue of the summability of the trace $\text{T}u$ by working again in terms of the measure-density condition \eqref{meas-dens}  and assuming an additional ``surface-density'' condition for $\partial\Omega$, namely that there is a constant $c=c_{\partial\Omega}>0$ such that
\[
 \mathcal{S}^h(B_\rho(x)\cap\partial\Omega)\le c\frac{\mu(B_\rho(x))}{\rho}
\]
 for any $x\in\partial\Omega$ and any $\rho\in (0,2\text{diam}(\Omega))$.

 Thus said, one question arises naturally: \textit{how does the requirement \eqref{per-compl} in Theorem \ref{mazyathm} relate with the measure-density condition \eqref{meas-dens} and with the surface-density condition above?}

 Answering to such a question would be of general interest as it would provide us with a better understanding of the domains where the ``nice'' properties of traces of $BV$ functions are satisfied, and therefore we would have a more consistent and more comprehensive theory of traces of $BV$ functions.
 \begin{flushright}
  $\blacksquare$
 \end{flushright}
\end{remark}

\bigskip


\section{Introduction}
\label{sec:introduction}
\input{introduction}

\section{Goals and Method's Overview}
\label{sec:rqs}
\input{methodology}

\section{\textbf{RQ$_1$} -- Flaky Tests: Nature, Origin, and Fixing}
\label{sec:rq1}
\input{rq1}

\section{\textbf{RQ$_2$} -- Flaky Tests: Relevance}
\label{sec:rq2}
\input{rq2}

\section{\textbf{RQ$_3$} -- Flaky Tests: Challenges}
\label{sec:rq3}
\input{rq3}

\section{Discussion and Implications}
\label{sec:discussion}
\input{discussion}

\section{Threats to Validity}
\label{sec:threats}
\input{threats}

\section{Related Work}
\label{sec:related}
\input{related}

\section{Conclusion}
\label{sec:conclusion}
\input{conclusion}

\begin{acks}
	The authors would like to thank all the \textsc{Mozilla}\xspace developers who participated in the creation of the dataset, as well as the respondents to our survey: You provided us and our research community with very precious data.
	Bacchelli and Palomba gratefully acknowledge the support of the Swiss National Science Foundation through the SNF Project No. PP00P2\_170529.
\end{acks}
\balance

\newpage

\bibliographystyle{ACM-Reference-Format}

\subsection{Research Questions}
We start our research by asking professional developers to classify (in terms of nature, origin, and fixing effort) flaky tests they previously fixed. Differently from Luo et al.\xspace \cite{Luo:fse2014}, we do not classify the underlying causes of flakiness ourselves, rather the original developers do and add information on the origin and fixing effort. Moreover, we complement the developers' analysis with information on the fixing strategies. Our goal is to triangulate the taxonomy proposed by Luo et al.\xspace \cite{Luo:fse2014} from a different data source and with a different methodology.
Hence, our first research question:

\begin{center}
	\begin{examplebox}
		\textbf{RQ$_1$.} \emph{How do professional developers categorize flaky tests, in terms of nature, origin, and fixing effort? How do they fix them?\xspace}
	\end{examplebox}
\end{center}

Subsequently, we turn to a broader audience of respondents. We conduct a survey targeting software developers on their experience with flaky tests.
We investigate the frequency of flaky tests in practice and how problematic flaky tests are from the developer's perspective.
We ask:

\begin{center}
	\begin{examplebox}
		\textbf{RQ$_2$.} \emph{How prominent is test flakiness and how problematic is it as perceived by developers?\xspace}
	\end{examplebox}
\end{center}

Finally, we investigate the challenges that developers perceive as most critical when they have to deal with flaky tests. We ask:

\begin{center}
	\begin{examplebox}
		\textbf{RQ$_3$.} \emph{What are the main challenges that developers face when dealing with flaky tests?}
	\end{examplebox}
\end{center}

\subsection{Overview Of The Research Method}
Our study features a mixed-methods approach \cite{johnson2004mixed} where quantitative and qualitative research are run in parallel with the goal of converging toward an empirical understanding of test code flakiness. We design and conduct a study to obtain data from two main sources: A novel annotated dataset (\textbf{\textsc{ds}}) of flaky tests (with 200\xspace instances annotated by 21\xspace professional developers) and the responses to an online survey (\textbf{\textsc{os}}) (with 121\xspace valid responses from developers).

\subsection{Developers' Analysis Of Flaky Tests}

In the following, we describe the methodological steps conducted to address our first research question.\smallskip

\textbf{Subject Flaky Tests.}
We first need to collect a dataset of flaky tests, which we then present to developers for their analysis.
To this aim, we mine the \textsc{Bugzilla} issue tracker of \textsc{Mozilla} (i.e.,\xspace a large free software organization counting more than 40,000 active contributors spread around the world and developing a variety of software, ranging from layout engines to operating systems). \textsc{Mozilla} has a database of flaky tests, verified and fixed by developers. According to such a database, the organization has 100 to 150 new flaky tests being detected every week: this makes it particularly suitable for our study because developers are very frequently in charge of diagnosing and fixing flaky tests, being therefore able to provide authoritative information on the nature of test flakiness, its origin, and the fixing effort.

We extract the data available after a flaky test has been reported. Thus, we gather the log files produced by the continuous integration system and the source code associated with the fixed flaky test (if available).
In a first step, we identify all (869) fixed flaky tests the \textsc{Mozilla}\xspace's bug tracking system tagged \texttt{resolved} and \texttt{fixed} between May 2017 and April 2018. We consider this time window since the company only stores the log files for twelve months after their creation.
From the set of retrieved flaky tests, we remove all instances for which no patch has been applied or other type of attachment is available (e.g.,\xspace some flaky tests stop occurring after a while and are closed as fixed), as they were never fixed or were false alarms.
This step filters out 295 tests; resulting in a set of 574 flaky tests, which we use in the next steps.

\smallskip
\textbf{Recruiting \textsc{Mozilla}\xspace Developers.}
The remaining 574 actual flaky tests are taken into further consideration and sorted according to the developer who is listed as the assignee or patch creator. From this list, to ensure we select people with a concrete knowledge on flaky tests, we exclude 177 programmers who have only fixed less than five  flaky tests. We end up with a list of 29 developers for a total of 304 fixed flaky tests. We contact these programmers through email and ask them to analyze the flaky tests as detailed in the following subsection.

\smallskip
\textbf{Developers' Analysis.}
We create a spreadsheet for each developer that contains two columns: the first reports the link to the bug report related to each flaky test fixed by a certain developer; the second is used by the programmer to classify the nature of each flaky test in the list. The participating developers are allowed to use the taxonomy defined by Luo et al.\xspace~\cite{Luo:fse2014} as a starting point for the classification process, as it (1) eases their task and (2) standardizes their answers---this is commonly done in both confirmatory and exploratory surveys \cite{flanigan2008conducting}.
However, they are also allowed to create additional categories if none of the existing ones fit; at the same time, they can indicate more than one type to specify the reasons behind the flakiness of a test (it may be flaky because of both a race condition and a network problem).
We also ask the developers to specify the development effort they spent to fix the flaky tests, based on a Likert scale \cite{Oppenheim:1992} between 1 (very low) to 5 (very high), as well as the origin (test or production code) of the flakiness.
Once each developers completes the analysis, they send back their spreadsheets with the annotated classification.
We received a total of 248 responses from 21\xspace professional \textsc{Mozilla}\xspace developers. These developers have 7.5 years (median) of experience with \textsc{Mozilla}\xspace, 958 bug reports (median) assigned to, and---over the last year---14 flaky tests fixed (median). Each developer provided us with 8.5 (median) answers (min = 4, max = 48). Of those responses, we excluded 48: (i) 24 cases turned into permanent failures, i.e.,\xspace they were labeled as intermittent by a \textsc{Mozilla}\xspace sheriff~\cite{mozillaSheriff}, but the fixing developer found them to be permanent failures; (ii) in the other 24 cases, the type of flakiness was unknown even to the developers, meaning that the fixing developers worked around the flakiness rewriting the whole test and code-under-test, but they could not ascertain the cause of the flakiness. By removing these cases, we intend to rely on precise information, only. Nevertheless, the excluded cases are available to our online appendix~\cite{eck:appendix}.
\smallskip

\textbf{Analysis Of The Developers' Responses.}
We use the 200\xspace classified flaky tests to define a taxonomy on the nature of flaky tests. In 72 cases (31\%) the assigned categories do not correspond to those available in the taxonomy by Luo et al.\xspace~\cite{Luo:fse2014} and, therefore, they are new and need to be defined. To this aim, we conduct an \emph{iterative content analysis} \cite{white2006content} to assign a common name to these new categories. The process involves three software engineering researchers, all authors of this paper, (one graduate student, one research associate, and one faculty member) and consists of the two iterative sessions:

\begin{description}[leftmargin=0.3cm]
	\item[Iteration 1:] The first author of this paper goes over the classifications made by developers. If the categories assigned belong to the taxonomy by Luo et al.\xspace~\cite{Luo:fse2014}, he leaves them as they are; if not, he assigns a temporary label to them. As an output, this step provides a draft categorization of the types of flakiness.

	\smallskip
	\item[Iteration 2:] The three researchers open a discussion on the draft taxonomy, with the aim of reaching a consensus on the assigned categories. Afterwards, the first author re-categorizes flaky tests according to the decisions taken during the discussion. Finally, the second author of the paper double-checks the classifications to reduce the risk of errors (he found no wrong classifications, thus reaching a total agreement).

\end{description}

The resulting extended taxonomy is then used to address \textbf{RQ$_1$}. Besides reporting the list of such categories, we also characterize them with additional information on \begin{inparaenum}[(i)]
	\item their frequency, computed on the basis of the distribution of the categories within the dataset,

	and
	\item the fixing strategies.
\end{inparaenum}
As for the latter point, to characterize the fixing strategies adopted by developers when dealing with flaky tests, two authors of this paper conduct a new iterative content analysis that---similarly to the previous one---consists of two iterations. In the first iteration, the first author analyzes the patches associated to the resolution of the considered flaky tests to label them with a name and a short description of the fixing action performed by developers. In the second iteration, the two authors open a discussion on the initial labels assigned to reach a consensus. Then, the first author applies the changes according to the discussion while the second re-checks the final classifications to reduce threats in the interpretation of the results.

\subsection{Survey: Research Method}\label{sec:survey_method}

To answer \textbf{RQ$_2$} and \textbf{RQ$_3$}, we design and deploy an online survey, and analyze the collected answers.

\smallskip
\textbf{Overall Survey Design.} Following the guidelines provided by Flanigan et al.\xspace~\cite{flanigan2008conducting}, we limit common issues possibly arising in survey studies and affecting the response rate: we keep the survey short, respecting the anonymity of participants and preventing our influence in the answers. We create an anonymous online survey using a professional tool (i.e.,\xspace \textsc{Surveygizmo}~\cite{surveygizmo}).

The survey first describes to the respondents the concept of flaky tests, following the definition accepted by the research community: \emph{``[flaky tests are] intermittent tests that sometimes pass, sometimes fail, even though there are no changes in the code they test''}. Then, the survey
asks for demographic information about the participants, including programming/testing experience as well as company and team size/domain. Subsequently, the survey contains other two main sections to collect data about the relevance of flakiness (\textbf{RQ$_2$}) and its challenges (\textbf{RQ$_3$}).\smallskip

\textbf{\textbf{RQ$_2$} -- Collecting Information About Relevance.} We gather data on \begin{inparaenum}[(i)]
	\item how many times flaky tests occur,
	\item how problematic they are,
	and
	\item what are the top 3 to 5 problems caused by test flakiness.
\end{inparaenum}
Participants can answer the first two questions by using a 5-point Likert scale indicating the extent to which the problem exists and how much it is serious, while they are free to write down the problems (if any) in a text box.\smallskip

\textbf{\textbf{RQ$_3$} -- Collecting Information About Challenges.}

We first conduct a multivocal literature review (MLR)~\cite{garousi2016need}. This allows us to let emerge eight pieces of information that may be linked to challenges in the process of fixing flaky tests.
Afterwards, we ask the survey respondents to rate how important is each of those information pieces from `Not at all important' to `Extremely important' (on a 4-point Likert scale) and the difficulty in obtaining it from `Very easy' to `Very difficult' (on a 5-point Likert scale). We also let the respondents indicate any information needs and/or challenges they face that are not included in the list (respondents indicated a total of another eleven needs/challenges).

For our MLR, we analyze (as described in the following protocol) both previously published papers on the topic (i.e.,\xspace white literature) and online sources (e.g.,\xspace blog posts, websites, and documents written by practitioners) related to flaky tests (i.e.,\xspace gray literature).

\begin{itemize}[leftmargin=0.3cm]
	\item \emph{Identifying relevant white literature:} We perform a keyword search on \textsc{Google Scholar}, \textsc{IEEE Explore}, and \textsc{ACM Digital Library} to create an initial selection of articles. As keywords we use: `flaky tests', `flaky test resolution practices', `intermittent failures'. This step results in an initial set of 15 papers.
	We also perform forward and backward snowballing \cite{wohlin2014guidelines}, inspecting sources referred or that refer to those belonging to the initial set of primary studies.
	At the same time, we consider the proceedings of all the relevant, top-tier conference venues in Software Engineering such as ICSE \cite{icse}, ISSTA \cite{issta}, ICST \cite{icst}, ICSME \cite{icsme}, ESEC/FSE \cite{fse} and journals such as IEEE TSE \cite{tse}, ACM TOSEM \cite{tosem}, and Springer's EMSE \cite{emse}. This step results in the inclusion of additional four papers.
	Once having this set of resources, we filter out the papers that do not report information on what are the practices used by developers to diagnose and/or fixing flaky tests: This is achieved by reading study setting, methodology, and conclusions made in all the considered papers. The filtering process is jointly discussed among all the authors of the paper and, in the end, we agree on a list of three papers.

	\smallskip
	\item \emph{Identifying relevant gray literature:} We conduct the gray literature survey following the guidelines by Garousi et al.\xspace \cite{garousi2016need}. We query \textsc{Google} by using `flaky tests', `flaky test resolution practices', `intermittent failures' as keywords. We perform our search on the results appearing in all the relevant \textsc{Google} pages until saturation is reached, i.e.,\xspace until the search results contain references to blogs, documents, or websites reporting information on flaky tests. We take great care to ensure that considered sources originate from reputable companies, organizations, and authors. We also take steps from preventing our personal search bias from playing a role in the search results, hence we search on \textsc{Google} using the incognito mode. Overall, we find 56 relevant sources to further consider. Whenever possible, we also follow the web links contained in the initial set of sources as they might refer to other documents. This step results in the addition of three sources. The high number of relevant sources identified in the gray literature, as opposed to that of the white one, hints at the fact that the problem of understanding flaky tests has been only partially addressed by the research community. This situation calls for further empirical studies to create a stronger scientific knowledge around test flakiness.

	\smallskip
	\item \emph{Data Extraction:} We summarize each of the 62 identified relevant sources and create an enumeration of the aspects that are mentioned and may impact on the flaky tests fixing process. Then, we conduct another iterative content analysis sessions to group those aspects into the higher level themes that are related to the important information developers need to have when diagnosing and fixing test flakiness. This is a two-step process similar to the one conducted in the context of \textbf{RQ$_1$}: the second author of this paper performs a first iteration and then the draft themes are refined with the help of the last author. This iterative process results in eight relevant information types, which we list in the survey as previously mentioned.

\end{itemize}

\textbf{Analysis Of The Open Answers.}
For the open answers in the survey, we conduct a two-stage process comprising Descriptive and Pattern coding analysis to name them \cite{corbin1990grounded}. Specifically, in a first step two authors shortly summarize the topic of each passage from the open answers; then, they identify explanatory codes to create themes that are finally discussed among all the authors. For example, in case of the challenges, with this process we end up with nine additional challenges grouped into two categories that indicate the point in time in which they occur, i.e.,\xspace (1) \emph{Test case design} and (2) \emph{Flaky test fixing}.

\smallskip
\textbf{Attracting Participants.} We advertised the online survey using the personal social network accounts of the authors (i.e.,\xspace \textsc{Facebook}, \textsc{Twitter}, and \textsc{LinkedIn}), through private contacts, and also published on practitioners blogs (e.g.,\xspace \textsc{Reddit}). To stimulate the participation, we allow the participants to indicate a non-profit organization of their choice to which we donate 2 USD.

\smallskip
\textbf{Respondents.} As a result, we collect 188 answers: We filter out 68 partial answers, thus, we only consider 121\xspace full responses. Among these respondents, 75\% have more than 6 years of programming experience (median 10) and two years of industrial programming as well as testing experience (median 5). Moreover, 45\% respondents come from large companies having more than 250 employees. Our sample is composed of developers who are experienced with (industrial) programming and tests, thus we consider the collected responses as valuable for our research questions.