Immediately after the return of the writ, the judge before whom the petitioner is brought shall examine the facts set forth in the return, the cause of the imprisonment or restraint, and whether the cause was upon commitment for a criminal charge or not.