timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::operation::finalize::print< Tp, true > Struct Template Reference

#include "timemory/operations/types.hpp"

+ Collaboration diagram for tim::operation::finalize::print< Tp, true >:

Public Types

using base_type = base::print
 
using this_type = print< Tp, has_data >
 
using type = Tp
 
using storage_type = impl::storage< Tp, has_data >
 
using result_type = typename storage_type::dmp_result_t
 
using result_node = typename storage_type::result_node
 
using graph_type = typename storage_type::graph_t
 
using graph_node = typename storage_type::graph_node
 
using hierarchy_type = std::vector< uint64_t >
 
using callback_type = std::function< void(this_type *)>
 
using stream_type = std::shared_ptr< utility::stream >
 
using basic_tree_type = basic_tree< node::tree< Tp > >
 
using basic_tree_vector_type = std::vector< basic_tree_type >
 
using result_tree = std::map< std::string, std::vector< basic_tree_vector_type > >
 
using settings_t = std::shared_ptr< settings >
 

Public Member Functions

 print (storage_type *_data, const settings_t &_settings=settings::shared_instance())
 
 print (const std::string &_label, storage_type *_data, const settings_t &_settings=settings::shared_instance())
 
 ~print () override=default
 
void execute () override
 
void update_data () override
 
void setup () override
 
void read_json () override
 
void print_dart () override
 
void print_custom () override
 
virtual void print_tree (const std::string &fname, result_tree &rt)
 
void write_stream (stream_type &stream, result_type &results)
 
void print_json (const std::string &fname, result_type &results)
 
const auto & get_data () const
 
const auto & get_node_results () const
 
const auto & get_node_input () const
 
const auto & get_node_delta () const
 
std::vector< result_node * > get_flattened (result_type &results)
 
virtual void write (std::ostream &os, stream_type stream)
 
virtual void print_cout (stream_type stream)
 
virtual void print_text (const std::string &fname, stream_type stream)
 
virtual void print_plot (const std::string &fname, std::string suffix)
 
auto get_label () const
 
auto get_text_output_name () const
 
auto get_tree_output_name () const
 
auto get_json_output_name () const
 
auto get_json_input_name () const
 
auto get_text_diff_name () const
 
auto get_json_diff_name () const
 
void set_debug (bool v)
 
void set_update (bool v)
 
void set_verbose (int32_t v)
 
void set_max_call_stack (int64_t v)
 
int64_t get_max_depth () const
 
bool dart_output ()
 
bool file_output ()
 
bool cout_output ()
 
bool tree_output ()
 
bool json_output ()
 
bool text_output ()
 
bool plot_output ()
 
bool flame_output ()
 

Static Public Member Functions

static callback_typeget_default_callback ()
 

Static Public Attributes

static constexpr bool has_data = true
 

Protected Attributes

storage_typedata = nullptr
 
callback_type callback = get_default_callback()
 
result_type node_results = {}
 
result_type node_input = {}
 
result_type node_delta = {}
 
result_tree node_tree = {}
 
settings_t m_settings = settings::shared_instance()
 
bool debug = false
 
bool update = true
 
bool json_forced = false
 
bool node_init = dmp::is_initialized()
 
int32_t node_rank = dmp::rank()
 
int32_t node_size = dmp::size()
 
int32_t verbose = 0
 
int64_t max_depth = 0
 
int64_t max_call_stack = std::numeric_limits<int64_t>::max()
 
std::string label = ""
 
std::string description = ""
 
std::string text_outfname = ""
 
std::string tree_outfname = ""
 
std::string json_outfname = ""
 
std::string json_inpfname = ""
 
std::string text_diffname = ""
 
std::string json_diffname = ""
 
stream_type data_stream = stream_type{}
 
stream_type diff_stream = stream_type{}
 

Detailed Description

template<typename Tp>
struct tim::operation::finalize::print< Tp, true >

Definition at line 1344 of file types.hpp.

Member Typedef Documentation

◆ base_type

Definition at line 1347 of file types.hpp.

◆ basic_tree_type

Definition at line 1358 of file types.hpp.

◆ basic_tree_vector_type

Definition at line 1359 of file types.hpp.

◆ callback_type

template<typename Tp >
using tim::operation::finalize::print< Tp, true >::callback_type = std::function<void(this_type*)>

Definition at line 1356 of file types.hpp.

◆ graph_node

template<typename Tp >
using tim::operation::finalize::print< Tp, true >::graph_node = typename storage_type::graph_node

Definition at line 1354 of file types.hpp.

◆ graph_type

template<typename Tp >
using tim::operation::finalize::print< Tp, true >::graph_type = typename storage_type::graph_t

Definition at line 1353 of file types.hpp.

◆ hierarchy_type

template<typename Tp >
using tim::operation::finalize::print< Tp, true >::hierarchy_type = std::vector<uint64_t>

Definition at line 1355 of file types.hpp.

◆ result_node

template<typename Tp >
using tim::operation::finalize::print< Tp, true >::result_node = typename storage_type::result_node

Definition at line 1352 of file types.hpp.

◆ result_tree

template<typename Tp >
using tim::operation::finalize::print< Tp, true >::result_tree = std::map<std::string, std::vector<basic_tree_vector_type> >

Definition at line 1360 of file types.hpp.

◆ result_type

template<typename Tp >
using tim::operation::finalize::print< Tp, true >::result_type = typename storage_type::dmp_result_t

Definition at line 1351 of file types.hpp.

◆ settings_t

using tim::operation::finalize::base::print::settings_t = std::shared_ptr<settings>
inherited

Definition at line 1174 of file types.hpp.

◆ storage_type

template<typename Tp >
using tim::operation::finalize::print< Tp, true >::storage_type = impl::storage<Tp, has_data>

Definition at line 1350 of file types.hpp.

◆ stream_type

template<typename Tp >
using tim::operation::finalize::print< Tp, true >::stream_type = std::shared_ptr<utility::stream>

Definition at line 1357 of file types.hpp.

◆ this_type

Definition at line 1348 of file types.hpp.

◆ type

template<typename Tp >
using tim::operation::finalize::print< Tp, true >::type = Tp

Definition at line 1349 of file types.hpp.

Constructor & Destructor Documentation

◆ print() [1/2]

template<typename Tp >
tim::operation::finalize::print< Tp, true >::print ( storage_type _data,
const settings_t _settings = settings::shared_instance() 
)
explicit

Definition at line 118 of file print.hpp.

119: base_type(trait::requires_json<Tp>::value, _settings)
120, data(_data)
121{
122 dmp::barrier();
123 node_init = dmp::is_initialized();
124 node_rank = dmp::rank();
125 node_size = dmp::size();
126 node_results = data->dmp_get();
127 if(tree_output())
128 node_tree = data->dmp_get(node_tree);
129 dmp::barrier();
130
131 settings::indent_width<Tp, 0>(Tp::get_width());
132 settings::indent_width<Tp, 1>(4);
133 settings::indent_width<Tp, 2>(4);
134
135 description = Tp::get_description();
136 for(auto& itr : description)
137 itr = toupper(itr);
138
139 // find the max width
140 for(const auto& mitr : node_results)
141 {
142 for(const auto& itr : mitr)
143 {
144 const auto& itr_obj = itr.data();
145 const auto& itr_prefix = itr.prefix();
146 const auto& itr_depth = itr.depth();
147
148 if(itr_depth < 0 || itr_depth > m_settings->get_max_depth() ||
149 itr_depth > max_call_stack)
150 continue;
151
152 max_depth = std::max<int64_t>(max_depth, itr_depth);
153
154 // find global max
155 settings::indent_width<Tp, 0>(itr_prefix.length());
156 settings::indent_width<Tp, 1>(std::log10(itr_obj.get_laps()) + 1);
157 settings::indent_width<Tp, 2>(std::log10(itr_depth) + 1);
158 }
159 }
160}
char argparse::argument_parser tim::settings * _settings
Definition: config.cpp:255

References tim::description(), tim::max_depth, and tim::tree_output.

◆ print() [2/2]

template<typename Tp >
tim::operation::finalize::print< Tp, true >::print ( const std::string &  _label,
storage_type _data,
const settings_t _settings = settings::shared_instance() 
)
inline

Definition at line 1371 of file types.hpp.

1373 : base_type(_label, trait::requires_json<Tp>::value, _settings)
1374 , data(_data)
1375 {}

◆ ~print()

template<typename Tp >
tim::operation::finalize::print< Tp, true >::~print ( )
overridevirtualdefault

Member Function Documentation

◆ cout_output()

bool tim::operation::finalize::base::print::cout_output ( )
inlineinherited

Definition at line 1255 of file types.hpp.

1256 {
1257 if(!m_settings)
1258 {
1259 PRINT_HERE("%s", "Null pointer to settings! Disabling");
1260 return false;
1261 }
1262 return m_settings->get_cout_output();
1263 }
#define PRINT_HERE(...)
Definition: macros.hpp:152

References tim::operation::finalize::base::print::m_settings, and PRINT_HERE.

◆ dart_output()

bool tim::operation::finalize::base::print::dart_output ( )
inlineinherited

Definition at line 1237 of file types.hpp.

1238 {
1239 if(!m_settings)
1240 {
1241 PRINT_HERE("%s", "Null pointer to settings! Disabling");
1242 return false;
1243 }
1244 return m_settings->get_dart_output();
1245 }

References tim::operation::finalize::base::print::m_settings, and PRINT_HERE.

◆ execute()

template<typename Tp >
void tim::operation::finalize::print< Tp, true >::execute ( )
inlineoverridevirtual

Implements tim::operation::finalize::base::print.

Definition at line 1379 of file types.hpp.

1380 {
1381 if(!data)
1382 return;
1383
1384 if(update)
1385 {
1386 update_data();
1387 }
1388 else
1389 {
1390 setup();
1391 }
1392
1393 if(node_init && node_rank > 0)
1394 return;
1395
1396 if(file_output())
1397 {
1398 if(json_output())
1400 if(tree_output())
1402 if(text_output())
1404 if(plot_output())
1406 }
1407
1408 if(cout_output())
1409 {
1411 }
1412 else
1413 {
1414 printf("\n");
1415 }
1416
1417 if(dart_output())
1418 print_dart();
1419
1420 if(!node_input.empty() && !node_delta.empty() && settings::diff_output())
1421 {
1422 if(file_output())
1423 {
1424 if(json_output())
1426 if(text_output())
1428 if(plot_output())
1429 {
1430 std::stringstream ss;
1431 ss << "Difference vs. " << json_inpfname;
1432 print_plot(json_diffname, ss.str());
1433 }
1434 }
1435
1436 if(cout_output())
1437 {
1439 }
1440 else
1441 {
1442 printf("\n");
1443 }
1444 }
1445
1446 print_custom();
1447 }
diff_output
Definition: settings.cpp:1630
virtual void print_cout(stream_type stream)
virtual void print_plot(const std::string &fname, std::string suffix)
virtual void print_text(const std::string &fname, stream_type stream)
virtual void print_tree(const std::string &fname, result_tree &rt)
Definition: print.hpp:474
void print_json(const std::string &fname, result_type &results)
Definition: print.hpp:435

References tim::cout_output, tim::dart_output, tim::diff_output, tim::file_output, tim::json_output, tim::plot_output, tim::text_output, and tim::tree_output.

◆ file_output()

bool tim::operation::finalize::base::print::file_output ( )
inlineinherited

Definition at line 1246 of file types.hpp.

1247 {
1248 if(!m_settings)
1249 {
1250 PRINT_HERE("%s", "Null pointer to settings! Disabling");
1251 return false;
1252 }
1253 return m_settings->get_file_output();
1254 }

References tim::operation::finalize::base::print::m_settings, and PRINT_HERE.

◆ flame_output()

bool tim::operation::finalize::base::print::flame_output ( )
inlineinherited

Definition at line 1303 of file types.hpp.

1304 {
1305 if(!m_settings)
1306 {
1307 PRINT_HERE("%s", "Null pointer to settings! Disabling");
1308 return false;
1309 }
1310 return m_settings->get_flamegraph_output() && m_settings->get_file_output();
1311 }

References tim::operation::finalize::base::print::m_settings, and PRINT_HERE.

◆ get_data()

template<typename Tp >
const auto & tim::operation::finalize::print< Tp, true >::get_data ( ) const
inline

Definition at line 1468 of file types.hpp.

1468{ return data; }

◆ get_default_callback()

template<typename Tp >
static callback_type & tim::operation::finalize::print< Tp, true >::get_default_callback ( )
inlinestatic

Definition at line 1362 of file types.hpp.

1363 {
1364 static callback_type _instance = [](this_type*) {};
1365 return _instance;
1366 }
std::function< void(this_type *)> callback_type
Definition: types.hpp:1356

◆ get_flattened()

template<typename Tp >
std::vector< result_node * > tim::operation::finalize::print< Tp, true >::get_flattened ( result_type results)
inline

Definition at line 1473 of file types.hpp.

1474 {
1475 std::vector<result_node*> flat;
1476 for(auto& ritr : results)
1477 {
1478 for(auto& itr : ritr)
1479 {
1480 flat.push_back(&itr);
1481 }
1482 }
1483 return flat;
1484 }

◆ get_json_diff_name()

auto tim::operation::finalize::base::print::get_json_diff_name ( ) const
inlineinherited

Definition at line 1223 of file types.hpp.

1223{ return json_diffname; }

References tim::operation::finalize::base::print::json_diffname.

◆ get_json_input_name()

auto tim::operation::finalize::base::print::get_json_input_name ( ) const
inlineinherited

Definition at line 1221 of file types.hpp.

1221{ return json_inpfname; }

References tim::operation::finalize::base::print::json_inpfname.

◆ get_json_output_name()

auto tim::operation::finalize::base::print::get_json_output_name ( ) const
inlineinherited

Definition at line 1220 of file types.hpp.

1220{ return json_outfname; }

References tim::operation::finalize::base::print::json_outfname.

◆ get_label()

auto tim::operation::finalize::base::print::get_label ( ) const
inlineinherited

Definition at line 1217 of file types.hpp.

1217{ return label; }

References tim::operation::finalize::base::print::label.

◆ get_max_depth()

int64_t tim::operation::finalize::base::print::get_max_depth ( ) const
inlineinherited

Definition at line 1230 of file types.hpp.

1231 {
1232 return (max_depth > 0)
1233 ? max_depth
1234 : std::min<int64_t>(max_call_stack, m_settings->get_max_depth());
1235 }

References tim::operation::finalize::base::print::m_settings, tim::operation::finalize::base::print::max_call_stack, and tim::operation::finalize::base::print::max_depth.

◆ get_node_delta()

template<typename Tp >
const auto & tim::operation::finalize::print< Tp, true >::get_node_delta ( ) const
inline

Definition at line 1471 of file types.hpp.

1471{ return node_delta; }

◆ get_node_input()

template<typename Tp >
const auto & tim::operation::finalize::print< Tp, true >::get_node_input ( ) const
inline

Definition at line 1470 of file types.hpp.

1470{ return node_input; }

◆ get_node_results()

template<typename Tp >
const auto & tim::operation::finalize::print< Tp, true >::get_node_results ( ) const
inline

Definition at line 1469 of file types.hpp.

1469{ return node_results; }

◆ get_text_diff_name()

auto tim::operation::finalize::base::print::get_text_diff_name ( ) const
inlineinherited

Definition at line 1222 of file types.hpp.

1222{ return text_diffname; }

References tim::operation::finalize::base::print::text_diffname.

◆ get_text_output_name()

auto tim::operation::finalize::base::print::get_text_output_name ( ) const
inlineinherited

Definition at line 1218 of file types.hpp.

1218{ return text_outfname; }

References tim::operation::finalize::base::print::text_outfname.

◆ get_tree_output_name()

auto tim::operation::finalize::base::print::get_tree_output_name ( ) const
inlineinherited

Definition at line 1219 of file types.hpp.

1219{ return tree_outfname; }

References tim::operation::finalize::base::print::tree_outfname.

◆ json_output()

bool tim::operation::finalize::base::print::json_output ( )
inlineinherited

Definition at line 1274 of file types.hpp.

1275 {
1276 if(!m_settings)
1277 {
1278 PRINT_HERE("%s", "Null pointer to settings! Disabling");
1279 return false;
1280 }
1281 return (m_settings->get_json_output() || json_forced) &&
1282 m_settings->get_file_output();
1283 }

References tim::operation::finalize::base::print::json_forced, tim::operation::finalize::base::print::m_settings, and PRINT_HERE.

◆ plot_output()

bool tim::operation::finalize::base::print::plot_output ( )
inlineinherited

Definition at line 1293 of file types.hpp.

1294 {
1295 if(!m_settings)
1296 {
1297 PRINT_HERE("%s", "Null pointer to settings! Disabling");
1298 return false;
1299 }
1300 return m_settings->get_plot_output() && m_settings->get_json_output() &&
1301 m_settings->get_file_output();
1302 }

References tim::operation::finalize::base::print::m_settings, and PRINT_HERE.

◆ print_cout()

virtual void tim::operation::finalize::base::print::print_cout ( stream_type  stream)
virtualinherited

◆ print_custom()

template<typename Tp >
void tim::operation::finalize::print< Tp, true >::print_custom ( )
inlineoverridevirtual

Implements tim::operation::finalize::base::print.

Definition at line 1454 of file types.hpp.

1455 {
1456 try
1457 {
1458 callback(this);
1459 } catch(std::exception& e)
1460 {
1461 fprintf(stderr, "Exception: %s\n", e.what());
1462 }
1463 }

◆ print_dart()

template<typename Tp >
void tim::operation::finalize::print< Tp, true >::print_dart
overridevirtual

Implements tim::operation::finalize::base::print.

Definition at line 512 of file print.hpp.

513{
514 using strvector_t = std::vector<std::string>;
515
516 // if only a specific type should be echoed
517 if(m_settings->get_dart_type().length() > 0)
518 {
519 auto dtype = m_settings->get_dart_type();
520 if(operation::echo_measurement<Tp>::lowercase(dtype) !=
521 operation::echo_measurement<Tp>::lowercase(label))
522 {
523 return;
524 }
525 }
526
527 uint64_t _nitr = 0;
528
529 auto indiv_results = get_flattened(node_results);
530 for(auto& itr : indiv_results)
531 {
532 auto& itr_depth = itr->depth();
533
534 if(itr_depth < 0 || itr_depth > max_depth)
535 continue;
536
537 // if only a specific number of measurements should be echoed
538 if(m_settings->get_dart_count() > 0 && _nitr >= m_settings->get_dart_count())
539 continue;
540
541 auto& itr_obj = itr->data();
542 auto& itr_hierarchy = itr->hierarchy();
543 strvector_t str_hierarchy{};
544 for(const auto& hitr : itr_hierarchy)
545 str_hierarchy.push_back(data->get_prefix(hitr));
546 operation::echo_measurement<Tp>(itr_obj, str_hierarchy);
547 ++_nitr;
548 }
549}
std::vector< result_node * > get_flattened(result_type &results)
Definition: types.hpp:1473

References tim::max_depth.

◆ print_json()

template<typename Tp >
void tim::operation::finalize::print< Tp, true >::print_json ( const std::string &  fname,
result_type results 
)

Definition at line 435 of file print.hpp.

436{
437 using policy_type = policy::output_archive_t<Tp>;
438 if(outfname.length() > 0)
439 {
440 std::ofstream ofs{};
441 if(filepath::open(ofs, outfname))
442 {
443 auto fext = outfname.substr(outfname.find_last_of('.') + 1);
444 if(fext.empty())
445 fext = "unknown";
446 manager::instance()->add_file_output(fext, label, outfname);
447 printf("[%s]|%i> Outputting '%s'...\n", label.c_str(), node_rank,
448 outfname.c_str());
449
450 // ensure write final block during destruction before the file is closed
451 auto oa = policy_type::get(ofs);
452
453 oa->setNextName("timemory");
454 oa->startNode();
455 operation::serialization<Tp>{}(*oa, results);
456 oa->finishNode(); // timemory
457 }
458 else
459 {
460 fprintf(stderr, "[storage<%s>::%s @ %i]|%i> Error opening '%s'...\n",
461 label.c_str(), __FUNCTION__, __LINE__, node_rank, outfname.c_str());
462 return;
463 }
464 if(ofs)
465 ofs << std::endl;
466 ofs.close();
467 }
468}
static pointer_t instance()
Get a shared pointer to the instance for the current thread.
bool open(std::ofstream &_ofs, std::string _fpath, Args &&... _args)
Definition: filepath.hpp:207
auto get(const auto_bundle< Tag, Types... > &_obj)

References tim::get(), tim::manager::instance(), and tim::filepath::open().

◆ print_plot()

virtual void tim::operation::finalize::base::print::print_plot ( const std::string &  fname,
std::string  suffix 
)
virtualinherited

◆ print_text()

virtual void tim::operation::finalize::base::print::print_text ( const std::string &  fname,
stream_type  stream 
)
virtualinherited

◆ print_tree()

template<typename Tp >
void tim::operation::finalize::print< Tp, true >::print_tree ( const std::string &  fname,
result_tree rt 
)
virtual

Definition at line 474 of file print.hpp.

475{
476 using policy_type = policy::output_archive_t<Tp>;
477
478 if(outfname.length() > 0)
479 {
480 auto fext = outfname.substr(outfname.find_last_of('.') + 1);
481 if(fext.empty())
482 fext = "unknown";
483 manager::instance()->add_file_output(fext, label, outfname);
484 printf("[%s]|%i> Outputting '%s'...\n", label.c_str(), node_rank,
485 outfname.c_str());
486 std::ofstream ofs{};
487 if(filepath::open(ofs, outfname))
488 {
489 // ensure write final block during destruction before the file is closed
490 auto oa = policy_type::get(ofs);
491
492 oa->setNextName("timemory");
493 oa->startNode();
494 operation::serialization<Tp>{}(*oa, rt);
495 oa->finishNode();
496 }
497 else
498 {
499 fprintf(stderr, "[storage<%s>::%s @ %i]|%i> Error opening '%s'...\n",
500 label.c_str(), __FUNCTION__, __LINE__, node_rank, outfname.c_str());
501 return;
502 }
503 ofs << std::endl;
504 ofs.close();
505 }
506}

References tim::get(), tim::manager::instance(), and tim::filepath::open().

◆ read_json()

template<typename Tp >
void tim::operation::finalize::print< Tp, true >::read_json
overridevirtual

Implements tim::operation::finalize::base::print.

Definition at line 555 of file print.hpp.

556{
557 using policy_type = policy::input_archive_t<Tp>;
558
559 if(json_inpfname.length() > 0)
560 {
561 std::ifstream ifs(json_inpfname.c_str());
562 if(ifs)
563 {
564 printf("[%s]|%i> Reading '%s'...\n", label.c_str(), node_rank,
565 json_inpfname.c_str());
566
567 // ensure write final block during destruction before the file is closed
568 auto ia = policy_type::get(ifs);
569
570 try
571 {
572 ia->setNextName("timemory");
573 ia->startNode();
574 operation::serialization<Tp>{}(*ia, node_input);
575 ia->finishNode();
576 } catch(tim::cereal::Exception& e)
577 {
578 PRINT_HERE("Exception reading %s :: %s", json_inpfname.c_str(), e.what());
579#if defined(TIMEMORY_INTERNAL_TESTING)
581 throw std::runtime_error("error reading json");
582#endif
583 }
584 }
585 else
586 {
587 fprintf(stderr, "[%s]|%i> Failure opening '%s' for input...\n", label.c_str(),
588 node_rank, json_inpfname.c_str());
589#if defined(TIMEMORY_INTERNAL_TESTING)
590 throw std::runtime_error("error opening file");
591#endif
592 }
593 ifs.close();
594 }
595}
#define TIMEMORY_CONDITIONAL_DEMANGLED_BACKTRACE(CONDITION, DEPTH)
Definition: macros.hpp:202

References tim::get(), PRINT_HERE, and TIMEMORY_CONDITIONAL_DEMANGLED_BACKTRACE.

◆ set_debug()

void tim::operation::finalize::base::print::set_debug ( bool  v)
inlineinherited

Definition at line 1225 of file types.hpp.

References tim::operation::finalize::base::print::debug.

◆ set_max_call_stack()

void tim::operation::finalize::base::print::set_max_call_stack ( int64_t  v)
inlineinherited

Definition at line 1228 of file types.hpp.

1228{ max_call_stack = v; }

References tim::operation::finalize::base::print::max_call_stack.

◆ set_update()

void tim::operation::finalize::base::print::set_update ( bool  v)
inlineinherited

Definition at line 1226 of file types.hpp.

1226{ update = v; }

References tim::operation::finalize::base::print::update.

◆ set_verbose()

void tim::operation::finalize::base::print::set_verbose ( int32_t  v)
inlineinherited

Definition at line 1227 of file types.hpp.

References tim::operation::finalize::base::print::verbose.

◆ setup()

template<typename Tp >
void tim::operation::finalize::print< Tp, true >::setup
overridevirtual

Implements tim::operation::finalize::base::print.

Definition at line 166 of file print.hpp.

167{
168 settings::indent_width<Tp, 0>(Tp::get_width());
169 settings::indent_width<Tp, 1>(4);
170 settings::indent_width<Tp, 2>(4);
171
172 description = Tp::get_description();
173 for(auto& itr : description)
174 itr = toupper(itr);
175
176 // find the max width
177 for(const auto& mitr : node_results)
178 {
179 for(const auto& itr : mitr)
180 {
181 const auto& itr_obj = itr.data();
182 const auto& itr_prefix = itr.prefix();
183 const auto& itr_depth = itr.depth();
184
185 if(itr_depth < 0 || itr_depth > m_settings->get_max_depth() ||
186 itr_depth > max_call_stack)
187 continue;
188
189 max_depth = std::max<int64_t>(max_depth, itr_depth);
190
191 // find global max
192 settings::indent_width<Tp, 0>(itr_prefix.length());
193 settings::indent_width<Tp, 1>(std::log10(itr_obj.get_laps()) + 1);
194 settings::indent_width<Tp, 2>(std::log10(itr_depth) + 1);
195 }
196 }
197
198 auto file_exists = [](const std::string& fname) {
199 std::cout << "Checking for existing input at " << fname << "...\n";
200 std::ifstream inpf(fname.c_str());
201 auto success = inpf.is_open();
202 inpf.close();
203 return success;
204 };
205
206 auto fext = trait::archive_extension<trait::output_archive_t<Tp>>{}();
207 auto extensions = tim::delimit(m_settings->get_input_extensions(), ",; ");
208
212
213 if(m_settings->get_diff_output())
214 {
215 extensions.insert(extensions.begin(), fext);
216 for(const auto& itr : extensions)
217 {
218 auto inpfname = settings::compose_input_filename(label, itr);
219 if(file_exists(inpfname))
220 {
221 json_inpfname = inpfname;
222 break;
223 }
224 }
225 }
226
227 if(!json_inpfname.empty())
228 {
229 auto dext = std::string(".diff") + fext;
232 if(m_settings->get_debug())
233 {
234 printf("difference filenames: '%s' and '%s'\n", json_diffname.c_str(),
235 text_diffname.c_str());
236 }
237 }
238
239 if(!(file_output() && text_output()) && !cout_output())
240 return;
241
243 data_stream->set_banner(description);
244
245 if(!node_delta.empty())
246 {
248 std::stringstream ss;
249 ss << description << " vs. " << json_inpfname;
250 diff_stream->set_banner(ss.str());
251 }
252}
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
ContainerT delimit(const std::string &line, const std::string &delimiters="\"',;: ", PredicateT &&predicate=[](const std::string &s) -> std::string { return s;})
Definition: delimit.hpp:68
void write_stream(stream_type &stream, result_type &results)
Definition: print.hpp:258
static string_t compose_output_filename(string_t _tag, string_t _ext, bool _use_suffix=use_output_suffix(), int32_t _suffix=default_process_suffix(), bool _make_dir=false, std::string _explicit={})
Definition: settings.cpp:322
static string_t compose_input_filename(string_t _tag, string_t _ext, bool _use_suffix=use_output_suffix(), int32_t _suffix=default_process_suffix(), std::string _explicit={})
Definition: settings.cpp:363

References tim::settings::compose_input_filename(), tim::settings::compose_output_filename(), tim::cout_output, tim::delimit(), tim::description(), tim::file_output, tim::max_depth, and tim::text_output.

◆ text_output()

bool tim::operation::finalize::base::print::text_output ( )
inlineinherited

Definition at line 1284 of file types.hpp.

1285 {
1286 if(!m_settings)
1287 {
1288 PRINT_HERE("%s", "Null pointer to settings! Disabling");
1289 return false;
1290 }
1291 return m_settings->get_text_output() && m_settings->get_file_output();
1292 }

References tim::operation::finalize::base::print::m_settings, and PRINT_HERE.

◆ tree_output()

bool tim::operation::finalize::base::print::tree_output ( )
inlineinherited

Definition at line 1264 of file types.hpp.

1265 {
1266 if(!m_settings)
1267 {
1268 PRINT_HERE("%s", "Null pointer to settings! Disabling");
1269 return false;
1270 }
1271 return (m_settings->get_tree_output() || json_forced) &&
1272 m_settings->get_file_output();
1273 }

References tim::operation::finalize::base::print::json_forced, tim::operation::finalize::base::print::m_settings, and PRINT_HERE.

◆ update_data()

template<typename Tp >
void tim::operation::finalize::print< Tp, true >::update_data
overridevirtual

Implements tim::operation::finalize::base::print.

Definition at line 352 of file print.hpp.

353{
354 dmp::barrier();
355 node_init = dmp::is_initialized();
356 node_rank = dmp::rank();
357 node_size = dmp::size();
358 node_results = data->dmp_get();
359 if(tree_output())
360 node_tree = data->dmp_get(node_tree);
361 dmp::barrier();
362
363 if(m_settings->get_debug())
364 {
365 printf("[%s]|%i> dmp results size: %i\n", label.c_str(), node_rank,
366 (int) node_results.size());
367 }
368
369 setup();
370
371 read_json();
372
373 if(!node_input.empty() && node_rank == 0)
374 {
375 node_delta.resize(node_input.size());
376
377 size_t num_ranks = std::min<size_t>(node_input.size(), node_results.size());
378
379 for(size_t i = 0; i < num_ranks; ++i)
380 {
381 for(auto& iitr : node_input.at(i))
382 {
383 for(auto& ritr : node_results.at(i))
384 {
385 if(iitr == ritr)
386 {
387 node_delta.at(i).push_back(ritr);
388 node_delta.at(i).back() -= iitr;
389 break;
390 }
391 }
392 }
393 }
395 std::stringstream ss;
396 ss << description << " vs. " << json_inpfname;
397 diff_stream->set_banner(ss.str());
398 }
399
400#if defined(DEBUG)
401 if(m_settings->get_debug() && m_settings->get_verbose() > 3)
402 {
403 auto indiv_results = get_flattened(node_results);
404 printf("\n");
405 size_t w = 0;
406 for(const auto& itr : indiv_results)
407 w = std::max<size_t>(w, data->get_prefix(itr->hash()).length());
408 for(const auto& itr : indiv_results)
409 {
410 std::cout << std::setw(w) << std::left << data->get_prefix(itr->hash())
411 << " : " << itr->data();
412 auto _hierarchy = itr->hierarchy();
413 for(size_t i = 0; i < _hierarchy.size(); ++i)
414 {
415 if(i == 0)
416 std::cout << " :: ";
417 std::cout << data->get_prefix(_hierarchy[i]);
418 if(i + 1 < _hierarchy.size())
419 std::cout << '/';
420 }
421 std::cout << std::endl;
422 }
423 printf("\n");
424 }
425#endif
426
427 if(flame_output())
428 operation::finalize::flamegraph<Tp>(data, label);
429}

References tim::description(), and tim::tree_output.

◆ write()

virtual void tim::operation::finalize::base::print::write ( std::ostream &  os,
stream_type  stream 
)
virtualinherited

◆ write_stream()

template<typename Tp >
void tim::operation::finalize::print< Tp, true >::write_stream ( stream_type stream,
result_type results 
)

Definition at line 258 of file print.hpp.

259{
260 auto stream_fmt = Tp::get_format_flags();
261 auto stream_width = Tp::get_width();
262 auto stream_prec = Tp::get_precision();
263
264 stream = std::make_shared<utility::stream>('|', '-', stream_fmt, stream_width,
265 stream_prec);
266
267 using get_return_type = decltype(std::declval<const Tp>().get());
268 using compute_type = math::compute<get_return_type>;
269
270 auto_lock_t slk(type_mutex<decltype(std::cout)>(), std::defer_lock);
271 if(!slk.owns_lock())
272 slk.lock();
273
274 auto result = get_flattened(result_array);
275 for(auto itr = result.begin(); itr != result.end(); ++itr)
276 {
277 auto& itr_obj = (*itr)->data();
278 auto& itr_prefix = (*itr)->prefix();
279 auto& itr_depth = (*itr)->depth();
280 auto itr_laps = itr_obj.get_laps();
281
282 if(itr_depth < 0 || itr_depth > get_max_depth())
283 continue;
284
285 // counts the number of non-exclusive values
286 int64_t nexclusive = 0;
287 // the sum of the exclusive values
288 get_return_type exclusive_values{};
289
290 // if we are not at the bottom of the call stack (i.e. completely
291 // inclusive)
292 if(itr_depth < max_depth)
293 {
294 // get the next iteration
295 auto eitr = itr;
296 std::advance(eitr, 1);
297 // counts the number of non-exclusive values
298 nexclusive = 0;
299 // the sum of the exclusive values
300 exclusive_values = get_return_type{};
301 // continue while not at end of graph until first sibling is
302 // encountered
303 if(eitr != result.end())
304 {
305 auto eitr_depth = (*eitr)->depth();
306 while(eitr_depth != itr_depth)
307 {
308 auto& eitr_obj = (*eitr)->data();
309
310 // if one level down, this is an exclusive value
311 if(eitr_depth == itr_depth + 1)
312 {
313 // if first exclusive value encountered: assign; else: combine
314 if(nexclusive == 0)
315 {
316 exclusive_values = eitr_obj.get();
317 }
318 else
319 {
320 compute_type::plus(exclusive_values, eitr_obj.get());
321 }
322 // increment. beyond 0 vs. 1, this value plays no role
323 ++nexclusive;
324 }
325 // increment iterator for next while check
326 ++eitr;
327 if(eitr == result.end())
328 break;
329 eitr_depth = (*eitr)->depth();
330 }
331 }
332 }
333
334 auto itr_self = compute_type::percent_diff(exclusive_values, itr_obj.get());
335 auto itr_stats = (*itr)->stats();
336
337 bool _first = std::distance(result.begin(), itr) == 0;
338 if(_first)
339 operation::print_header<Tp>(itr_obj, *(stream.get()), itr_stats);
340
341 operation::print<Tp>(itr_obj, *(stream.get()), itr_prefix, itr_laps, itr_depth,
342 itr_self, itr_stats);
343
344 stream->add_row();
345 }
346}
Tp & plus(Tp &, const Up &)
Definition: plus.hpp:106
Tp percent_diff(const Tp &, const Tp &)
data::stream stream
Definition: stream.hpp:982
MutexT & type_mutex(uint64_t _n=0)
A simple way to get a mutex for a class or common behavior, e.g. type_mutex<decltype(std::cout)>() pr...
Definition: locking.hpp:57
std::unique_lock< mutex_t > auto_lock_t
Unique lock type around mutex_t.
Definition: locking.hpp:42
int add_row()
indicate that a row of data has been finished
Definition: stream.hpp:693

References tim::data::stream::add_row(), tim::max_depth, tim::math::percent_diff(), tim::math::plus(), and tim::type_mutex().

Member Data Documentation

◆ callback

template<typename Tp >
callback_type tim::operation::finalize::print< Tp, true >::callback = get_default_callback()
protected

Definition at line 1489 of file types.hpp.

◆ data

template<typename Tp >
storage_type* tim::operation::finalize::print< Tp, true >::data = nullptr
protected

Definition at line 1488 of file types.hpp.

◆ data_stream

stream_type tim::operation::finalize::base::print::data_stream = stream_type{}
protectedinherited

Definition at line 1333 of file types.hpp.

◆ debug

bool tim::operation::finalize::base::print::debug = false
protectedinherited

◆ description

std::string tim::operation::finalize::base::print::description = ""
protectedinherited

Definition at line 1326 of file types.hpp.

◆ diff_stream

stream_type tim::operation::finalize::base::print::diff_stream = stream_type{}
protectedinherited

Definition at line 1334 of file types.hpp.

◆ has_data

template<typename Tp >
constexpr bool tim::operation::finalize::print< Tp, true >::has_data = true
staticconstexpr

Definition at line 1346 of file types.hpp.

◆ json_diffname

std::string tim::operation::finalize::base::print::json_diffname = ""
protectedinherited

◆ json_forced

bool tim::operation::finalize::base::print::json_forced = false
protectedinherited

◆ json_inpfname

std::string tim::operation::finalize::base::print::json_inpfname = ""
protectedinherited

◆ json_outfname

std::string tim::operation::finalize::base::print::json_outfname = ""
protectedinherited

◆ label

std::string tim::operation::finalize::base::print::label = ""
protectedinherited

◆ m_settings

◆ max_call_stack

int64_t tim::operation::finalize::base::print::max_call_stack = std::numeric_limits<int64_t>::max()
protectedinherited

◆ max_depth

int64_t tim::operation::finalize::base::print::max_depth = 0
protectedinherited

Definition at line 1323 of file types.hpp.

Referenced by tim::operation::finalize::base::print::get_max_depth().

◆ node_delta

template<typename Tp >
result_type tim::operation::finalize::print< Tp, true >::node_delta = {}
protected

Definition at line 1492 of file types.hpp.

◆ node_init

bool tim::operation::finalize::base::print::node_init = dmp::is_initialized()
protectedinherited

Definition at line 1319 of file types.hpp.

◆ node_input

template<typename Tp >
result_type tim::operation::finalize::print< Tp, true >::node_input = {}
protected

Definition at line 1491 of file types.hpp.

◆ node_rank

int32_t tim::operation::finalize::base::print::node_rank = dmp::rank()
protectedinherited

Definition at line 1320 of file types.hpp.

Referenced by tim::operation::finalize::TIMEMORY_OPERATIONS_LINKAGE().

◆ node_results

template<typename Tp >
result_type tim::operation::finalize::print< Tp, true >::node_results = {}
protected

Definition at line 1490 of file types.hpp.

◆ node_size

int32_t tim::operation::finalize::base::print::node_size = dmp::size()
protectedinherited

Definition at line 1321 of file types.hpp.

◆ node_tree

template<typename Tp >
result_tree tim::operation::finalize::print< Tp, true >::node_tree = {}
protected

Definition at line 1493 of file types.hpp.

◆ text_diffname

std::string tim::operation::finalize::base::print::text_diffname = ""
protectedinherited

◆ text_outfname

std::string tim::operation::finalize::base::print::text_outfname = ""
protectedinherited

◆ tree_outfname

std::string tim::operation::finalize::base::print::tree_outfname = ""
protectedinherited

◆ update

bool tim::operation::finalize::base::print::update = true
protectedinherited

Definition at line 1317 of file types.hpp.

Referenced by tim::operation::finalize::base::print::set_update().

◆ verbose

int32_t tim::operation::finalize::base::print::verbose = 0
protectedinherited

The documentation for this struct was generated from the following files: