api: split listener and server creation
api: add memory profiling flag

When a file path is provided, a heap profile will get dumped to this
file.