Given function of $\tau(n,\vartheta)$ denotes $\sum_{d|n}d^{i\vartheta}$ for $\vartheta\neq 0$. Also, here $e(x)=\exp(2\pi ix)$. The book mentioned the theorem to be used for the exercise (problem below),
Theorem: Let $f\in C^1([a,b])$ be such that $f'(t)$ is monotone on $(a,b]$. Set $$\alpha:=\inf_{a<t<b}f'(t), \beta:=\sup_{a<t<b}f'(t).$$ Then, for each $\varepsilon>0$, we have $$\sum_{a<n\le b}e(f(n))=\sum_{\alpha-\varepsilon<\nu<\beta+\varepsilon}\int_a^b e(f(t)-\nu t)dt+O_{\varepsilon}(\log(\beta-\alpha+2)).$$
The problem is that
Problem: Making use of the theorem above, prove that $$\dfrac{1}{X}\left|\sum_{n\le X}\tau(n,\vartheta)\right|\ll \log(2+|\vartheta|)+\dfrac{1}{|\vartheta|}, \vartheta\neq 0, X>1+|\vartheta|.$$
Now, here are what I tried which I am not sure that it is the good place to start and seems weird. First, we have $$\sum_{n\le X}\tau(n,\vartheta)=\sum_{n\le X} \sum_{m|n}m^{i\vartheta}=\sum_{m\le X} m^{i\vartheta}\left\lfloor\dfrac{X}{m}\right\rfloor=X\left(\sum_{m\le X}m^{i\vartheta-1}\right)+O(X).$$ Thus, it suffices to show that $\displaystyle\left|\sum_{m\le X}m^{i\vartheta -1}\right|\ll \log(2+|\vartheta|)+\dfrac{1}{|\vartheta|}.$ For $f(t)=\dfrac{\vartheta}{2\pi}\log t$, \begin{align*} \sum_{m\le X}m^{i\vartheta}=\sum_{m\le X} e\left(\dfrac{\vartheta}{2\pi}\log m\right)&=\sum_{r\le\frac{\log X}{\log 2}}\left(\sum_{2^r<m\le 2^{r+1}}e\left(\dfrac{\vartheta}{2\pi}\log m\right)\right)+O(1):=\sum_{r\le\frac{\log X}{\log 2}} F(r)+O(1). \end{align*}
We use theorem above to bound $F(r)$, as $f'(t)=\vartheta/(2\pi t)$, we have $\alpha,\beta \asymp \vartheta/2^r$ \begin{align*} F(r)= \sum_{\alpha-1<\nu<\beta+1}\int_{2^r}^{2^{r+1}}e(f(t)-\nu t)dt+O(\log(|\vartheta|/2^r+2))\ll\dfrac{\vartheta}{2^r}\cdot .(2^r)+\log(|\vartheta|+2)=|\vartheta|+\log(|\vartheta|+2) \end{align*} Thus, \begin{align*} \sum_{m\le X}m^{i\vartheta}\ll (|\vartheta|+\log(|\vartheta|+2))\log X. \end{align*} By partial summation \begin{align*} \left|\sum_{m\le X}m^{i\vartheta-1}\right|\ll \dfrac{(|\vartheta|+\log(|\vartheta|+2))\log X}{X}+\int_{2}^X\dfrac{(|\vartheta|+\log(|\vartheta|+2))\log t}{t^2} dt\ll \log(2+|\vartheta|)+\dfrac{\log(2+|\vartheta|)\log X}{X}, \end{align*} where the second term is, for small $|\vartheta|$, $\ll \dfrac{1}{|\vartheta|}$.