# Linux Kernel Module Cheat

##### 24.10.3.1. gem5 HDF5 statistics

We can make gem5 dump statistics in the HDF5 format by adding the magic `h5://` prefix to the file name as in:

    gem5.opt --stats-file h5://stats.h5

as explained in:

    gem5.opt --stats-help

This is not exposed in LKMC f42c525d7973d70f4c836d2169cc2bd2893b4197 however, you just have to hack the gem5 CLI for now.

TODO what is the advantage? The generated file for `--stats-file h5://stats.h5?desc=False` in LKMC f42c525d7973d70f4c836d2169cc2bd2893b4197 gem5 5af26353b532d7b5988cf0f6f3d0fbc5087dd1df for a single dump was 946K, so much larger than the text version seen at gem5 m5out/stats.txt file which was only 59KB max!

We then try to see if it is any better when you have a bunch of dump events:

    ./run --arch aarch64 --emulator gem5 --userland userland/c/m5ops.c --cli-args 'd 1000'

and there yes, we see that the file size fell from 39MB on `stats.txt` to 3.2MB on `stats.m5`, so the increase observed previously was just due to some initial size overhead (considering the patched gem5 with no spaces in the text file).

We also note however that the stat dump made the such a simulation that just loops and dumps considerably slower, from 3s to 15s on 2017 Lenovo ThinkPad P51. Fascinating, we are definitely not disk bound there.

We enable HDF5 on the build by default with `USE_HDF5=1`. To disable it, you can add `USE_HDF5=0` to the build as in:

    ./build-gem5 -- USE_HDF5=0

Library support is automatically detected, and only built if you have it installed. But there have been some compilation bugs with HDF5, which is why you might want to turn it off sometimes, e.g.: https://gem5.atlassian.net/browse/GEM5-365