lazy generate monitor code