Evaluating contour integral along the boundary of the fundamental domain of $SL_2(\mathbb{Z})$ near poles Background: I'm working through Serre's introduction to modular forms in A Course in Arithmetic, Ch. 6, $\S 3$, where we prove the weighted sum of the count of poles and zeros on the fundamental domain is k/12 (k/6 by Serre's notation). The contour integral is broken into pieces, some of which are arcs of circles. I don't understand why the contour integrals along these arcs are proportional to the portion of the circumference the path takes.
Question: Let $f$ be a modular function of weight $2k$. Let $C$ be a negatively-oriented circlular path centered at $\rho=e^{2\pi/3}$ with radius $r>0$. For sufficiently small $r$ (we in fact take the limit as $r\to\infty$), the closed contour integral $\frac{1}{2i\pi}\int_C \frac{df}{f}=-v_\rho(f)$, but I don't see why evaluating only along 1/6 of the circumference produces 1/6 the result - for instance, if $a=\rho+ir$ and we integrate clockwise along the arc of a circle of radius $r$ centered at $\rho$ to $b$ on the unit circle, $$\frac{1}{2i\pi}\lim_{r\to 0}\int_{a}^{b}\frac{df}{f}=-\frac{1}{6}v_\rho(f).$$
I'm not sure if this is a general property of complex analysis - because the radius is going to zero, the value of the function becomes constant along the contour, so the integral becomes linear in arc length? - or a property of modular functions in particular.
 A: Here's (most of) the demonstration, with thanks to user1952009 for the clue. Let $f$ be a modular function of weight $k$. Note first that, for $g=\begin{bmatrix} a & b \\ c & d\end{bmatrix}\in G$, the full modular group, $$\frac{df(gz)}{f(gz)}=\frac{d[(cz+d)^kf(z)]}{(cz+d)^kf(z)}=\frac{kc\,dz}{cz+d}+\frac{df}{f}.$$ In particular, for $T=\begin{bmatrix} 1 & 1 \\ 0 & 1\end{bmatrix}$, $\frac{df(Tz)}{f(Tz)}=\frac{df}{f}$, for $S=\begin{bmatrix} 0 & -1 \\ 1 & 0\end{bmatrix}$, $\frac{df(Sz)}{f(Sz)}=\frac{k\,dz}{z} + \frac{df}{f}$, for $ST=\begin{bmatrix} 0 & -1 \\ 1 & 1\end{bmatrix}$, $\frac{df(STz)}{f(STz)}=\frac{k\,dz}{z+1} + \frac{df}{f}$, and for $(ST)^2=\begin{bmatrix} -1 & -1 \\ 1 & 0 \end{bmatrix}$, $\frac{df((ST)^2z)}{f((ST)^2z)}=\frac{k\,dz}{z} + \frac{df}{f}$.
We demonstrate the case of $z=\rho$, but the case is easier for $z=i$. We wish to determine the value of the sums of the integrals along the two arcs of radius $r$ near $\rho$ and $-\bar{\rho}$ in the fundamental domain $D$ of the full modular group $G$. Let the arc near $\rho$ be from $a_0$ to $a_1$ on the unit circle and the arc near $-\bar{\rho}$ be from $b_0$ on the unit circle to $b_1$. \begin{align*}
\int_{a_0}^{a_1}\frac{df}{f}+\int_{b_0}^{b_1}\frac{df}{f} &= \int_{a_0}^{a_1}\frac{df}{f}+\int_{T(b_0)}^{T(b_1)}\frac{df(Tz)}{f(T)} \\
&= \int_{a_0}^{a_1}\frac{df}{f}+\int_{b_0-1}^{b_1-1}\frac{df}{f} \\
&= \int_{b_0-1}^{a_1}\frac{df}{f} 
\end{align*}
since the sum of integrals is precisely over the arc from $b_0-1$ to $a_1$ on the circle $C_r(\rho)$ of radius $r$ centered at $\rho$, since $b_1-1=a_0$. It is the value of this last integral as $r\to 0$ that we are seeking. 
We show that taking the image of this arc under $ST$ and $(ST)^2=(ST)^{-1}$ forms a closed loop. Note $ST(b_0-1)=\frac{-1}{b_0-1+1}=-1/b_0=a_0$ and $(ST)^2(a_1)=T^{-1}S^{-1}(a_1)=T^{-1}(b_0)=b_0-1$, so the endpoint of the arc is the starting point of the image of the arc under $ST$, and thus the starting and ending points of the image under $ST$ and image under $(ST)^2$ align. We use the fact that the action of $G$ is one to one, and that our original arc lies in $D\cup T^{-1}D$, and the intersection of that region with its image under $ST$ and $(ST)^2$ occurs only on the boundary to demonstrate these three paths together form a closed loop with no self-intersections. Note also that $ST$ is a bounded transformation near $\rho$, that is, given $r>0$, there exists a $\delta>0$ such that $\left|\rho-z\right|<\delta$ implies $\left|\rho-STz\right|<r$ (the proof of this fact is left to the reader), so that it makes sense to talk of the limit as $r\to 0$ of a path around $\rho$ contained in a ball of radius $r$. We thus have for this path $C_r$, oriented clockwise, 
\begin{align*}
-v_\rho(f) &= \lim_{r\to 0}\int_{C_r}\frac{df}{f} \\
&= \lim_{r\to 0}\int_{b_0-1}^{a_1}\frac{df}{f}+\int_{b_0-1}^{a_1}\frac{df(STz)}{f(STz)}+\int_{b_0-1}^{a_1}\frac{df((ST)^2z)}{f((ST)^2z)} \\
&= \lim_{r\to 0}\int_{b_0-1}^{a_1}\left(\frac{df}{f}+k\frac{dz}{z+1}+\frac{df}{f}+k\frac{dz}{z}+\frac{df}{f}\right) \\
&= \lim_{r\to 0} 3\int_{b_0-1}^{a_1}\frac{df}{f}+k\int_{b_0-1}^{a_1}\left(\frac{dz}{z+1}+\frac{dz}{z}\right) \\
&= \lim_{r\to 0} 3\int_{b_0-1}^{a_1}\frac{df}{f}+k\left(\ln(z)+\ln(z+1)\right)\bigg|_{b_0-1}^{a_1} \\
&= \lim_{r\to 0} 3\int_{b_0-1}^{a_1}\frac{df}{f}.
\end{align*}
Thus $\lim_{r\to 0} \int_{b_0-1}^{a_1}\frac{df}{f}=-\frac{1}{3}v_\rho(f)$, completing the desired portion of the proof of the valence formula.
