CnC
 All Classes Namespaces Functions Variables Typedefs Enumerator Friends
debug.h
00001 /* *******************************************************************************
00002  *  Copyright (c) 2007-2014, Intel Corporation
00003  *
00004  *  Redistribution and use in source and binary forms, with or without
00005  *  modification, are permitted provided that the following conditions are met:
00006  *
00007  *  * Redistributions of source code must retain the above copyright notice,
00008  *    this list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  *  * Neither the name of Intel Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *
00016  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00020  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  ********************************************************************************/
00027 
00028 /*
00029   CnC debug interface.
00030 */
00031 
00032 #ifndef _CnC_DEBUG_H_
00033 #define _CnC_DEBUG_H_
00034 
00035 #include <cnc/internal/cnc_api.h>
00036 #include <cnc/internal/chronometer.h>
00037 #include <cnc/internal/step_launcher.h>
00038 
00039 namespace CnC {
00040 
00041     class graph;
00042     template< class T > class context;
00043     template< typename Tag, typename Tuner > class tag_collection;
00044     template< typename Tag, typename Item, typename Tuner > class item_collection;
00045     template< typename UserStep, typename Tuner > class step_collection;
00046     
00047 
00048     /// \brief Debugging interface providing tracing and timing capabilities
00049     ///
00050     /// \#include <cnc/debug.h>
00051     ///
00052     /// For a meaningful tracing the runtime requires a function cnc_format for
00053     /// every non-standard item and tag type. The expected signature is:
00054     /// \code std::ostream & cnc_format( std::ostream & os, const your_type & p ) \endcode
00055     /// Make sure it is defined in the corresponding namespace.
00056     struct debug {
00057         /// \brief sets the number of threads used by the application
00058         ///
00059         /// Overwrites environment variable CNC_NUM_THREADS.
00060         /// To be effective, it must be called prior to context creation.
00061         static void CNC_API set_num_threads( int n );
00062 
00063         /// \brief enable tracing of a given tag collection at a given level
00064         ///
00065         /// To be used in a safe environment only (no steps in flight)
00066         /// \param tc    the tag collection to be traced
00067         /// \param level trace level
00068         template< typename Tag, typename Tuner >
00069         static void trace( tag_collection< Tag, Tuner > & tc, int level = 1 )
00070         { tc.m_tagCollection.set_tracing( level ); }
00071 
00072         /// \brief enable tracing of a given item collection at a given level
00073         ///
00074         /// To be used in a safe environment only (no steps in flight).
00075         /// \param ic    the item collection to be traced
00076         /// \param level trace level
00077         template< typename Tag, typename Item, typename HC >
00078         static void trace( item_collection< Tag, Item, HC > & ic, int level = 1 )
00079         { ic.m_itemCollection.set_tracing( level ); }
00080 
00081         /// \brief enable tracing of a given step-collection at a given level (off=0)
00082         ///
00083         /// To be used in a safe environment only (no steps in flight)
00084         /// \param sc  the step-collection to be traced
00085         /// \param level trace level
00086         template< typename UserStep, typename Tuner >
00087         static void trace( step_collection< UserStep, Tuner > & sc, int level = 1 )
00088         {
00089             sc.set_tracing( level );
00090             CNC_ASSERT( sc.trace_level() == level );
00091         }
00092         
00093         /// \brief enable tracing of graph internals (not including its I/O collections)
00094         ///
00095         /// To be used in a safe environment only (no steps in flight)
00096         /// names of collections are unavailable unless tracing them was enabled explicitly.
00097         /// \param g     the graph to be traced
00098         /// \param level trace level
00099         static void CNC_API trace( ::CnC::graph & g, int level = 1 );
00100 
00101         /// \brief enable tracing of everything in given context (off=0)
00102         ///
00103         /// To be used in a safe environment only (no steps in flight)
00104         /// \param c     the context to be traced
00105         /// \param level trace level
00106         template< class Derived >
00107         static void trace_all( ::CnC::context< Derived > & c, int level = 1 )
00108         { c.set_tracing( level ); }
00109 
00110         /// \brief initalize timer
00111         /// \param cycle if true, use cycle counter only
00112         /// Cycle counters might overflow: TSC results are incorrect if the measured time-interval
00113         /// is larger than a full turn-around.
00114         static void init_timer( bool cycle = false )
00115         { Internal::chronometer::init( cycle ); }
00116 
00117         /// \brief save collected time log to a specified file
00118         /// \param name  the file to write the time log, pass "-" for printing to stdout
00119         static void finalize_timer( const char * name )
00120         { Internal::chronometer::save_log( name ? name : "-" ); }
00121 
00122         /// \brief enable timing of a given step
00123         ///
00124         /// To be used in a safe environment only (no steps in flight)
00125         /// \param sc  the step-collection to be timed
00126         template< typename UserStep, typename Tuner >
00127         static void time( step_collection< UserStep, Tuner > & sc )
00128         { sc.set_timing(); }
00129 
00130         /// \brief enable collection scheduler statistics per context
00131         ///
00132         /// Statistics will be print upon destructino of a context.
00133         /// \param c     the context to be examined
00134         template< class Derived >
00135         static void collect_scheduler_statistics( ::CnC::context< Derived > & c )
00136         { c.init_scheduler_statistics(); }
00137     };
00138 
00139 } // namespace cnc
00140 
00141 #endif // _CnC_DEBUG_H_
 All Classes Namespaces Functions Variables Typedefs Enumerator Friends