Add timer for measure time consumption
This commit is contained in:
parent
e85e7a743b
commit
47952e0c08
@ -281,6 +281,8 @@ set(SLIC3R_SOURCES
|
|||||||
Utils.hpp
|
Utils.hpp
|
||||||
Time.cpp
|
Time.cpp
|
||||||
Time.hpp
|
Time.hpp
|
||||||
|
Timer.cpp
|
||||||
|
Timer.hpp
|
||||||
Thread.cpp
|
Thread.cpp
|
||||||
Thread.hpp
|
Thread.hpp
|
||||||
TriangleSelector.cpp
|
TriangleSelector.cpp
|
||||||
|
12
src/libslic3r/Timer.cpp
Normal file
12
src/libslic3r/Timer.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "Timer.hpp"
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
|
Slic3r::Timer::Timer(const std::string &name) : m_name(name), m_start(steady_clock::now()) {}
|
||||||
|
|
||||||
|
Slic3r::Timer::~Timer()
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "Timer '" << m_name << "' spend " <<
|
||||||
|
duration_cast<milliseconds>(steady_clock::now() - m_start).count() << "ms";
|
||||||
|
}
|
31
src/libslic3r/Timer.hpp
Normal file
31
src/libslic3r/Timer.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef libslic3r_Timer_hpp_
|
||||||
|
#define libslic3r_Timer_hpp_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instance of this class is used for measure time consumtion
|
||||||
|
/// of block code until instance is alive and write result to debug output
|
||||||
|
/// </summary>
|
||||||
|
class Timer
|
||||||
|
{
|
||||||
|
std::string m_name;
|
||||||
|
std::chrono::steady_clock::time_point m_start;
|
||||||
|
public:
|
||||||
|
/// <summary>
|
||||||
|
/// name describe timer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Describe timer in consol log</param>
|
||||||
|
Timer(const std::string& name);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// name describe timer
|
||||||
|
/// </summary>
|
||||||
|
~Timer();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Slic3r
|
||||||
|
#endif // libslic3r_Timer_hpp_
|
@ -10,6 +10,7 @@
|
|||||||
#include "slic3r/GUI/format.hpp"
|
#include "slic3r/GUI/format.hpp"
|
||||||
#include "slic3r/GUI/CameraUtils.hpp"
|
#include "slic3r/GUI/CameraUtils.hpp"
|
||||||
#include "slic3r/GUI/Jobs/EmbossJob.hpp"
|
#include "slic3r/GUI/Jobs/EmbossJob.hpp"
|
||||||
|
#include "slic3r/GUI/Jobs/CreateFontNameImageJob.hpp"
|
||||||
#include "slic3r/GUI/Jobs/NotificationProgressIndicator.hpp"
|
#include "slic3r/GUI/Jobs/NotificationProgressIndicator.hpp"
|
||||||
#include "slic3r/Utils/WxFontUtils.hpp"
|
#include "slic3r/Utils/WxFontUtils.hpp"
|
||||||
#include "slic3r/Utils/UndoRedo.hpp"
|
#include "slic3r/Utils/UndoRedo.hpp"
|
||||||
@ -17,6 +18,7 @@
|
|||||||
// TODO: remove include
|
// TODO: remove include
|
||||||
#include "libslic3r/SVG.hpp" // debug store
|
#include "libslic3r/SVG.hpp" // debug store
|
||||||
#include "libslic3r/Geometry.hpp" // covex hull 2d
|
#include "libslic3r/Geometry.hpp" // covex hull 2d
|
||||||
|
#include "libslic3r/Timer.hpp" // covex hull 2d
|
||||||
|
|
||||||
#include "libslic3r/NSVGUtils.hpp"
|
#include "libslic3r/NSVGUtils.hpp"
|
||||||
#include "libslic3r/Model.hpp"
|
#include "libslic3r/Model.hpp"
|
||||||
@ -1297,6 +1299,7 @@ static std::string concat(std::vector<wxString> data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoEmboss::init_face_names() {
|
void GLGizmoEmboss::init_face_names() {
|
||||||
|
Timer t("enumerate_fonts");
|
||||||
if (m_face_names.is_init) return;
|
if (m_face_names.is_init) return;
|
||||||
m_face_names.is_init = true;
|
m_face_names.is_init = true;
|
||||||
MyFontEnumerator font_enumerator(m_face_names.encoding);
|
MyFontEnumerator font_enumerator(m_face_names.encoding);
|
||||||
@ -1328,6 +1331,7 @@ void GLGizmoEmboss::init_face_names() {
|
|||||||
|
|
||||||
// create texture for visualization font face
|
// create texture for visualization font face
|
||||||
void GLGizmoEmboss::init_font_name_texture() {
|
void GLGizmoEmboss::init_font_name_texture() {
|
||||||
|
Timer t("init_font_name_texture");
|
||||||
// check if already exists
|
// check if already exists
|
||||||
GLuint &id = m_face_names.texture_id;
|
GLuint &id = m_face_names.texture_id;
|
||||||
if (id != 0) return;
|
if (id != 0) return;
|
||||||
@ -1355,56 +1359,12 @@ void GLGizmoEmboss::init_font_name_texture() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "slic3r/GUI/Jobs/CreateFontNameImageJob.hpp"
|
void GLGizmoEmboss::draw_font_preview(FaceName& face)
|
||||||
void GLGizmoEmboss::draw_font_list()
|
|
||||||
{
|
{
|
||||||
// Set partial
|
|
||||||
wxString actual_face_name;
|
|
||||||
if (m_style_manager.is_activ_font()) {
|
|
||||||
const std::optional<wxFont> &wx_font_opt = m_style_manager.get_wx_font();
|
|
||||||
if (wx_font_opt.has_value())
|
|
||||||
actual_face_name = wx_font_opt->GetFaceName();
|
|
||||||
}
|
|
||||||
const char * selected = (!actual_face_name.empty()) ?
|
|
||||||
actual_face_name.ToUTF8().data() : " --- ";
|
|
||||||
|
|
||||||
std::optional<size_t> del_index;
|
|
||||||
|
|
||||||
ScopeGuard unknown_font_sc;
|
|
||||||
if (m_is_unknown_font) {
|
|
||||||
m_imgui->disabled_end();
|
|
||||||
unknown_font_sc = ScopeGuard([&]() {
|
|
||||||
m_imgui->disabled_begin(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// variable for detection just closed combo box
|
|
||||||
static bool allow_update_rendered_font = false;
|
|
||||||
|
|
||||||
if (ImGui::BeginCombo("##font_selector", selected)) {
|
|
||||||
if (!m_face_names.is_init) init_face_names();
|
|
||||||
if (m_face_names.texture_id == 0) init_font_name_texture();
|
|
||||||
unsigned int &count_opened_fonts = m_face_names.count_opened_font_files;
|
unsigned int &count_opened_fonts = m_face_names.count_opened_font_files;
|
||||||
for (FaceName &face : m_face_names.faces) {
|
|
||||||
const wxString &face_name = face.name;
|
|
||||||
size_t index = &face - &m_face_names.faces.front();
|
|
||||||
ImGui::PushID(index);
|
|
||||||
bool is_selected = (actual_face_name == face_name);
|
|
||||||
ImVec2 selectable_size(0, m_gui_cfg->face_name_size.y());
|
|
||||||
ImGuiSelectableFlags flags = 0;
|
|
||||||
if (ImGui::Selectable(face.name_truncated.c_str(), is_selected, flags, selectable_size)) {
|
|
||||||
if (!select_facename(face_name)) {
|
|
||||||
del_index = index;
|
|
||||||
wxMessageBox(GUI::format(_L("Font face \"%1%\" can't be selected."), face_name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ImGui::IsItemHovered())
|
|
||||||
ImGui::SetTooltip("%s", face_name.ToUTF8().data());
|
|
||||||
if (is_selected) ImGui::SetItemDefaultFocus();
|
|
||||||
|
|
||||||
ImVec2 size(m_gui_cfg->face_name_size.x(), m_gui_cfg->face_name_size.y());
|
ImVec2 size(m_gui_cfg->face_name_size.x(), m_gui_cfg->face_name_size.y());
|
||||||
// set to pixel 0,0 in texture
|
// set to pixel 0,0 in texture
|
||||||
ImVec2 uv0(0.f, 0.f), uv1(1.f, 1.f / size.y / m_face_names.count_cached_textures);
|
ImVec2 uv0(0.f, 0.f), uv1(1.f / size.x, 1.f / size.y / m_face_names.count_cached_textures);
|
||||||
ImTextureID tex_id = (void *) (intptr_t) m_face_names.texture_id;
|
ImTextureID tex_id = (void *) (intptr_t) m_face_names.texture_id;
|
||||||
if (face.is_created != nullptr) {
|
if (face.is_created != nullptr) {
|
||||||
if (*face.is_created) {
|
if (*face.is_created) {
|
||||||
@ -1415,8 +1375,7 @@ void GLGizmoEmboss::draw_font_list()
|
|||||||
face.is_created = nullptr;
|
face.is_created = nullptr;
|
||||||
face.cancel->store(true);
|
face.cancel->store(true);
|
||||||
}
|
}
|
||||||
} else if (ImGui::IsItemVisible() &&
|
} else if (ImGui::IsItemVisible() && count_opened_fonts < m_gui_cfg->max_count_opened_font_files) {
|
||||||
count_opened_fonts < m_gui_cfg->max_count_opened_font_files) {
|
|
||||||
++count_opened_fonts;
|
++count_opened_fonts;
|
||||||
face.cancel = std::make_shared<std::atomic_bool>(false);
|
face.cancel = std::make_shared<std::atomic_bool>(false);
|
||||||
face.is_created = std::make_shared<bool>(false);
|
face.is_created = std::make_shared<bool>(false);
|
||||||
@ -1432,8 +1391,7 @@ void GLGizmoEmboss::draw_font_list()
|
|||||||
// set previous cach as deleted
|
// set previous cach as deleted
|
||||||
for (FaceName &f : m_face_names.faces)
|
for (FaceName &f : m_face_names.faces)
|
||||||
if (f.texture_index == texture_index) {
|
if (f.texture_index == texture_index) {
|
||||||
if (f.cancel != nullptr)
|
if (f.cancel != nullptr) f.cancel->store(true);
|
||||||
f.cancel->store(true);
|
|
||||||
f.is_created = nullptr;
|
f.is_created = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1441,8 +1399,9 @@ void GLGizmoEmboss::draw_font_list()
|
|||||||
face.texture_index = texture_index;
|
face.texture_index = texture_index;
|
||||||
|
|
||||||
// render text to texture
|
// render text to texture
|
||||||
FontImageData data{text,
|
FontImageData data{
|
||||||
face_name,
|
text,
|
||||||
|
face.wx_name,
|
||||||
m_face_names.encoding,
|
m_face_names.encoding,
|
||||||
m_face_names.texture_id,
|
m_face_names.texture_id,
|
||||||
m_face_names.texture_index,
|
m_face_names.texture_index,
|
||||||
@ -1462,7 +1421,59 @@ void GLGizmoEmboss::draw_font_list()
|
|||||||
|
|
||||||
ImGui::SameLine(m_gui_cfg->face_name_texture_offset_x);
|
ImGui::SameLine(m_gui_cfg->face_name_texture_offset_x);
|
||||||
ImGui::Image(tex_id, size, uv0, uv1);
|
ImGui::Image(tex_id, size, uv0, uv1);
|
||||||
ImGui::PopID();
|
}
|
||||||
|
|
||||||
|
void GLGizmoEmboss::draw_font_list()
|
||||||
|
{
|
||||||
|
// Set partial
|
||||||
|
wxString actual_face_name;
|
||||||
|
if (m_style_manager.is_activ_font()) {
|
||||||
|
const std::optional<wxFont> &wx_font_opt = m_style_manager.get_wx_font();
|
||||||
|
if (wx_font_opt.has_value())
|
||||||
|
actual_face_name = wx_font_opt->GetFaceName();
|
||||||
|
}
|
||||||
|
// name of actual selected font
|
||||||
|
const char * selected = (!actual_face_name.empty()) ?
|
||||||
|
actual_face_name.ToUTF8().data() : " --- ";
|
||||||
|
|
||||||
|
// Do not remove font face during enumeration
|
||||||
|
// When deletation of font appear this variable is set
|
||||||
|
std::optional<size_t> del_index;
|
||||||
|
|
||||||
|
// When is unknown font is inside .3mf only font selection is allowed
|
||||||
|
// Stop Imgui disable + Guard again start disabling
|
||||||
|
ScopeGuard unknown_font_sc;
|
||||||
|
if (m_is_unknown_font) {
|
||||||
|
m_imgui->disabled_end();
|
||||||
|
unknown_font_sc = ScopeGuard([&]() {
|
||||||
|
m_imgui->disabled_begin(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// variable for detect just closed combo box
|
||||||
|
static bool allow_update_rendered_font = false;
|
||||||
|
|
||||||
|
if (ImGui::BeginCombo("##font_selector", selected)) {
|
||||||
|
if (!m_face_names.is_init) init_face_names();
|
||||||
|
if (m_face_names.texture_id == 0) init_font_name_texture();
|
||||||
|
for (FaceName &face : m_face_names.faces) {
|
||||||
|
const wxString &wx_face_name = face.wx_name;
|
||||||
|
size_t index = &face - &m_face_names.faces.front();
|
||||||
|
ImGui::PushID(index);
|
||||||
|
ScopeGuard sg([]() { ImGui::PopID(); });
|
||||||
|
bool is_selected = (actual_face_name == wx_face_name);
|
||||||
|
ImVec2 selectable_size(0, m_gui_cfg->face_name_size.y());
|
||||||
|
ImGuiSelectableFlags flags = 0;
|
||||||
|
if (ImGui::Selectable(face.name_truncated.c_str(), is_selected, flags, selectable_size)) {
|
||||||
|
if (!select_facename(wx_face_name)) {
|
||||||
|
del_index = index;
|
||||||
|
wxMessageBox(GUI::format(_L("Font face \"%1%\" can't be selected."), wx_face_name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ImGui::IsItemHovered())
|
||||||
|
ImGui::SetTooltip("%s", wx_face_name.ToUTF8().data());
|
||||||
|
if (is_selected) ImGui::SetItemDefaultFocus();
|
||||||
|
draw_font_preview(face);
|
||||||
}
|
}
|
||||||
#ifdef SHOW_FONT_COUNT
|
#ifdef SHOW_FONT_COUNT
|
||||||
ImGui::TextColored(ImGuiWrapper::COL_GREY_LIGHT, "Count %d",
|
ImGui::TextColored(ImGuiWrapper::COL_GREY_LIGHT, "Count %d",
|
||||||
|
@ -115,6 +115,8 @@ private:
|
|||||||
void draw_style_save_as_popup();
|
void draw_style_save_as_popup();
|
||||||
void draw_style_add_button();
|
void draw_style_add_button();
|
||||||
void init_font_name_texture();
|
void init_font_name_texture();
|
||||||
|
struct FaceName;
|
||||||
|
void draw_font_preview(FaceName &face);
|
||||||
void draw_font_list();
|
void draw_font_list();
|
||||||
void draw_style_edit();
|
void draw_style_edit();
|
||||||
bool draw_italic_button();
|
bool draw_italic_button();
|
||||||
@ -227,7 +229,7 @@ private:
|
|||||||
EmbossStyleManager m_style_manager;
|
EmbossStyleManager m_style_manager;
|
||||||
|
|
||||||
struct FaceName{
|
struct FaceName{
|
||||||
wxString name;
|
wxString wx_name;
|
||||||
std::string name_truncated = "";
|
std::string name_truncated = "";
|
||||||
size_t texture_index = 0;
|
size_t texture_index = 0;
|
||||||
// State for generation of texture
|
// State for generation of texture
|
||||||
|
Loading…
Reference in New Issue
Block a user