1 | /* |
2 | Open Asset Import Library (assimp) |
3 | ---------------------------------------------------------------------- |
4 | |
5 | Copyright (c) 2006-2017, assimp team |
6 | |
7 | All rights reserved. |
8 | |
9 | Redistribution and use of this software in source and binary forms, |
10 | with or without modification, are permitted provided that the |
11 | following conditions are met: |
12 | |
13 | * Redistributions of source code must retain the above |
14 | copyright notice, this list of conditions and the |
15 | following disclaimer. |
16 | |
17 | * Redistributions in binary form must reproduce the above |
18 | copyright notice, this list of conditions and the |
19 | following disclaimer in the documentation and/or other |
20 | materials provided with the distribution. |
21 | |
22 | * Neither the name of the assimp team, nor the names of its |
23 | contributors may be used to endorse or promote products |
24 | derived from this software without specific prior |
25 | written permission of the assimp team. |
26 | |
27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | |
39 | ---------------------------------------------------------------------- |
40 | */ |
41 | |
42 | /** @file Profiler.h |
43 | * @brief Utility to measure the respective runtime of each import step |
44 | */ |
45 | #ifndef INCLUDED_PROFILER_H |
46 | #define INCLUDED_PROFILER_H |
47 | |
48 | #include <chrono> |
49 | #include <assimp/DefaultLogger.hpp> |
50 | #include "TinyFormatter.h" |
51 | |
52 | #include <map> |
53 | |
54 | namespace Assimp { |
55 | namespace Profiling { |
56 | |
57 | using namespace Formatter; |
58 | |
59 | // ------------------------------------------------------------------------------------------------ |
60 | /** Simple wrapper around boost::timer to simplify reporting. Timings are automatically |
61 | * dumped to the log file. |
62 | */ |
63 | class Profiler { |
64 | public: |
65 | Profiler() { |
66 | // empty |
67 | } |
68 | |
69 | public: |
70 | |
71 | /** Start a named timer */ |
72 | void BeginRegion(const std::string& region) { |
73 | regions[region] = std::chrono::system_clock::now(); |
74 | DefaultLogger::get()->debug((format("START `" ),region,"`" )); |
75 | } |
76 | |
77 | |
78 | /** End a specific named timer and write its end time to the log */ |
79 | void EndRegion(const std::string& region) { |
80 | RegionMap::const_iterator it = regions.find(region); |
81 | if (it == regions.end()) { |
82 | return; |
83 | } |
84 | |
85 | std::chrono::duration<double> elapsedSeconds = std::chrono::system_clock::now() - regions[region]; |
86 | DefaultLogger::get()->debug((format("END `" ),region,"`, dt= " , elapsedSeconds.count()," s" )); |
87 | } |
88 | |
89 | private: |
90 | typedef std::map<std::string,std::chrono::time_point<std::chrono::system_clock>> RegionMap; |
91 | RegionMap regions; |
92 | }; |
93 | |
94 | } |
95 | } |
96 | |
97 | #endif |
98 | |
99 | |