2016-08-18 23:26:41 +03:00
|
|
|
/************************************************************************
|
|
|
|
* file name : tree_widget_loader.h
|
|
|
|
* ----------------- :
|
|
|
|
* creation time : 2016/08/18
|
|
|
|
* author : Victor Zarubkin
|
|
|
|
* email : v.s.zarubkin@gmail.com
|
|
|
|
* ----------------- :
|
2018-01-28 20:52:17 +03:00
|
|
|
* description : The file contains declaration of TreeWidgetLoader which aim is
|
2016-08-18 23:26:41 +03:00
|
|
|
* : to load EasyProfiler blocks hierarchy in separate thread.
|
|
|
|
* ----------------- :
|
|
|
|
* change log : * 2016/08/18 Victor Zarubkin: moved sources from blocks_tree_widget.h/.cpp
|
|
|
|
* : and renamed Prof* to Easy*.
|
|
|
|
* :
|
|
|
|
* : *
|
|
|
|
* ----------------- :
|
2016-09-06 21:49:32 +03:00
|
|
|
* license : Lightweight profiler library for c++
|
2018-01-29 23:29:43 +03:00
|
|
|
* : Copyright(C) 2016-2018 Sergey Yagovtsev, Victor Zarubkin
|
2017-03-30 06:14:23 +03:00
|
|
|
* :
|
|
|
|
* : 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.
|
2016-11-13 16:39:59 +03:00
|
|
|
* : 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.
|
2016-08-18 23:26:41 +03:00
|
|
|
************************************************************************/
|
|
|
|
|
2017-03-05 22:59:03 +03:00
|
|
|
#ifndef EASY_TREE_WIDGET_LOADER_H
|
|
|
|
#define EASY_TREE_WIDGET_LOADER_H
|
2016-08-18 23:26:41 +03:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <atomic>
|
2017-03-05 23:50:38 +03:00
|
|
|
#include <easy/reader.h>
|
2016-08-18 23:26:41 +03:00
|
|
|
#include "common_types.h"
|
2018-01-28 20:52:17 +03:00
|
|
|
#include "thread_pool_task.h"
|
2016-08-18 23:26:41 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-01-28 20:52:17 +03:00
|
|
|
class TreeWidgetItem;
|
2016-12-12 21:39:16 +03:00
|
|
|
|
|
|
|
#ifndef EASY_TREE_WIDGET__USE_VECTOR
|
2018-01-28 20:52:17 +03:00
|
|
|
using Items = ::std::unordered_map<profiler::block_index_t, TreeWidgetItem*, ::estd::hash<profiler::block_index_t> >;
|
2016-12-12 21:39:16 +03:00
|
|
|
#else
|
2018-01-28 20:52:17 +03:00
|
|
|
using Items = ::std::vector<TreeWidgetItem*>;
|
2016-12-12 21:39:16 +03:00
|
|
|
#endif
|
|
|
|
|
2018-01-28 20:52:17 +03:00
|
|
|
using ThreadedItems = ::std::vector<::std::pair<profiler::thread_id_t, TreeWidgetItem*> >;
|
|
|
|
using RootsMap = ::std::unordered_map<profiler::thread_id_t, TreeWidgetItem*, ::estd::hash<profiler::thread_id_t> >;
|
|
|
|
using IdItems = ::std::unordered_map<profiler::block_id_t, TreeWidgetItem*, ::estd::hash<profiler::block_index_t> >;
|
2016-12-18 15:56:08 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-01-28 20:52:17 +03:00
|
|
|
enum class TreeMode : uint8_t
|
2016-12-18 15:56:08 +03:00
|
|
|
{
|
2018-01-28 20:52:17 +03:00
|
|
|
Full,
|
|
|
|
Plain
|
2016-12-18 15:56:08 +03:00
|
|
|
};
|
2016-08-18 23:26:41 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-01-28 20:52:17 +03:00
|
|
|
class TreeWidgetLoader Q_DECL_FINAL
|
2016-08-18 23:26:41 +03:00
|
|
|
{
|
|
|
|
ThreadedItems m_topLevelItems; ///<
|
|
|
|
Items m_items; ///<
|
2016-12-18 15:56:08 +03:00
|
|
|
IdItems m_iditems; ///<
|
2018-01-28 20:52:17 +03:00
|
|
|
ThreadPoolTask m_worker; ///<
|
|
|
|
std::atomic_bool m_bDone; ///<
|
|
|
|
std::atomic_bool m_bInterrupt; ///<
|
|
|
|
std::atomic<int> m_progress; ///<
|
|
|
|
TreeMode m_mode; ///<
|
2016-08-18 23:26:41 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2018-01-28 20:52:17 +03:00
|
|
|
TreeWidgetLoader();
|
|
|
|
~TreeWidgetLoader();
|
2016-08-18 23:26:41 +03:00
|
|
|
|
|
|
|
int progress() const;
|
|
|
|
bool done() const;
|
|
|
|
|
|
|
|
void takeTopLevelItems(ThreadedItems& _output);
|
|
|
|
void takeItems(Items& _output);
|
|
|
|
|
2016-09-17 15:38:41 +03:00
|
|
|
void interrupt(bool _wait = false);
|
2018-01-28 20:52:17 +03:00
|
|
|
void fillTree(profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const profiler::thread_blocks_tree_t& _blocksTree, TreeMode _mode);
|
|
|
|
void fillTreeBlocks(const::profiler_gui::TreeBlocks& _blocks, profiler::timestamp_t _beginTime, profiler::timestamp_t _left, profiler::timestamp_t _right, bool _strict, TreeMode _mode);
|
2016-12-18 15:56:08 +03:00
|
|
|
|
|
|
|
private:
|
2016-08-18 23:26:41 +03:00
|
|
|
|
2016-12-18 15:56:08 +03:00
|
|
|
bool interrupted() const;
|
2016-08-18 23:26:41 +03:00
|
|
|
void setDone();
|
|
|
|
void setProgress(int _progress);
|
|
|
|
|
2018-01-28 20:52:17 +03:00
|
|
|
void setTreeInternal1(profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const profiler::thread_blocks_tree_t& _blocksTree, bool _addZeroBlocks, bool _decoratedThreadNames, bool _hexThreadId, ::profiler_gui::TimeUnits _units);
|
|
|
|
void setTreeInternal2(const profiler::timestamp_t& _beginTime, const ::profiler_gui::TreeBlocks& _blocks, profiler::timestamp_t _left, profiler::timestamp_t _right, bool _strict, bool _addZeroBlocks, bool _decoratedThreadNames, bool _hexThreadId, ::profiler_gui::TimeUnits _units);
|
|
|
|
size_t setTreeInternal(const profiler::BlocksTreeRoot& _threadRoot, profiler::block_index_t _firstCswitch, const profiler::timestamp_t& _beginTime, const profiler::BlocksTree::children_t& _children, TreeWidgetItem* _parent, TreeWidgetItem* _frame, profiler::timestamp_t _left, profiler::timestamp_t _right, bool _strict, profiler::timestamp_t& _duration, bool _addZeroBlocks, ::profiler_gui::TimeUnits _units);
|
|
|
|
size_t setTreeInternalPlain(const profiler::BlocksTreeRoot& _threadRoot, profiler::block_index_t _firstCswitch, const profiler::timestamp_t& _beginTime, const profiler::BlocksTree::children_t& _children, TreeWidgetItem* _parent, TreeWidgetItem* _frame, profiler::timestamp_t _left, profiler::timestamp_t _right, bool _strict, profiler::timestamp_t& _duration, bool _addZeroBlocks, ::profiler_gui::TimeUnits _units);
|
2016-12-18 17:59:41 +03:00
|
|
|
|
2018-01-28 20:52:17 +03:00
|
|
|
profiler::timestamp_t calculateChildrenDurationRecursive(const profiler::BlocksTree::children_t& _children, profiler::block_id_t _id);
|
2016-08-18 23:26:41 +03:00
|
|
|
|
2018-01-28 20:52:17 +03:00
|
|
|
}; // END of class TreeWidgetLoader.
|
2016-08-18 23:26:41 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-03-05 22:59:03 +03:00
|
|
|
#endif // EASY_TREE_WIDGET_LOADER_H
|