How to calculate output resistance impadence with using small signal analyse?
You use the second diagram (with vin grounded) and apply a small signal test voltage (vx) and measure the small signal test current (ix).

The important thing to realize is that you are measuring small signal parameters.  Vin (large signal biasing input voltage) is assumed to be still exist, biasing the circuit in the linear region.  But since you are only interested in the small signal parameters, you treat vin as grounded (measuring output resistance around the operating point of the circuit).

For this circuit (which is neglecting the c-e output resistance, ro), and summing the currents at the node (and noticing that vx = -vpi)

\$
i_x + g_m*v_{\pi} = -v_{\pi}/r_{\pi}
\$

\$
i_x -g_m*v_x = v_x/r_{\pi}
\$

\$
i_x = v_x/r_{\pi} + g_m*v_x
\$

\$
i_x/v_x = (1/r_{\pi} + g_m)
\$

\$
r_o = v_x/i_x = 1/(1/r_{\pi} + g_m)
\$

Unless my algebra is incorrect somewhere.  Also \$ r_{\pi} = {\beta}/g_m \$

So,

\$
r_o = 1/(1/({\beta}/g_m) + g_m)
\$

\$
r_o = 1/(g_m/{\beta} + g_m)
\$

\$
r_o = {\frac1{g_m(1/{\beta} + 1)}}
\$

Since \$ {\beta} \$ is large, this can be easily approximated to

\$
r_o = {\frac1{g_m}}
\$

Keep in mind this is ignoring both the input source resistance and the collector-emmitter resistance, so a very idealized formula.