00001 //******************************************************************************** 00002 // Copyright 2007-2010 Intel Corporation All Rights Reserved. ** 00003 // ** 00004 // The source code contained or described herein and all documents related to ** 00005 // the source code ("Material") are owned by Intel Corporation or its suppliers ** 00006 // or licensors. Title to the Material remains with Intel Corporation or its ** 00007 // suppliers and licensors. The Material contains trade secrets and proprietary ** 00008 // and confidential information of Intel or its suppliers and licensors. The ** 00009 // Material is protected by worldwide copyright and trade secret laws and ** 00010 // treaty provisions. No part of the Material may be used, copied, reproduced, ** 00011 // modified, published, uploaded, posted, transmitted, distributed, or ** 00012 // disclosed in any way without Intel's prior express written permission. ** 00013 // ** 00014 // No license under any patent, copyright, trade secret or other intellectual ** 00015 // property right is granted to or conferred upon you by disclosure or delivery ** 00016 // of the Materials, either expressly, by implication, inducement, estoppel or ** 00017 // otherwise. Any license under such intellectual property rights must be ** 00018 // express and approved by Intel in writing. ** 00019 //******************************************************************************** 00020 00021 #ifndef _CnC_DEBUG_H_ 00022 #define _CnC_DEBUG_H_ 00023 00024 #include <cnc/cnc.h> 00025 #include <cnc/internal/cnc_api.h> 00026 00027 namespace CnC { 00028 00029 /// \brief Debugging interface providing tracing and timing capabilities 00030 /// 00031 /// \#include <cnc/debug.h> 00032 /// 00033 /// For a meaningful tracing the runtime requires a function cnc_format for 00034 /// every non-standard item and tag type. The expected signature is: 00035 /// \code 00036 /// std::ostream & cnc_format( std::ostream & os, const your_type & p ) 00037 /// \endcode 00038 /// Make sure it is defined in the corresponding namespace. 00039 struct debug { 00040 /// \brief sets the number of threads used by the application 00041 /// 00042 /// Overwrites environment variable CNC_NUM_THREADS. 00043 /// To be effective, it must be called prior to context creation. 00044 static void CNC_API set_num_threads( int n ); 00045 00046 /// \brief enable tracing of a given tag collection at a given level 00047 /// 00048 /// To be used in a safe environment only (no steps in flight) 00049 /// \param tc the tag collection to be traced 00050 /// \param name the name by which the tag collection should be identified in the trace 00051 /// \param level trace level 00052 template< typename Tag, typename Range, typename HC > 00053 static void trace( tag_collection< Tag, Range, HC > & tc, const char * name, int level = 1 ) 00054 { tc.m_tagCollection.set_tracing( name, level ); } 00055 00056 /// \brief enable tracing of a given item collection at a given level 00057 /// 00058 /// To be used in a safe environment only (no steps in flight). 00059 /// \param ic the item collection to be traced 00060 /// \param name the name by which the item collection should be identified in the trace 00061 /// \param level trace level 00062 template< typename Tag, typename Item, typename HC > 00063 static void trace( item_collection< Tag, Item, HC > & ic, const char * name, int level = 1 ) 00064 { ic.m_itemCollection.set_tracing( name, level ); } 00065 00066 /// \brief enable tracing of everything in given context 00067 /// 00068 /// To be used in a safe environment only (no steps in flight) 00069 /// names of collections are unavailable unless tracing them was enabled explicitly. 00070 /// \param c the context to be traced 00071 /// \param name the name by which the context should be identified in the trace 00072 /// \param level trace level 00073 template< class Derived > 00074 static void trace_all( ::CnC::context< Derived > & c, const char * name, int level = 1 ) 00075 { c.set_tracing( name, level ); } 00076 00077 /// \brief enable tracing of a given step at a given level 00078 /// 00079 /// To be used in a safe environment only (no steps in flight) 00080 /// \param step the step to be traced 00081 /// \param name the name by which the step should be identified in the trace 00082 /// \param level trace level 00083 template< typename Step > 00084 static void trace( Step step, const char * name, int level = 1 ) 00085 { Internal::step_tracer< Step >::s_traceName = name; Internal::step_tracer< Step >::s_traceLevel = level; } 00086 00087 /// \brief initalize timer 00088 /// \param cycle if true, use cycle counter only 00089 /// Cycle counters might overflow: TSC results are incorrect if the measured time-interval 00090 /// is larger than a full turn-around. 00091 static void init_timer( bool cycle = false ) 00092 { Internal::chronometer::init( cycle ); } 00093 00094 /// \brief save collected time log to a specified file 00095 /// \param name the file to write the time log, pass "-" for printing to stdout 00096 static void finalize_timer( const char * name ) 00097 { Internal::chronometer::save_log( name ? name : "-" ); } 00098 00099 /// \brief enable timing of a given step 00100 /// 00101 /// To be used in a safe environment only (no steps in flight) 00102 /// \param step the step to be timed 00103 /// \param name the name by which the step should be identified in the time log 00104 template< typename Step > 00105 static void time( Step step, const char * name ) 00106 { Internal::step_timer< Step >::s_timingName = name; Internal::step_timer< Step >::s_timing = true; } 00107 00108 /// \brief enable collection scheduler statistics per context 00109 /// 00110 /// Statistics will be print upon destructino of a context. 00111 /// \param c the context to be examined 00112 template< class Derived > 00113 static void collect_scheduler_statistics( ::CnC::context< Derived > & c ) 00114 { c.init_scheduler_statistics(); } 00115 }; 00116 00117 } // namespace cnc 00118 00119 #endif // _CnC_DEBUG_H_
1.5.6