Once all the improvements present @ MDL-26425 have been committed, it will be possible to simplify a bit the xhprof_table_sql implementation by using standard build_table() method and, instead, override the newly available get_row_class() for stylizing rows.
Right now the improvements are only available @ 20_STABLE so the initial patch will be for it. Once the change is available @ master, the patch will be applied there and this issue requested for pull.
Ciao