How to measure enclave's memory consumption on Intel SGX
- Make sure you have
sgx-gdbinstalled on your machine. Run:$ sgx-gdb --versionto check it. - Create a
.gdbinitfile in your project directory. - Paste this into the file:
# enable SGX memory measurement tool enable sgx_emmt # exit GDB after successfull execution set $_exitcode = -999 define hook-stop if $_exitcode != -999 quit end end - In your global gdbinit file (in my case,
~/.gdbinit) paste these lines:set auto-load local-gdbinit on add-auto-load-safe-path /path/to/project/.gdbinit - In your application, make sure you are destroying the enclave using
sgx_destroy_enclave(const sgx_enclave_id_t enclave_id). - Run your SGX program using SGX-GDB:
$ sgx-gdb -ex=r --args your_executable arg1 arg2what it means:
ex=r- tells GDB to run the program immediately
--args- everything that follows it is a command and its argsYou could set an alias for this command to make it even smoother.
- In the output you will now find the memory usage, e.g.,
[Peak stack used]: 14 KB [Peak heap used]: 67764 KB [Peak reserved memory used]: 0 KB