2016-08-08 22:54:20 +03:00
/************************************************************************
* file name : globals . h
* - - - - - - - - - - - - - - - - - :
* creation time : 2016 / 08 / 03
* author : Victor Zarubkin
* email : v . s . zarubkin @ gmail . com
* - - - - - - - - - - - - - - - - - :
* description : The file contains declaration of global constants and variables for profiler gui .
* - - - - - - - - - - - - - - - - - :
* change log : * 2016 / 08 / 03 Victor Zarubkin : initial commit .
* :
* : *
* - - - - - - - - - - - - - - - - - :
2016-09-06 21:49:32 +03:00
* license : Lightweight profiler library for c + +
2019-10-20 16:12:37 +03:00
* : Copyright ( C ) 2016 - 2019 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-03 23:00:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# ifndef EASY_PROFILER__GUI_GLOBALS_H
# define EASY_PROFILER__GUI_GLOBALS_H
# include <string>
# include <QObject>
2016-08-06 14:50:31 +03:00
# include <QColor>
2016-08-09 00:45:45 +03:00
# include <QTextCodec>
2016-09-15 23:56:20 +03:00
# include <QSize>
2017-08-10 09:12:33 +01:00
# include <QFont>
2017-12-07 22:36:53 +03:00
# include "common_functions.h"
2016-08-08 22:54:20 +03:00
# include "globals_qobjects.h"
2016-08-03 23:00:04 +03:00
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
namespace profiler_gui {
2016-09-06 22:23:55 +03:00
const QString ORGANAZATION_NAME = " EasyProfiler " ;
2019-10-22 09:58:25 +03:00
const QString DEFAULT_WINDOW_TITLE = " EasyProfiler " ;
2016-09-06 22:23:55 +03:00
const QString APPLICATION_NAME = " Easy profiler gui application " ;
2016-08-04 23:12:41 +03:00
2018-05-24 02:19:48 +03:00
const QColor RULER_COLOR = QColor : : fromRgba ( 0x40000000 | ( : : profiler : : colors : : RichBlue & 0x00ffffff ) ) ; // 0x402020c0);
const QColor RULER_COLOR2 = QColor : : fromRgba ( 0x40000000 | ( : : profiler : : colors : : Dark & 0x00ffffff ) ) ; // 0x40408040);
2017-11-23 22:01:44 +03:00
const QColor TEXT_COLOR = QColor : : fromRgb ( 0xff504040 ) ;
2018-05-24 02:19:48 +03:00
const QColor SYSTEM_BORDER_COLOR = QColor : : fromRgb ( 0xffc4c4c4 ) ;
2017-11-23 22:01:44 +03:00
EASY_CONSTEXPR QRgb SELECTED_THREAD_BACKGROUND = 0xffe0e060 ;
EASY_CONSTEXPR QRgb SELECTED_THREAD_FOREGROUND = 0xffffffff - ( SELECTED_THREAD_BACKGROUND & 0x00ffffff ) ;
2016-08-06 14:50:31 +03:00
2017-11-23 22:01:44 +03:00
EASY_CONSTEXPR qreal SCALING_COEFFICIENT = 1.25 ;
EASY_CONSTEXPR qreal SCALING_COEFFICIENT_INV = 1.0 / SCALING_COEFFICIENT ;
2016-08-21 22:44:03 +03:00
2017-11-23 22:01:44 +03:00
EASY_CONSTEXPR uint32_t V130 = 0x01030000 ;
2017-06-06 20:46:06 +03:00
2016-09-15 22:30:32 +03:00
# ifdef _WIN32
2017-11-23 22:01:44 +03:00
EASY_CONSTEXPR qreal FONT_METRICS_FACTOR = 1.05 ;
2016-09-15 22:30:32 +03:00
# else
2017-11-23 22:01:44 +03:00
EASY_CONSTEXPR qreal FONT_METRICS_FACTOR = 1. ;
2016-09-15 22:30:32 +03:00
# endif
2016-08-04 22:38:45 +03:00
//////////////////////////////////////////////////////////////////////////
2016-08-09 00:45:45 +03:00
template < class T >
2016-08-09 01:29:24 +03:00
inline auto toUnicode ( const T & _inputString ) - > decltype ( QTextCodec : : codecForLocale ( ) - > toUnicode ( _inputString ) )
2016-08-09 00:45:45 +03:00
{
return QTextCodec : : codecForLocale ( ) - > toUnicode ( _inputString ) ;
}
2016-08-04 22:38:45 +03:00
//////////////////////////////////////////////////////////////////////////
2017-06-05 21:26:10 +03:00
inline QString decoratedThreadName ( bool _use_decorated_thread_name , const : : profiler : : BlocksTreeRoot & _root , const QString & _unicodeThreadWord , bool _hex = false )
2016-12-14 21:47:33 +03:00
{
if ( _root . got_name ( ) )
{
QString rootname ( toUnicode ( _root . name ( ) ) ) ;
if ( ! _use_decorated_thread_name | | rootname . contains ( _unicodeThreadWord , Qt : : CaseInsensitive ) )
2017-06-05 21:26:10 +03:00
{
if ( _hex )
return QString ( " %1 0x%2 " ) . arg ( rootname ) . arg ( _root . thread_id , 0 , 16 ) ;
2016-12-14 21:47:33 +03:00
return QString ( " %1 %2 " ) . arg ( rootname ) . arg ( _root . thread_id ) ;
2017-06-05 21:26:10 +03:00
}
if ( _hex )
return QString ( " %1 Thread 0x%2 " ) . arg ( rootname ) . arg ( _root . thread_id , 0 , 16 ) ;
2016-12-14 21:47:33 +03:00
return QString ( " %1 Thread %2 " ) . arg ( rootname ) . arg ( _root . thread_id ) ;
}
2017-06-05 21:26:10 +03:00
if ( _hex )
return QString ( " Thread 0x%1 " ) . arg ( _root . thread_id , 0 , 16 ) ;
2016-12-14 21:47:33 +03:00
return QString ( " Thread %1 " ) . arg ( _root . thread_id ) ;
}
2017-06-05 21:26:10 +03:00
inline QString decoratedThreadName ( bool _use_decorated_thread_name , const : : profiler : : BlocksTreeRoot & _root , bool _hex = false )
2016-12-14 21:47:33 +03:00
{
if ( _root . got_name ( ) )
{
QString rootname ( toUnicode ( _root . name ( ) ) ) ;
if ( ! _use_decorated_thread_name | | rootname . contains ( toUnicode ( " thread " ) , Qt : : CaseInsensitive ) )
2017-06-05 21:26:10 +03:00
{
if ( _hex )
return QString ( " %1 0x%2 " ) . arg ( rootname ) . arg ( _root . thread_id , 0 , 16 ) ;
2016-12-14 21:47:33 +03:00
return QString ( " %1 %2 " ) . arg ( rootname ) . arg ( _root . thread_id ) ;
2017-06-05 21:26:10 +03:00
}
if ( _hex )
return QString ( " %1 Thread 0x%2 " ) . arg ( rootname ) . arg ( _root . thread_id , 0 , 16 ) ;
2016-12-14 21:47:33 +03:00
return QString ( " %1 Thread %2 " ) . arg ( rootname ) . arg ( _root . thread_id ) ;
}
2017-06-05 21:26:10 +03:00
if ( _hex )
return QString ( " Thread 0x%1 " ) . arg ( _root . thread_id , 0 , 16 ) ;
2016-12-14 21:47:33 +03:00
return QString ( " Thread %1 " ) . arg ( _root . thread_id ) ;
}
//////////////////////////////////////////////////////////////////////////
2018-05-24 02:19:48 +03:00
enum RulerTextPosition : int8_t
2016-08-24 01:00:24 +03:00
{
2018-05-24 02:19:48 +03:00
RulerTextPosition_Center = 0 ,
RulerTextPosition_Top ,
RulerTextPosition_Bottom ,
2016-08-24 01:00:24 +03:00
2018-05-24 02:19:48 +03:00
} ; // END of enum RulerTextPosition.
2016-08-24 01:00:24 +03:00
//////////////////////////////////////////////////////////////////////////
2018-02-01 23:17:01 +03:00
class Globals Q_DECL_FINAL
2016-08-03 23:00:04 +03:00
{
2018-02-01 23:17:01 +03:00
struct SceneData
{
qreal left = 0 ;
qreal right = 100 ;
qreal window = 100 ;
qreal offset = 0 ;
bool empty = true ;
} ;
struct Fonts
{
2018-03-26 21:38:41 +03:00
QFont default_font ; ///< Default font
2018-02-01 23:17:01 +03:00
QFont background ; ///< Font for blocks_graphics_view
QFont ruler ; ///< Font for diagram rulers
QFont item ; ///< Font for graphics items
QFont selected_item ; ///< Font for selected graphics item
Fonts ( ) ;
} ;
2016-08-03 23:00:04 +03:00
2018-02-01 23:17:01 +03:00
struct SizeGuide
{
qreal pixelRatio = 1 ;
int font_height = 17 ;
2018-03-26 21:38:41 +03:00
int font_line_spacing = 20 ;
2018-02-01 23:17:01 +03:00
int graphics_row_height = 20 ;
int graphics_row_spacing = 0 ;
int graphics_row_full = 20 ;
int threads_row_spacing = 10 ;
int timeline_height = 26 ;
int icon_size = 28 ;
} ;
public :
GlobalSignals events ; ///< Global signals
2016-08-09 00:14:58 +03:00
: : profiler : : thread_blocks_tree_t profiler_blocks ; ///< Profiler blocks tree loaded from file
2016-08-28 18:19:12 +03:00
: : profiler : : descriptors_list_t descriptors ; ///< Profiler block descriptors list
2018-06-09 02:18:39 +03:00
: : profiler : : bookmarks_t bookmarks ; ///< User bookmarks
2016-08-18 23:26:41 +03:00
EasyBlocks gui_blocks ; ///< Profiler graphics blocks builded by GUI
2017-11-26 15:37:39 +03:00
QString theme ; ///< Current UI theme name
2018-02-20 22:11:43 +03:00
QString lastFileDir ;
2018-02-01 23:17:01 +03:00
Fonts font ; ///< Fonts
2017-11-26 15:37:39 +03:00
2018-02-01 23:17:01 +03:00
SceneData scene ; ///< Diagram scene sizes and visible area position
SizeGuide size ; ///< Various widgets and font sizes adapted to current device pixel ratio
2018-04-22 03:34:26 +03:00
: : profiler : : processid_t pid ; ///< Profiled process ID
2018-02-01 23:17:01 +03:00
: : profiler : : timestamp_t begin_time ; ///< Timestamp of the most left diagram scene point (x=0)
2016-08-09 00:14:58 +03:00
: : profiler : : thread_id_t selected_thread ; ///< Current selected thread id
2016-09-17 11:10:45 +03:00
: : profiler : : block_index_t selected_block ; ///< Current selected profiler block index
2016-11-30 21:59:40 +03:00
: : profiler : : block_id_t selected_block_id ; ///< Current selected profiler block id
2017-06-06 20:46:06 +03:00
uint32_t version ; ///< Opened file version (files may have different format)
2018-06-09 02:18:39 +03:00
2019-10-24 19:21:31 +03:00
uint32_t max_rows_count ; ///< Maximum blocks count for the Hierarchy widget for the full call-stack mode
2017-03-07 00:29:34 +03:00
float frame_time ; ///< Expected frame time value in microseconds to be displayed at minimap on graphics scrollbar
2016-11-19 04:52:45 +03:00
int blocks_spacing ; ///< Minimum blocks spacing on diagram
int blocks_size_min ; ///< Minimum blocks size on diagram
int blocks_narrow_size ; ///< Width indicating narrow blocks
2017-04-03 23:16:36 +03:00
int max_fps_history ; ///< Max frames history displayed in FPS Monitor
int fps_timer_interval ; ///< Interval in milliseconds for sending network requests to the profiled application (used by FPS Monitor)
2017-04-05 22:37:40 +03:00
int fps_widget_line_width ; ///< Line width in pixels of FPS lines for FPS Monitor
2018-06-09 02:18:39 +03:00
: : profiler : : color_t bookmark_default_color ; ///<
RulerTextPosition chrono_text_position ; ///< Selected interval text position
2016-11-30 21:59:40 +03:00
TimeUnits time_units ; ///< Units type for time (milliseconds, microseconds, nanoseconds or auto-definition)
2018-06-09 02:18:39 +03:00
2016-09-25 11:49:49 +03:00
bool connected ; ///< Is connected to source (to be able to capture profiling information)
2018-06-09 02:18:39 +03:00
bool has_local_changes ; ///<
bool use_custom_window_header ; ///<
bool is_right_window_header_controls ; ///<
2017-04-03 23:16:36 +03:00
bool fps_enabled ; ///< Is FPS Monitor enabled
2016-12-14 21:47:33 +03:00
bool use_decorated_thread_name ; ///< Add "Thread" to the name of each thread (if there is no one)
2017-06-05 21:26:10 +03:00
bool hex_thread_id ; ///< Use hex view for thread-id instead of decimal
2017-03-13 20:30:57 +03:00
bool enable_event_markers ; ///< Enable event indicators painting (These are narrow rectangles at the bottom of each thread)
2016-09-14 23:13:38 +03:00
bool enable_statistics ; ///< Enable gathering and using statistics (Disable if you want to consume less memory)
2016-11-23 22:54:59 +03:00
bool enable_zero_length ; ///< Enable zero length blocks (if true, then such blocks will have width == 1 pixel on each scale)
2016-11-26 18:08:02 +03:00
bool add_zero_blocks_to_hierarchy ; ///< Enable adding zero blocks into hierarchy tree
2016-08-09 00:14:58 +03:00
bool draw_graphics_items_borders ; ///< Draw borders for graphics blocks or not
2016-12-12 21:39:16 +03:00
bool hide_narrow_children ; ///< Hide children for narrow graphics blocks (See blocks_narrow_size)
bool hide_minsize_blocks ; ///< Hide blocks which screen size is less than blocks_size_min
2016-08-09 00:14:58 +03:00
bool display_only_relevant_stats ; ///< Display only relevant information in ProfTreeWidget (excludes min, max, average times if there are only 1 calls number)
2016-08-23 22:44:04 +03:00
bool collapse_items_on_tree_close ; ///< Collapse all items which were displayed in the hierarchy tree after tree close/reset
2016-08-23 23:50:30 +03:00
bool all_items_expanded_by_default ; ///< Expand all items after file is opened
2016-11-20 21:01:33 +03:00
bool only_current_thread_hierarchy ; ///< Build hierarchy tree for current thread only
2016-11-30 21:59:40 +03:00
bool highlight_blocks_with_same_id ; ///< Highlight all blocks with same id on diagram
2016-12-04 16:51:27 +03:00
bool selecting_block_changes_thread ; ///< If true then current selected thread will change every time you select block
2017-03-13 20:30:57 +03:00
bool auto_adjust_histogram_height ; ///< Automatically adjust histogram height to the visible region
2018-01-21 19:37:44 +03:00
bool auto_adjust_chart_height ; ///< Automatically adjust arbitrary value chart height to the visible region
2017-06-07 02:08:53 +03:00
bool display_only_frames_on_histogram ; ///< Display only top-level blocks on histogram when drawing histogram by block id
2016-08-23 23:50:30 +03:00
bool bind_scene_and_tree_expand_status ; /** \brief If true then items on graphics scene and in the tree (blocks hierarchy) are binded on each other
so expanding / collapsing items on scene also expands / collapse items in the tree . */
2017-11-26 15:37:39 +03:00
2018-02-01 23:17:01 +03:00
static Globals & instance ( ) ;
2016-08-03 23:00:04 +03:00
private :
2018-01-28 20:52:17 +03:00
Globals ( ) ;
2016-08-24 01:00:24 +03:00
2018-01-28 20:52:17 +03:00
} ; // END of struct Globals.
2016-08-24 01:00:24 +03:00
2016-08-04 22:38:45 +03:00
//////////////////////////////////////////////////////////////////////////
2016-08-03 23:00:04 +03:00
} // END of namespace profiler_gui.
2018-02-01 23:17:01 +03:00
# define EASY_GLOBALS profiler_gui::Globals::instance()
2016-08-30 22:51:18 +03:00
2018-02-01 23:17:01 +03:00
inline profiler_gui : : EasyBlock & easyBlock ( profiler : : block_index_t i ) {
2016-08-30 22:51:18 +03:00
return EASY_GLOBALS . gui_blocks [ i ] ;
}
2018-02-01 23:17:01 +03:00
inline profiler : : SerializedBlockDescriptor & easyDescriptor ( profiler : : block_id_t i ) {
2016-08-30 22:51:18 +03:00
return * EASY_GLOBALS . descriptors [ i ] ;
}
2019-10-20 16:12:37 +03:00
inline profiler : : SerializedBlockDescriptor & easyDescriptor ( const profiler : : BlocksTree & block ) {
return easyDescriptor ( block . node - > id ( ) ) ;
2018-04-22 03:34:26 +03:00
}
2018-02-01 23:17:01 +03:00
EASY_FORCE_INLINE const profiler : : BlocksTree & easyBlocksTree ( profiler : : block_index_t i ) {
2016-08-30 22:51:18 +03:00
return easyBlock ( i ) . tree ;
}
2017-11-26 15:37:39 +03:00
2019-10-20 16:12:37 +03:00
EASY_FORCE_INLINE const char * easyBlockName ( const profiler : : BlocksTree & block ) {
const char * name = block . node - > name ( ) ;
return * name ! = 0 ? name : easyDescriptor ( block . node - > id ( ) ) . name ( ) ;
2017-12-07 22:36:53 +03:00
}
2019-10-20 16:12:37 +03:00
EASY_FORCE_INLINE const char * easyBlockName ( const profiler : : BlocksTree & block , const profiler : : SerializedBlockDescriptor & desc ) {
const char * name = block . node - > name ( ) ;
return * name ! = 0 ? name : desc . name ( ) ;
2017-12-07 22:36:53 +03:00
}
2018-02-01 23:17:01 +03:00
EASY_FORCE_INLINE const char * easyBlockName ( profiler : : block_index_t i ) {
2017-12-07 22:36:53 +03:00
return easyBlockName ( easyBlock ( i ) . tree ) ;
}
2019-10-20 16:12:37 +03:00
inline qreal sceneX ( profiler : : timestamp_t time ) {
return PROF_MICROSECONDS ( qreal ( time - EASY_GLOBALS . begin_time ) ) ;
2017-11-30 22:21:08 +03:00
}
2019-10-20 16:12:37 +03:00
inline QString imagePath ( const QString & resource_name ) {
return QString ( " :/images/%1/%2 " ) . arg ( EASY_GLOBALS . theme ) . arg ( resource_name ) ;
2017-11-26 15:37:39 +03:00
}
2019-10-20 16:12:37 +03:00
inline QString imagePath ( const char * resource_name ) {
return QString ( " :/images/%1/%2 " ) . arg ( EASY_GLOBALS . theme ) . arg ( resource_name ) ;
2017-11-26 15:37:39 +03:00
}
2018-02-01 23:17:01 +03:00
inline QSize applicationIconsSize ( ) {
return QSize ( EASY_GLOBALS . size . icon_size , EASY_GLOBALS . size . icon_size ) ;
}
2018-06-09 02:18:39 +03:00
inline qreal pxf ( int pixels ) {
return pixels * EASY_GLOBALS . size . pixelRatio ;
}
2018-02-01 23:17:01 +03:00
inline int px ( int pixels ) {
2018-06-09 02:18:39 +03:00
return static_cast < int > ( pxf ( pixels ) + 0.5 ) ;
2018-02-01 23:17:01 +03:00
}
2016-08-30 22:51:18 +03:00
2016-08-03 23:00:04 +03:00
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
# endif // EASY_PROFILER__GUI_GLOBALS_H