Probing the origins of photodegradation in organic--inorganic metal halide perovskites with time-resolved mass spectrometry