In your example code, you call `stopProfiling()` before `writeHprofDataAndShutdown()` whereas you need to call one or the other (usually the latter).