| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2000-2022 Inria | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions are met: | ||
| 7 | * | ||
| 8 | * * Redistributions of source code must retain the above copyright notice, | ||
| 9 | * this list of conditions and the following disclaimer. | ||
| 10 | * * Redistributions in binary form must reproduce the above copyright notice, | ||
| 11 | * this list of conditions and the following disclaimer in the documentation | ||
| 12 | * and/or other materials provided with the distribution. | ||
| 13 | * * Neither the name of the ALICE Project-Team nor the names of its | ||
| 14 | * contributors may be used to endorse or promote products derived from this | ||
| 15 | * software without specific prior written permission. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | * | ||
| 29 | * Contact: Bruno Levy | ||
| 30 | * | ||
| 31 | * https://www.inria.fr/fr/bruno-levy | ||
| 32 | * | ||
| 33 | * Inria, | ||
| 34 | * Domaine de Voluceau, | ||
| 35 | * 78150 Le Chesnay - Rocquencourt | ||
| 36 | * FRANCE | ||
| 37 | * | ||
| 38 | */ | ||
| 39 | |||
| 40 | #ifndef H_HEXDOM_ALGO_TIME_LOG_H | ||
| 41 | #define H_HEXDOM_ALGO_TIME_LOG_H | ||
| 42 | |||
| 43 | #include <exploragram/basic/common.h> | ||
| 44 | #include <string> | ||
| 45 | #include <iostream> | ||
| 46 | #include <vector> | ||
| 47 | #include <time.h> | ||
| 48 | #include <fstream> | ||
| 49 | |||
| 50 | /** | ||
| 51 | * LogTime reports a hierarchical execution pipeline: | ||
| 52 | * A logger outputs the steps during execution | ||
| 53 | * It summarizes execution time in each step | ||
| 54 | * It outputs important values (stats) at the end of the execution | ||
| 55 | */ | ||
| 56 | |||
| 57 | struct EXPLORAGRAM_API LogTime { | ||
| 58 | // _ ___ ___ | ||
| 59 | // /_\ | _ \_ _| | ||
| 60 | // / _ \| _/| | | ||
| 61 | // /_/ \_\_| |___| | ||
| 62 | // | ||
| 63 | ✗ | LogTime() { post_fix = ""; } | |
| 64 | ✗ | ~LogTime(){} | |
| 65 | // construct API | ||
| 66 | /** | ||
| 67 | * put it before starting a new task of the pipeline | ||
| 68 | */ | ||
| 69 | void add_step(const std::string& name); | ||
| 70 | |||
| 71 | /** | ||
| 72 | * start/end section to define tasks that will be split into smaller tasks | ||
| 73 | */ | ||
| 74 | void start_section(const std::string& secname, const std::string& name = "begin section"); | ||
| 75 | void end_section(); | ||
| 76 | |||
| 77 | /** | ||
| 78 | * values are used to get feedback (mostly quality stats) | ||
| 79 | */ | ||
| 80 | void add_value(std::string str, double val); | ||
| 81 | |||
| 82 | /** | ||
| 83 | * values are used to get feedback (mostly quality stats) | ||
| 84 | */ | ||
| 85 | void add_string(std::string str, std::string val); | ||
| 86 | |||
| 87 | // output API | ||
| 88 | |||
| 89 | /** | ||
| 90 | * show is to have the summary in the console | ||
| 91 | */ | ||
| 92 | void show(); | ||
| 93 | /** | ||
| 94 | * drop_file is to have the summary in a file. | ||
| 95 | */ | ||
| 96 | void drop_file(std::string filename, bool append = false,unsigned int timing_depth=1000); | ||
| 97 | |||
| 98 | void set_suffix(const std::string& suffix) { post_fix=suffix; } | ||
| 99 | // _ _ | ||
| 100 | // _ __ _ _(_)_ ____ _| |_ ___ | ||
| 101 | // | '_ \ '_| \ V / _` | _/ -_) | ||
| 102 | // | .__/_| |_|\_/\__,_|\__\___| | ||
| 103 | // |_| | ||
| 104 | |||
| 105 | private: | ||
| 106 | /** | ||
| 107 | * CheckPoint is the list item of LogTime | ||
| 108 | * "up" is it's father | ||
| 109 | * "right" is the next item at the same level | ||
| 110 | */ | ||
| 111 | struct CheckPoint{ | ||
| 112 | ✗ | CheckPoint(const std::string& p_n, unsigned int p_up){ n = p_n; up = p_up; t = clock(); right = (unsigned int)(-1); } | |
| 113 | std::string n; | ||
| 114 | clock_t t; | ||
| 115 | unsigned int right; | ||
| 116 | unsigned int up; | ||
| 117 | }; | ||
| 118 | |||
| 119 | bool is_start_section(unsigned int i); | ||
| 120 | bool is_end_section(unsigned int i); | ||
| 121 | bool is_final(unsigned int i); | ||
| 122 | double time(unsigned int i); | ||
| 123 | unsigned int dec(unsigned int i = (unsigned int)(-1)); | ||
| 124 | unsigned int lastdec(); | ||
| 125 | void debug(); | ||
| 126 | std::string cur_stack(); | ||
| 127 | void report(std::ostream &out, unsigned int timing_depth = 10000); | ||
| 128 | void report_py(std::ostream &out, unsigned int timing_depth = 10000); | ||
| 129 | |||
| 130 | private: | ||
| 131 | std::string post_fix; | ||
| 132 | std::vector<CheckPoint> check; | ||
| 133 | std::vector<std::pair<std::string, double> > out_values; | ||
| 134 | std::vector<std::pair<std::string, std::string> > out_strings; | ||
| 135 | }; | ||
| 136 | |||
| 137 | extern EXPLORAGRAM_API LogTime logt; | ||
| 138 | |||
| 139 | #endif | ||
| 140 |