I’m using Intel Instrumentation and Tracing Technology to generate performance file, and codes like this:
__itt_domain *domain = __itt_domain_create("Example.Domain.Global");
__itt_string_handle *handle_main = __itt_string_handle_create("Main");
int main() {
__itt_task_begin(domain, __itt_null, __itt_null, handle_main);
int sum = 0;
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < 10000; j++) {
sum += i;
}
}
sleep(1);
printf("Result: %dn", sum);
__itt_task_end(domain);
return 0;
}
It successes running on VTune and get a performance result about “Main” Task. It’s all right.
But now, I want to get the result without running it on VTune. Can I do it?
In another word, I’m trying to find out how itt implement the funtion of recording runnning time. In the source code, I only find this:
ITT_EXTERN_C void ITTAPI __itt_task_begin(
const __itt_domain *domain, __itt_id taskid, __itt_id parentid, __itt_string_handle *name)
{
if (domain != NULL && name != NULL)
{
(void)taskid;
(void)parentid;
LOG_FUNC_CALL_INFO("functions args: domain=%s handle=%s", domain->nameA, name->strA);
}
else
{
LOG_FUNC_CALL_WARN("Incorrect function call");
}
}
What’s more, LOG_FUNC_CALL_INFO
will call log_func_call
, which will open a file, and write something, and close it. Like this:
void log_func_call(uint8_t log_level, const char* function_name, const char* message_format, ...)
{
if (g_ref_collector_logger.init_state)
{
FILE * pLogFile = NULL;
char log_buffer[LOG_BUFFER_MAX_SIZE];
uint32_t result_len = 0;
va_list message_args;
result_len += sprintf(log_buffer, "[%s] %s(...) - ", log_level_str[log_level] ,function_name);
va_start(message_args, message_format);
vsnprintf(log_buffer + result_len, LOG_BUFFER_MAX_SIZE - result_len, message_format, message_args);
pLogFile = fopen(g_ref_collector_logger.file_name, "a");
if (!pLogFile)
{
printf("ERROR: Cannot open file: %sn", g_ref_collector_logger.file_name);
return;
}
fprintf(pLogFile, "%sn", log_buffer);
fclose(pLogFile);
}
else
{
return;
}
}
However, these codes maybe not work. Vtune will output performance files like: userapicollector-xxx.
Maybe itt doesn’t write the method of generating code in source code? I don’t know. 🙁