Skip to content

Commit

Permalink
#106 [Core][UI] Added possibility to add user bookmarks with double-c…
Browse files Browse the repository at this point in the history
…licking on a timeline in the Diagram window.

#112 [UI] Fixed losing focus (and getting under MainWindow) for Blocks widget.
#0 [UI] UI styling, added custom window header and dialogs (could be turned off/on and adjusted position at [Settings -> Appearance] menu).
  • Loading branch information
cas4ey committed Jun 8, 2018
1 parent 91d10c2 commit 0ae4304
Show file tree
Hide file tree
Showing 39 changed files with 2,983 additions and 501 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
option(EASY_PROFILER_NO_GUI "Build easy_profiler without the GUI application (required Qt)" OFF)

set(EASY_PROGRAM_VERSION_MAJOR 2)
set(EASY_PROGRAM_VERSION_MINOR 0)
set(EASY_PROGRAM_VERSION_PATCH 1)
set(EASY_PROGRAM_VERSION_MINOR 1)
set(EASY_PROGRAM_VERSION_PATCH 0)
set(EASY_PRODUCT_VERSION_STRING "${EASY_PROGRAM_VERSION_MAJOR}.${EASY_PROGRAM_VERSION_MINOR}.${EASY_PROGRAM_VERSION_PATCH}")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
Expand Down
78 changes: 52 additions & 26 deletions easy_profiler_converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,44 +80,70 @@ void JsonExporter::convert(const ::std::string& inputFile, const ::std::string&

nlohmann::json json = {{"version", fr.getVersionString()}, {"timeUnits", "ns"}};

auto descriptors = nlohmann::json::array();
const auto& block_descriptors = fr.getBlockDescriptors();
for (const auto& descriptor : block_descriptors)
// convert descriptors
{
descriptors.emplace_back();
auto descriptors = nlohmann::json::array();
const auto& block_descriptors = fr.getBlockDescriptors();
for (const auto& descriptor : block_descriptors)
{
descriptors.emplace_back();

std::stringstream stream;
stream << "0x" << std::hex << descriptor.argbColor;
std::stringstream stream;
stream << "0x" << std::hex << descriptor.argbColor;

auto& desc = descriptors.back();
auto& desc = descriptors.back();

desc["id"] = descriptor.id;
if (descriptor.parentId != descriptor.id)
desc["parentId"] = descriptor.parentId;
desc["id"] = descriptor.id;
if (descriptor.parentId != descriptor.id)
desc["parentId"] = descriptor.parentId;

desc["name"] = descriptor.blockName;
desc["type"] = descriptor.blockType;
desc["color"] = stream.str();
desc["sourceFile"] = descriptor.fileName;
desc["sourceLine"] = descriptor.lineNumber;
}
desc["name"] = descriptor.blockName;
desc["type"] = descriptor.blockType;
desc["color"] = stream.str();
desc["sourceFile"] = descriptor.fileName;
desc["sourceLine"] = descriptor.lineNumber;
}

json["blockDescriptors"] = descriptors;
json["blockDescriptors"] = descriptors;
}

auto threads = nlohmann::json::array();
const auto& blocks_tree = fr.getBlocksTree();
for (const auto& kv : blocks_tree)
// convert threads and blocks
{
threads.emplace_back();
auto threads = nlohmann::json::array();
const auto& blocks_tree = fr.getBlocksTree();
for (const auto& kv : blocks_tree)
{
threads.emplace_back();

auto& thread = threads.back();
thread["threadId"] = kv.first;
thread["threadName"] = fr.getThreadName(kv.first);

auto& thread = threads.back();
thread["threadId"] = kv.first;
thread["threadName"] = fr.getThreadName(kv.first);
convertChildren(kv.second, thread);
}

convertChildren(kv.second, thread);
json["threads"] = threads;
}

json["threads"] = threads;
// convert bookmarks
{
auto bookmarks = nlohmann::json::array();
const auto& bmarks = fr.getBookmarks();
for (const auto& mark : bmarks)
{
std::stringstream stream;
stream << "0x" << std::hex << mark.color;

bookmarks.emplace_back();

auto& bookmark = bookmarks.back();
bookmark["timestamp"] = mark.pos;
bookmark["color"] = stream.str();
bookmark["text"] = mark.text;
}

json["bookmarks"] = bookmarks;
}

try
{
Expand Down
16 changes: 13 additions & 3 deletions easy_profiler_converter/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@ namespace reader

profiler::block_index_t FileReader::readFile(const std::string& filename)
{
::profiler::SerializedData serialized_blocks, serialized_descriptors;
profiler::SerializedData serialized_blocks, serialized_descriptors;
profiler::descriptors_list_t descriptors;
profiler::blocks_t blocks;
profiler::thread_blocks_tree_t threaded_trees;
profiler::bookmarks_t bookmarks;
profiler::BeginEndTime beginEndTime;

profiler::processid_t pid = 0;
uint32_t total_descriptors_number = 0;

EASY_CONSTEXPR bool DoNotGatherStats = false;
const auto blocks_number = ::fillTreesFromFile(filename.c_str(), serialized_blocks, serialized_descriptors,
descriptors, blocks, threaded_trees, total_descriptors_number, m_version, pid, DoNotGatherStats, m_errorMessage);
const auto blocks_number = ::fillTreesFromFile(filename.c_str(), beginEndTime, serialized_blocks, serialized_descriptors,
descriptors, blocks, threaded_trees, bookmarks, total_descriptors_number, m_version, pid, DoNotGatherStats,
m_errorMessage);

if (blocks_number == 0)
return 0;
Expand Down Expand Up @@ -156,6 +159,8 @@ profiler::block_index_t FileReader::readFile(const std::string& filename)
}
}

m_bookmarks.swap(bookmarks);

return blocks_number;
}

Expand All @@ -169,6 +174,11 @@ const descriptors_list_t& FileReader::getBlockDescriptors() const
return m_blockDescriptors;
}

const profiler::bookmarks_t& FileReader::getBookmarks() const
{
return m_bookmarks;
}

const std::string& FileReader::getThreadName(uint64_t threadId) const
{
auto it = m_threadNames.find(threadId);
Expand Down
3 changes: 3 additions & 0 deletions easy_profiler_converter/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class FileReader EASY_FINAL

const descriptors_list_t& getBlockDescriptors() const;

const profiler::bookmarks_t& getBookmarks() const;

/*! get thread name by Id
\param threadId thread Id
\return Name of thread
Expand All @@ -132,6 +134,7 @@ class FileReader EASY_FINAL
thread_names_t m_threadNames; ///< [thread_id, thread_name]
context_switches_t m_contextSwitches; ///< context switches info
descriptors_list_t m_blockDescriptors; ///< block descriptors
profiler::bookmarks_t m_bookmarks; ///< User bookmarks
uint32_t m_version; ///< .prof file version

}; // end of class FileReader.
Expand Down
57 changes: 42 additions & 15 deletions easy_profiler_core/include/easy/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ namespace profiler {
children_t children; ///< List of children blocks. May be empty.

union {
profiler::SerializedBlock* node; ///< Pointer to serialized data for regular block (id, name, begin, end etc.)
profiler::SerializedCSwitch* cs; ///< Pointer to serialized data for context switch (thread_id, name, begin, end etc.)
profiler::ArbitraryValue* value; ///< Pointer to serialized data for arbitrary value
profiler::SerializedBlock* node; ///< Pointer to serialized data for regular block (id, name, begin, end etc.)
profiler::SerializedCSwitch* cs; ///< Pointer to serialized data for context switch (thread_id, name, begin, end etc.)
profiler::ArbitraryValue* value; ///< Pointer to serialized data for arbitrary value
};

profiler::BlockStatistics* per_parent_stats; ///< Pointer to statistics for this block within the parent (may be nullptr for top-level blocks)
profiler::BlockStatistics* per_frame_stats; ///< Pointer to statistics for this block within the frame (may be nullptr for top-level blocks)
profiler::BlockStatistics* per_thread_stats; ///< Pointer to statistics for this block within the bounds of all frames per current thread
uint8_t depth; ///< Maximum number of sublevels (maximum children depth)
uint8_t depth; ///< Maximum number of sublevels (maximum children depth)

BlocksTree(const This&) = delete;
This& operator = (const This&) = delete;
Expand Down Expand Up @@ -204,22 +204,36 @@ namespace profiler {

//////////////////////////////////////////////////////////////////////////

struct Bookmark EASY_FINAL
{
EASY_STATIC_CONSTEXPR size_t BaseSize = sizeof(profiler::timestamp_t) +
sizeof(profiler::color_t) + 1;

std::string text;
profiler::timestamp_t pos;
profiler::color_t color;
};

using bookmarks_t = std::vector<Bookmark>;

//////////////////////////////////////////////////////////////////////////

class BlocksTreeRoot EASY_FINAL
{
using This = BlocksTreeRoot;

public:

BlocksTree::children_t children; ///< List of children indexes
BlocksTree::children_t sync; ///< List of context-switch events
BlocksTree::children_t events; ///< List of events indexes
std::string thread_name; ///< Name of this thread
BlocksTree::children_t children; ///< List of children indexes
BlocksTree::children_t sync; ///< List of context-switch events
BlocksTree::children_t events; ///< List of events indexes
std::string thread_name; ///< Name of this thread
profiler::timestamp_t profiled_time; ///< Profiled time of this thread (sum of all children duration)
profiler::timestamp_t wait_time; ///< Wait time of this thread (sum of all context switches)
profiler::thread_id_t thread_id; ///< System Id of this thread
profiler::block_index_t frames_number; ///< Total frames number (top-level blocks)
profiler::block_index_t blocks_number; ///< Total blocks number including their children
uint8_t depth; ///< Maximum stack depth (number of levels)
uint8_t depth; ///< Maximum stack depth (number of levels)

BlocksTreeRoot(const This&) = delete;
This& operator = (const This&) = delete;
Expand Down Expand Up @@ -275,6 +289,12 @@ namespace profiler {

}; // END of class BlocksTreeRoot.

struct BeginEndTime
{
profiler::timestamp_t beginTime;
profiler::timestamp_t endTime;
};

using blocks_t = profiler::BlocksTree::blocks_t;
using thread_blocks_tree_t = std::unordered_map<profiler::thread_id_t, profiler::BlocksTreeRoot, ::estd::hash<profiler::thread_id_t> >;
using block_getter_fn = std::function<const profiler::BlocksTree&(profiler::block_index_t)>;
Expand Down Expand Up @@ -334,24 +354,28 @@ namespace profiler {
extern "C" {

PROFILER_API profiler::block_index_t fillTreesFromFile(std::atomic<int>& progress, const char* filename,
profiler::BeginEndTime& begin_end_time,
profiler::SerializedData& serialized_blocks,
profiler::SerializedData& serialized_descriptors,
profiler::descriptors_list_t& descriptors,
profiler::blocks_t& _blocks,
profiler::thread_blocks_tree_t& threaded_trees,
uint32_t& total_descriptors_number,
profiler::bookmarks_t& bookmarks,
uint32_t& descriptors_count,
uint32_t& version,
profiler::processid_t& pid,
bool gather_statistics,
std::ostream& _log);

PROFILER_API profiler::block_index_t fillTreesFromStream(std::atomic<int>& progress, std::istream& str,
profiler::BeginEndTime& begin_end_time,
profiler::SerializedData& serialized_blocks,
profiler::SerializedData& serialized_descriptors,
profiler::descriptors_list_t& descriptors,
profiler::blocks_t& _blocks,
profiler::thread_blocks_tree_t& threaded_trees,
uint32_t& total_descriptors_number,
profiler::bookmarks_t& bookmarks,
uint32_t& descriptors_count,
uint32_t& version,
profiler::processid_t& pid,
bool gather_statistics,
Expand All @@ -364,19 +388,22 @@ extern "C" {

}

inline profiler::block_index_t fillTreesFromFile(const char* filename, profiler::SerializedData& serialized_blocks,
inline profiler::block_index_t fillTreesFromFile(const char* filename, profiler::BeginEndTime& begin_end_time,
profiler::SerializedData& serialized_blocks,
profiler::SerializedData& serialized_descriptors,
profiler::descriptors_list_t& descriptors, profiler::blocks_t& _blocks,
profiler::thread_blocks_tree_t& threaded_trees,
uint32_t& total_descriptors_number,
profiler::bookmarks_t& bookmarks,
uint32_t& descriptors_count,
uint32_t& version,
profiler::processid_t& pid,
bool gather_statistics,
std::ostream& _log)
{
std::atomic<int> progress = ATOMIC_VAR_INIT(0);
return fillTreesFromFile(progress, filename, serialized_blocks, serialized_descriptors, descriptors, _blocks,
threaded_trees, total_descriptors_number, version, pid, gather_statistics, _log);
return fillTreesFromFile(progress, filename, begin_end_time, serialized_blocks, serialized_descriptors,
descriptors, _blocks, threaded_trees, bookmarks, descriptors_count, version, pid,
gather_statistics, _log);
}

inline bool readDescriptionsFromStream(std::istream& str,
Expand Down
8 changes: 6 additions & 2 deletions easy_profiler_core/include/easy/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ extern "C" {
const profiler::descriptors_list_t& descriptors,
profiler::block_id_t descriptors_count,
const profiler::thread_blocks_tree_t& trees,
const profiler::bookmarks_t& bookmarks,
profiler::block_getter_fn block_getter,
profiler::timestamp_t begin_time,
profiler::timestamp_t end_time,
Expand All @@ -63,6 +64,7 @@ extern "C" {
const profiler::descriptors_list_t& descriptors,
profiler::block_id_t descriptors_count,
const profiler::thread_blocks_tree_t& trees,
const profiler::bookmarks_t& bookmarks,
profiler::block_getter_fn block_getter,
profiler::timestamp_t begin_time,
profiler::timestamp_t end_time,
Expand All @@ -75,6 +77,7 @@ inline profiler::block_index_t writeTreesToFile(const char* filename,
const profiler::descriptors_list_t& descriptors,
profiler::block_id_t descriptors_count,
const profiler::thread_blocks_tree_t& trees,
const profiler::bookmarks_t& bookmarks,
profiler::block_getter_fn block_getter,
profiler::timestamp_t begin_time,
profiler::timestamp_t end_time,
Expand All @@ -83,14 +86,15 @@ inline profiler::block_index_t writeTreesToFile(const char* filename,
{
std::atomic<int> progress = ATOMIC_VAR_INIT(0);
return writeTreesToFile(progress, filename, serialized_descriptors, descriptors, descriptors_count, trees,
std::move(block_getter), begin_time, end_time, pid, log);
bookmarks, std::move(block_getter), begin_time, end_time, pid, log);
}

inline profiler::block_index_t writeTreesToStream(std::ostream& str,
const profiler::SerializedData& serialized_descriptors,
const profiler::descriptors_list_t& descriptors,
profiler::block_id_t descriptors_count,
const profiler::thread_blocks_tree_t& trees,
const profiler::bookmarks_t& bookmarks,
profiler::block_getter_fn block_getter,
profiler::timestamp_t begin_time,
profiler::timestamp_t end_time,
Expand All @@ -99,7 +103,7 @@ inline profiler::block_index_t writeTreesToStream(std::ostream& str,
{
std::atomic<int> progress = ATOMIC_VAR_INIT(0);
return writeTreesToStream(progress, str, serialized_descriptors, descriptors, descriptors_count, trees,
std::move(block_getter), begin_time, end_time, pid, log);
bookmarks, std::move(block_getter), begin_time, end_time, pid, log);
}

#endif //EASY_PROFILER_WRITER_H
6 changes: 6 additions & 0 deletions easy_profiler_core/profile_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,9 @@ uint32_t ProfileManager::dumpBlocksToStream(std::ostream& _outputStream, bool _l
write(_outputStream, m_descriptorsMemorySize);
write(_outputStream, blocks_number);
write(_outputStream, static_cast<uint32_t>(m_descriptors.size()));
write(_outputStream, static_cast<uint32_t>(m_threads.size()));
write(_outputStream, static_cast<uint16_t>(0)); // Bookmarks count (they can be created by user in the UI)
write(_outputStream, static_cast<uint16_t>(0)); // padding

// Write block descriptors
for (const auto descriptor : m_descriptors)
Expand Down Expand Up @@ -1135,6 +1138,9 @@ uint32_t ProfileManager::dumpBlocksToStream(std::ostream& _outputStream, bool _l
}
}

// End of threads section
write(_outputStream, EASY_PROFILER_SIGNATURE);

m_storedSpin.unlock();
m_spin.unlock();

Expand Down
Loading

0 comments on commit 0ae4304

Please sign in to comment.