(a) When the defendant is discharged upon the examination, or acquitted in any criminal prosecution for a public offense, and the court is of opinion that the prosecution was malicious or frivolous, the prosecutor may be taxed with all the costs.
(b) This section extend to trials before judges of general sessions courts, by whom the prosecutor may, in like manner and under like circumstances, be taxed with all the costs.