LLNL/Caliper

[ feature request ] API for printing report

Closed this issue · 3 comments

XL64 commented

Hello,

I didn't find it in the documentation, is there an API to print the runtime-report from within the code.
I would like to print it to a file at different step of my code to be able to follow the evolution of it.

Thanks for your work,

regards,

XL.

Hi @XL64 ,

There is a nice way to do that in Caliper 2.x using channels, there just isn't much documentation for it yet. You can create a channel for the runtime-config profile, and write it with cali_channel_flush(). However, the report will currently overwrite the output file on every flush. You can work around that by generating a distinct file name for each step. This is how you'd do it (using only the C API):

#include <caliper/cali.h>

// Create a channel with the runtime-config profile at program start
const char* profile_config[][2] = {
  { "CALI_CONFIG_PROFILE", "runtime-report" },
  { "CALI_REPORT_FILENAME", "report_%step%.out" },
  { "CALI_CHANNEL_FLUSH_ON_EXIT", "false" },
  { NULL, NULL }
};

cali_configset_t cfg = cali_create_configset(profile_config);
cali_id_t channel = cali_create_channel("profile", false, cfg);
cali_delete_configset(cfg);

// run steps
for ( ... ) {
  
  // Flush profile data for current step
  cali_set_int_byname("step", i);
  cali_channel_flush(channel, CALI_FLUSH_CLEAR_BUFFERS);
}

This will write a runtime report whenever you call cali_channel_flush(). Note that you don't have to set any Caliper environment variables like to activate profiling in this case, it is all done through the channel API (in fact, you could enable an entirely different configuration through environment variables and both would run). With the CALI_FLUSH_CLEAR_BUFFERS flag, the reports will only contain the times since the last flush. With cali_channel_flush(channel, 0), they will always contain the times since program start. The "report_%step%.out" pattern for the file name will generate files using the value of the "step" attribute at the time of the flush as part of the name; so it will create report_0.out, report_1.out, etc.

We should be able to add an "append" mode so we can write multiple reports to a single file - let me know if that would be useful for you.

Finally, there is also a more direct way to do this with the C++ API: You can avoid the report service and use the cali::write_report_for_query() function to flush Caliper data directly into a C++ ostream. This would allow you to write all reports into a single file. There is a small example in the doxygen documentation in cali.h, but let me know if you want to know more about this.

XL64 commented

Thanks for your detailled answer.
I think I'll try the C++ API, read the .h file and continue playing with caliper :)

Hi @XL64 ,

The Caliper ConfigManager API now provides a convenient API to control profiling: https://github.com/LLNL/Caliper/blob/master/doc/CaliperConfiguration.md

There is also the RegionProfile class, which lets you query region times at runtime:
https://github.com/LLNL/Caliper/blob/master/examples/apps/cali-regionprofile.cpp