| 544 | } |
| 545 | |
| 546 | void DumpGraphvizVideoFrame(const Model& model) { |
| 547 | namespace port = toco::port; |
| 548 | |
| 549 | const auto& dump_options = *GraphVizDumpOptions::singleton(); |
| 550 | if (!dump_options.dump_graphviz_video) { |
| 551 | return; |
| 552 | } |
| 553 | CHECK(!dump_options.dump_graphviz.empty()); |
| 554 | // TODO(benoitjacob): the static data here means that this function |
| 555 | // is stateful, not reentrant, and effectively leaks memory till exit |
| 556 | // (since dump_hashes can only grow in size). It also means that it |
| 557 | // really only is intended to be called for a single model during the |
| 558 | // process' lifetime. So it's not great design at all. The overriding |
| 559 | // design aspect here is to make the video-dumping code as unintrusive |
| 560 | // and self-contained as possible. Eventually, we'll want to have that |
| 561 | // cleaned-up, but that will require some form of general statefulness |
| 562 | // in toco (some kind of 'tooling state' data structure) that does |
| 563 | // not exist at present, and would be premature to design here just for |
| 564 | // this new video-dumping feature. |
| 565 | static int dump_id = 0; |
| 566 | static std::unordered_set<std::size_t> dump_hashes; |
| 567 | string graphviz_dump; |
| 568 | DumpGraphviz(model, &graphviz_dump, |
| 569 | toco::port::StringF("VIDEO frame:%05d", dump_id)); |
| 570 | std::size_t hash = std::hash<string>{}(graphviz_dump); |
| 571 | if (!dump_hashes.count(hash)) { |
| 572 | LOG(INFO) << "DUMPING GRAPHVIZ VIDEO FRAME: " << dump_id; |
| 573 | dump_hashes.insert(hash); |
| 574 | const auto result = port::file::SetContents( |
| 575 | port::file::JoinPath( |
| 576 | dump_options.dump_graphviz, |
| 577 | toco::port::StringF("toco_video_%05d.dot", dump_id)), |
| 578 | graphviz_dump, port::file::Defaults()); |
| 579 | QCHECK(result.ok()) << result.error_message(); |
| 580 | dump_id++; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | void LogDump(int log_level, const string& message, const Model& model) { |
| 585 | namespace port = toco::port; |
no test coverage detected