Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-29 07:58:16

0001 /*
0002 Open Asset Import Library (assimp)
0003 ----------------------------------------------------------------------
0004 
0005 Copyright (c) 2006-2025, assimp team
0006 
0007 All rights reserved.
0008 
0009 Redistribution and use of this software in source and binary forms,
0010 with or without modification, are permitted provided that the
0011 following conditions are met:
0012 
0013 * Redistributions of source code must retain the above
0014   copyright notice, this list of conditions and the
0015   following disclaimer.
0016 
0017 * Redistributions in binary form must reproduce the above
0018   copyright notice, this list of conditions and the
0019   following disclaimer in the documentation and/or other
0020   materials provided with the distribution.
0021 
0022 * Neither the name of the assimp team, nor the names of its
0023   contributors may be used to endorse or promote products
0024   derived from this software without specific prior
0025   written permission of the assimp team.
0026 
0027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0028 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0029 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0030 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0031 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0032 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0033 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0034 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0035 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0036 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0038 
0039 ----------------------------------------------------------------------
0040 */
0041 
0042 /** @file Profiler.h
0043  *  @brief Utility to measure the respective runtime of each import step
0044  */
0045 #pragma once
0046 #ifndef AI_INCLUDED_PROFILER_H
0047 #define AI_INCLUDED_PROFILER_H
0048 
0049 #ifdef __GNUC__
0050 #   pragma GCC system_header
0051 #endif
0052 
0053 #include <chrono>
0054 #include <assimp/DefaultLogger.hpp>
0055 #include <assimp/TinyFormatter.h>
0056 
0057 #include <map>
0058 
0059 namespace Assimp {
0060 namespace Profiling {
0061 
0062 using namespace Formatter;
0063 
0064 // ------------------------------------------------------------------------------------------------
0065 /** Simple wrapper around boost::timer to simplify reporting. Timings are automatically
0066  *  dumped to the log file.
0067  */
0068 class Profiler {
0069 public:
0070     Profiler() = default;
0071 
0072 
0073     /** Start a named timer */
0074     void BeginRegion(const std::string& region) {
0075         regions[region] = std::chrono::system_clock::now();
0076         ASSIMP_LOG_DEBUG("START `",region,"`");
0077     }
0078 
0079 
0080     /** End a specific named timer and write its end time to the log */
0081     void EndRegion(const std::string& region) {
0082         RegionMap::const_iterator it = regions.find(region);
0083         if (it == regions.end()) {
0084             return;
0085         }
0086 
0087         std::chrono::duration<double> elapsedSeconds = std::chrono::system_clock::now() - regions[region];
0088         ASSIMP_LOG_DEBUG("END   `",region,"`, dt= ", elapsedSeconds.count()," s");
0089     }
0090 
0091 private:
0092     typedef std::map<std::string,std::chrono::time_point<std::chrono::system_clock>> RegionMap;
0093     RegionMap regions;
0094 };
0095 
0096 }
0097 }
0098 
0099 #endif // AI_INCLUDED_PROFILER_H
0100