diff --git a/easy_profiler_converter/reader.cpp b/easy_profiler_converter/reader.cpp index 19ca65c..f01ffdb 100644 --- a/easy_profiler_converter/reader.cpp +++ b/easy_profiler_converter/reader.cpp @@ -57,20 +57,20 @@ inline bool isCompatibleVersion(uint32_t _version) #ifdef EASY_PROFILER_HASHED_CSTR_DEFINED -typedef ::std::unordered_map<::profiler::block_id_t, ::profiler::BlockStatistics*, ::profiler::passthrough_hash<::profiler::block_id_t> > StatsMap; +using StatsMap = ::std::unordered_map<::profiler::block_id_t, ::profiler::BlockStatistics*, ::estd::hash<::profiler::block_id_t> >; /** \note It is absolutely safe to use hashed_cstr (which simply stores pointer) because std::unordered_map, which uses it as a key, exists only inside fillTreesFromFile function. */ -typedef ::std::unordered_map<::profiler::hashed_cstr, ::profiler::block_id_t> IdMap; +using IdMap = ::std::unordered_map<::profiler::hashed_cstr, ::profiler::block_id_t>; -typedef ::std::unordered_map<::profiler::hashed_cstr, ::profiler::BlockStatistics*> CsStatsMap; +using CsStatsMap = ::std::unordered_map<::profiler::hashed_cstr, ::profiler::BlockStatistics*>; #else // TODO: Create optimized version of profiler::hashed_cstr for Linux too. -typedef ::std::unordered_map<::profiler::block_id_t, ::profiler::BlockStatistics*, ::profiler::passthrough_hash<::profiler::block_id_t> > StatsMap; -typedef ::std::unordered_map<::profiler::hashed_stdstring, ::profiler::block_id_t> IdMap; -typedef ::std::unordered_map<::profiler::hashed_stdstring, ::profiler::BlockStatistics*> CsStatsMap; +using StatsMap = ::std::unordered_map<::profiler::block_id_t, ::profiler::BlockStatistics*, ::estd::hash<::profiler::block_id_t> >; +using IdMap = ::std::unordered_map<::profiler::hashed_stdstring, ::profiler::block_id_t>; +using CsStatsMap = ::std::unordered_map<::profiler::hashed_stdstring, ::profiler::BlockStatistics*>; #endif @@ -125,8 +125,8 @@ using namespace profiler::reader; int64_t file_cpu_frequency = 0LL; inFile.read((char*)&file_cpu_frequency, sizeof(int64_t)); - uint64_t cpu_frequency = file_cpu_frequency; - const double conversion_factor = static_cast(TIME_FACTOR) / static_cast(cpu_frequency); + const uint64_t cpu_frequency = file_cpu_frequency; + const double conversion_factor = (cpu_frequency != 0 ? static_cast(TIME_FACTOR) / static_cast(cpu_frequency) : 1.); ::profiler::timestamp_t begin_time = 0ULL; ::profiler::timestamp_t end_time = 0ULL; @@ -189,14 +189,15 @@ using namespace profiler::reader; inFile.read(data, sz); auto descriptor = reinterpret_cast<::profiler::SerializedBlockDescriptor*>(data); - m_BlockDescriptors.push_back(::std::make_shared()); - m_BlockDescriptors.back()->lineNumber = descriptor->line(); - m_BlockDescriptors.back()->blockId = descriptor->id(); - m_BlockDescriptors.back()->argbColor = descriptor->color(); - m_BlockDescriptors.back()->blockType = descriptor->type(); - m_BlockDescriptors.back()->status = descriptor->status(); - m_BlockDescriptors.back()->compileTimeName = descriptor->name(); - m_BlockDescriptors.back()->fileName = descriptor->file(); + auto desc = ::std::make_shared(); + desc->lineNumber = descriptor->line(); + desc->blockId = descriptor->id(); + desc->argbColor = descriptor->color(); + desc->blockType = static_castblockType)>(descriptor->type()); + desc->status = descriptor->status(); + desc->compileTimeName = descriptor->name(); + desc->fileName = descriptor->file(); + m_BlockDescriptors.push_back(::std::move(desc)); i += sz; } @@ -281,7 +282,7 @@ using namespace profiler::reader; prev_node->current_block = ::std::make_shared(); ::std::shared_ptr element; - uint level = 0; + uint32_t level = 0; while (!inFile.eof() && read_number < threshold) { diff --git a/easy_profiler_converter/reader.h b/easy_profiler_converter/reader.h index a25fb0a..fe7706b 100644 --- a/easy_profiler_converter/reader.h +++ b/easy_profiler_converter/reader.h @@ -1,3 +1,45 @@ +/** +Lightweight profiler library for c++ +Copyright(C) 2016-2018 Sergey Yagovtsev, Victor Zarubkin + +Licensed under either of + * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT) + * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0) +at your option. + +The MIT License + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished + to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. + + +The Apache License, Version 2.0 (the "License"); + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +**/ + #ifndef EASY_PROFILER_READER_H #define EASY_PROFILER_READER_H @@ -12,49 +54,39 @@ ///this #include #include +#include -#ifndef uint -#define uint unsigned int -#endif - -namespace profiler{ +namespace profiler { namespace reader { +class BlocksTreeNode; +using thread_blocks_tree_t = ::std::unordered_map<::profiler::thread_id_t, BlocksTreeNode, ::estd::hash<::profiler::thread_id_t> >; +using thread_names_t = ::std::unordered_map<::profiler::thread_id_t, ::std::string>; +using context_switches_t = ::std::vector<::std::shared_ptr >; + class BlocksTreeNode { public: + ::std::vector<::std::shared_ptr> children; ::std::shared_ptr current_block; BlocksTreeNode* parent; - ::std::vector<::std::shared_ptr> children; - BlocksTreeNode(BlocksTreeNode&& other) - : current_block(::std::move(other.current_block)), - parent(other.parent), - children(::std::move(other.children)) + BlocksTreeNode(BlocksTreeNode&& other) : children(::std::move(other.children)) + , current_block(::std::move(other.current_block)) + , parent(other.parent) { } - BlocksTreeNode():current_block(nullptr), - parent(nullptr) + + BlocksTreeNode() : parent(nullptr) { } -}; - -typedef ::std::unordered_map<::profiler::thread_id_t, BlocksTreeNode, ::profiler::passthrough_hash<::profiler::thread_id_t> > thread_blocks_tree_t; -typedef ::std::unordered_map<::profiler::thread_id_t, ::std::string> thread_names_t; -typedef ::std::vector<::std::shared_ptr > context_switches_t; +}; // end of class BlocksTreeNode. class FileReader EASY_FINAL { public: - - FileReader() - { } - - ~FileReader() - { } - /*-----------------------------------------------------------------*/ ///initial read file with RAW data ::profiler::block_index_t readFile(const ::std::string& filename); @@ -78,6 +110,7 @@ public: /*-----------------------------------------------------------------*/ private: + ///serialized raw data ::profiler::SerializedData serialized_blocks, serialized_descriptors; ///error log stream @@ -91,8 +124,11 @@ private: std::vector> m_BlockDescriptors; ///data file version uint32_t m_version; -}; -} //namespace reader -} //namespace profiler -#endif //EASY_PROFILER_READER_H +}; // end of class FileReader. + +} // end of namespace reader. + +} // end of namespace profiler. + +#endif // EASY_PROFILER_READER_H