The official way is to place a dowel down the barrel (while installed, and breech closed) and mark the spot on the dowel where the barrel stops. Measure from the end of the dowel to the mark - and that's your official barrel length.
This is the official way of measure semi-auto pistols. Revolvers are different, and do NOT include the chamber area. Seems stupid, but that's the way it is.