tbb_statistics.cpp
Go to the documentation of this file.
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "tbb_statistics.h"
#if __TBB_STATISTICS
#include <climits>
#include <cstdarg>
#if __TBB_STATISTICS_STDOUT
#include <cstdio>
#endif
#include "tbb/spin_mutex.h"
namespace tbb {
namespace internal {
const char* StatGroupTitles[] = {
"task objects", "tasks executed", "stealing attempts", "task proxies", "arena", "market", "priority ops", "prio ops details"
};
const char* StatFieldTitles[] = {
/*task objects*/ "active", "freed", "big", NULL,
/*tasks executed*/ "total", "w/o spawn", NULL,
/*stealing attempts*/ "succeeded", "failed", "conflicts", "backoffs", NULL,
/*task proxies*/ "mailed", "revoked", "stolen", "bypassed", "ignored", NULL,
/*arena*/ "switches", "roundtrips", "avg.conc", "avg.allot", NULL,
/*market*/ "roundtrips", NULL,
/*priority ops*/ "ar.switch", "mkt.switch", "ar.reset", "ref.fixup", "avg.ar.pr", "avg.mkt.pr", NULL,
/*prio ops details*/ "winnows", "reloads", "orphaned", "winnowed", "reloaded", NULL
};
class statistics_logger {
public:
statistics_logger () {
__TBB_ASSERT( sg_end - 1 == 1 << (sizeof(StatGroupTitles)/sizeof(*StatGroupTitles) - 1), NULL );
my_file = fopen("statistics.txt","w");
if( !my_file )
perror("fopen(\"statistics.txt\"\")");
// Initialize groups dump layout info
group_start_field[0] = 0;
for ( size_t i = 0, j = 0; i < NumGroups; ++i, ++j ) {
__TBB_ASSERT( StatFieldTitles[j], "Empty group occurred" );
while ( StatFieldTitles[j] )
++j;
group_start_field[i + 1] = j - i; // -i accounts for preceding NULL separators
}
__TBB_ASSERT( group_start_field[NumGroups] == statistics_counters::size(),
"Wrong number of elements in StatFieldTitles" );
dump( "\n%-*s", IDColumnWidth, "");
process_groups( &statistics_logger::print_group_title );
dump( "%-*s", IDColumnWidth, "ID");
process_groups( &statistics_logger::print_field_titles );
}
~statistics_logger () { fclose(my_file); }
void record( const statistics_counters& c, size_t id ) {
spin_mutex::scoped_lock lock(my_mutex);
counters_to_dump = &c;
#if __TBB_STATISTICS_TOTALS_ONLY
if ( id == arena_counters_total ) {
dump( "%-*s", IDColumnWidth, "Tot" );
process_groups( &statistics_logger::print_field_values );
}
#else /* !__TBB_STATISTICS_TOTALS_ONLY */
const char* idString = NULL;
switch ( id ) {
case 0:
idString = "M"; break;
case workers_counters_total:
idString = "Wtot"; break;
case arena_counters_total:
idString = "Tot"; break;
default:
dump( "W%-*u", IDColumnWidth - 1, id );
}
if ( idString )
dump( "%-*s", IDColumnWidth, idString );
process_groups( &statistics_logger::print_field_values );
#endif /* !__TBB_STATISTICS_TOTALS_ONLY */
}
private:
static const size_t IDColumnWidth = 5;
static const size_t StatisticsColumnWidth = 10;
static const size_t NumGroups = sizeof(StatGroupTitles)/sizeof(char*);
FILE* my_file;
spin_mutex my_mutex;
size_t group_start_field[NumGroups + 1];
const statistics_counters* counters_to_dump;
static const size_t NumFields = sizeof(StatFieldTitles)/sizeof(*StatFieldTitles) - NumGroups;
bool averages_fields[NumFields];
void dump ( char const* fmt, ... ) {
va_list args;
if ( my_file ) {
va_start( args, fmt );
vfprintf( my_file, fmt, args );
va_end( args );
}
#if __TBB_STATISTICS_STDOUT
va_start( args, fmt );
vprintf( fmt, args );
va_end( args );
#endif
}
void process_groups ( void (statistics_logger::*per_group_action)(size_t group_idx) ) {
for ( size_t i = 0, group_flag = 1; i < NumGroups; ++i, group_flag <<= 1 ) {
__TBB_ASSERT( group_flag < sg_end, "StatGroupTitles contents is incompatible with statistics_groups definition" );
if ( __TBB_ActiveStatisticsGroups & group_flag )
(this->*per_group_action)( i );
}
dump( "\n" );
}
void print_group_title ( size_t group_idx ) {
dump( "%-*s", (group_start_field[group_idx + 1] - group_start_field[group_idx]) * (StatisticsColumnWidth + 1),
StatGroupTitles[group_idx] );
}
void print_field_titles ( size_t group_idx ) {
// +group_idx accounts for preceding NULL separators
size_t i = group_start_field[group_idx] + group_idx;
while ( StatFieldTitles[i] ) {
averages_fields[i - group_idx] = strncmp(StatFieldTitles[i], "avg.", 4) == 0;
dump( "%-*s ", StatisticsColumnWidth, StatFieldTitles[i++] );
}
}
void print_field_values ( size_t group_idx ) {
size_t begin = group_start_field[group_idx],
end = group_start_field[group_idx + 1];
for ( size_t i = begin; i < end; ++i ) {
if ( averages_fields[i] )
dump( "%-*.2f ", StatisticsColumnWidth, (double)counters_to_dump->field(i)/counters_to_dump->tasks_executed );
else
dump( "%-*ld ", StatisticsColumnWidth, counters_to_dump->field(i) );
}
}
}; // class statistics_logger
static statistics_logger the_statistics;
void dump_statistics ( const statistics_counters& c, size_t id ) {
the_statistics.record(c, id);
}
} // namespace internal
} // namespace tbb
#endif /* __TBB_STATISTICS */
spin_mutex.h
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb_statistics.h
end
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp end
Definition: ittnotify_static.h:182
lock
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void * lock
Definition: ittnotify_static.h:121
begin
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp begin
Definition: ittnotify_static.h:182
size
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t size
Definition: ittnotify_static.h:109
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::spin_mutex::scoped_lock
friend class scoped_lock
Definition: spin_mutex.h:179

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.