Logging of memory used by the gcode processor and viewer
This commit is contained in:
parent
aedb3892ba
commit
dd6994c3b2
4 changed files with 126 additions and 71 deletions
|
@ -787,10 +787,12 @@ void GCode::do_export(Print* print, const char* path, GCodePreviewData* preview_
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER
|
#if ENABLE_GCODE_VIEWER
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "Start processing gcode, " << log_memory_info();
|
||||||
m_processor.process_file(path_tmp, [print]() { print->throw_if_canceled(); });
|
m_processor.process_file(path_tmp, [print]() { print->throw_if_canceled(); });
|
||||||
DoExport::update_print_estimated_times_stats(m_processor, print->m_print_statistics);
|
DoExport::update_print_estimated_times_stats(m_processor, print->m_print_statistics);
|
||||||
if (result != nullptr)
|
if (result != nullptr)
|
||||||
*result = std::move(m_processor.extract_result());
|
*result = std::move(m_processor.extract_result());
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "Finished processing gcode, " << log_memory_info();
|
||||||
#else
|
#else
|
||||||
GCodeTimeEstimator::PostProcessData normal_data = m_normal_time_estimator.get_post_process_data();
|
GCodeTimeEstimator::PostProcessData normal_data = m_normal_time_estimator.get_post_process_data();
|
||||||
GCodeTimeEstimator::PostProcessData silent_data = m_silent_time_estimator.get_post_process_data();
|
GCodeTimeEstimator::PostProcessData silent_data = m_silent_time_estimator.get_post_process_data();
|
||||||
|
@ -2452,14 +2454,17 @@ void GCode::process_layer(
|
||||||
#endif /* HAS_PRESSURE_EQUALIZER */
|
#endif /* HAS_PRESSURE_EQUALIZER */
|
||||||
|
|
||||||
_write(file, gcode);
|
_write(file, gcode);
|
||||||
#if !ENABLE_GCODE_VIEWER
|
#if ENABLE_GCODE_VIEWER
|
||||||
|
BOOST_LOG_TRIVIAL(trace) << "Exported layer " << layer.id() << " print_z " << print_z <<
|
||||||
|
log_memory_info();
|
||||||
|
#else
|
||||||
BOOST_LOG_TRIVIAL(trace) << "Exported layer " << layer.id() << " print_z " << print_z <<
|
BOOST_LOG_TRIVIAL(trace) << "Exported layer " << layer.id() << " print_z " << print_z <<
|
||||||
", time estimator memory: " <<
|
", time estimator memory: " <<
|
||||||
format_memsize_MB(m_normal_time_estimator.memory_used() + (m_silent_time_estimator_enabled ? m_silent_time_estimator.memory_used() : 0)) <<
|
format_memsize_MB(m_normal_time_estimator.memory_used() + (m_silent_time_estimator_enabled ? m_silent_time_estimator.memory_used() : 0)) <<
|
||||||
", analyzer memory: " <<
|
", analyzer memory: " <<
|
||||||
format_memsize_MB(m_analyzer.memory_used()) <<
|
format_memsize_MB(m_analyzer.memory_used()) <<
|
||||||
log_memory_info();
|
log_memory_info();
|
||||||
#endif // !ENABLE_GCODE_VIEWER
|
#endif // ENABLE_GCODE_VIEWER
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCode::apply_print_config(const PrintConfig &print_config)
|
void GCode::apply_print_config(const PrintConfig &print_config)
|
||||||
|
|
|
@ -1583,7 +1583,7 @@ void Print::auto_assign_extruders(ModelObject* model_object) const
|
||||||
// Slicing process, running at a background thread.
|
// Slicing process, running at a background thread.
|
||||||
void Print::process()
|
void Print::process()
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(info) << "Staring the slicing process." << log_memory_info();
|
BOOST_LOG_TRIVIAL(info) << "Starting the slicing process." << log_memory_info();
|
||||||
for (PrintObject *obj : m_objects)
|
for (PrintObject *obj : m_objects)
|
||||||
obj->make_perimeters();
|
obj->make_perimeters();
|
||||||
this->set_status(70, L("Infilling layers"));
|
this->set_status(70, L("Infilling layers"));
|
||||||
|
|
|
@ -440,6 +440,19 @@ void GCodeViewer::refresh(const GCodeProcessor::Result& gcode_result, const std:
|
||||||
|
|
||||||
// update buffers' render paths
|
// update buffers' render paths
|
||||||
refresh_render_paths(false, false);
|
refresh_render_paths(false, false);
|
||||||
|
|
||||||
|
if (Slic3r::get_logging_level() >= 5) {
|
||||||
|
long long paths_size = 0;
|
||||||
|
for (const TBuffer& buffer : m_buffers) {
|
||||||
|
paths_size += SLIC3R_STDVEC_MEMSIZE(buffer.paths, Path);
|
||||||
|
}
|
||||||
|
long long layers_zs_size = SLIC3R_STDVEC_MEMSIZE(m_layers_zs, double);
|
||||||
|
long long roles_size = SLIC3R_STDVEC_MEMSIZE(m_roles, Slic3r::ExtrusionRole);
|
||||||
|
long long extruder_ids_size = SLIC3R_STDVEC_MEMSIZE(m_extruder_ids, unsigned char);
|
||||||
|
BOOST_LOG_TRIVIAL(trace) << "Refreshed G-code extrusion paths, "
|
||||||
|
<< format_memsize_MB(paths_size + layers_zs_size + roles_size + extruder_ids_size)
|
||||||
|
<< log_memory_info();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCodeViewer::reset()
|
void GCodeViewer::reset()
|
||||||
|
@ -1209,6 +1222,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
||||||
buffer.vertices.count = buffer_vertices.size() / buffer.vertices.vertex_size_floats();
|
buffer.vertices.count = buffer_vertices.size() / buffer.vertices.vertex_size_floats();
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
m_statistics.vertices_gpu_size += buffer_vertices.size() * sizeof(float);
|
m_statistics.vertices_gpu_size += buffer_vertices.size() * sizeof(float);
|
||||||
|
m_statistics.max_vertices_in_vertex_buffer = std::max(m_statistics.max_vertices_in_vertex_buffer, static_cast<long long>(buffer.vertices.count));
|
||||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
|
||||||
glsafe(::glGenBuffers(1, &buffer.vertices.id));
|
glsafe(::glGenBuffers(1, &buffer.vertices.id));
|
||||||
|
@ -1221,6 +1235,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
||||||
buffer.indices.count = buffer_indices.size();
|
buffer.indices.count = buffer_indices.size();
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
m_statistics.indices_gpu_size += buffer.indices.count * sizeof(unsigned int);
|
m_statistics.indices_gpu_size += buffer.indices.count * sizeof(unsigned int);
|
||||||
|
m_statistics.max_indices_in_index_buffer = std::max(m_statistics.max_indices_in_index_buffer, static_cast<long long>(buffer.indices.count));
|
||||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
|
||||||
if (buffer.indices.count > 0) {
|
if (buffer.indices.count > 0) {
|
||||||
|
@ -1278,6 +1293,27 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
||||||
std::sort(m_extruder_ids.begin(), m_extruder_ids.end());
|
std::sort(m_extruder_ids.begin(), m_extruder_ids.end());
|
||||||
m_extruder_ids.erase(std::unique(m_extruder_ids.begin(), m_extruder_ids.end()), m_extruder_ids.end());
|
m_extruder_ids.erase(std::unique(m_extruder_ids.begin(), m_extruder_ids.end()), m_extruder_ids.end());
|
||||||
|
|
||||||
|
if (Slic3r::get_logging_level() >= 5) {
|
||||||
|
long long vertices_size = 0;
|
||||||
|
for (size_t i = 0; i < vertices.size(); ++i) {
|
||||||
|
vertices_size += SLIC3R_STDVEC_MEMSIZE(vertices[i], float);
|
||||||
|
}
|
||||||
|
long long indices_size = 0;
|
||||||
|
for (size_t i = 0; i < indices.size(); ++i) {
|
||||||
|
indices_size += SLIC3R_STDVEC_MEMSIZE(indices[i], unsigned int);
|
||||||
|
}
|
||||||
|
long long paths_size = 0;
|
||||||
|
for (const TBuffer& buffer : m_buffers) {
|
||||||
|
paths_size += SLIC3R_STDVEC_MEMSIZE(buffer.paths, Path);
|
||||||
|
}
|
||||||
|
long long layers_zs_size = SLIC3R_STDVEC_MEMSIZE(m_layers_zs, double);
|
||||||
|
long long roles_size = SLIC3R_STDVEC_MEMSIZE(m_roles, Slic3r::ExtrusionRole);
|
||||||
|
long long extruder_ids_size = SLIC3R_STDVEC_MEMSIZE(m_extruder_ids, unsigned char);
|
||||||
|
BOOST_LOG_TRIVIAL(trace) << "Loaded G-code extrusion paths, "
|
||||||
|
<< format_memsize_MB(vertices_size + indices_size + paths_size + layers_zs_size + roles_size + extruder_ids_size)
|
||||||
|
<< log_memory_info();
|
||||||
|
}
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
m_statistics.load_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start_time).count();
|
m_statistics.load_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start_time).count();
|
||||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
@ -2266,77 +2302,87 @@ void GCodeViewer::render_statistics() const
|
||||||
|
|
||||||
ImGuiWrapper& imgui = *wxGetApp().imgui();
|
ImGuiWrapper& imgui = *wxGetApp().imgui();
|
||||||
|
|
||||||
|
auto add_time = [this, &imgui](const std::string& label, long long time) {
|
||||||
|
char buf[1024];
|
||||||
|
sprintf(buf, "%lld ms (%s)", time, get_time_dhms(static_cast<float>(time) * 0.001f).c_str());
|
||||||
|
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
|
||||||
|
ImGui::SameLine(offset);
|
||||||
|
imgui.text(buf);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto add_memory = [this, &imgui](const std::string& label, long long memory) {
|
||||||
|
static const float mb = 1024.0f * 1024.0f;
|
||||||
|
static const float inv_mb = 1.0f / mb;
|
||||||
|
static const float gb = 1024.0f * mb;
|
||||||
|
static const float inv_gb = 1.0f / gb;
|
||||||
|
char buf[1024];
|
||||||
|
if (static_cast<float>(memory) < gb)
|
||||||
|
sprintf(buf, "%lld bytes (%.3f MB)", memory, static_cast<float>(memory) * inv_mb);
|
||||||
|
else
|
||||||
|
sprintf(buf, "%lld bytes (%.3f GB)", memory, static_cast<float>(memory) * inv_gb);
|
||||||
|
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
|
||||||
|
ImGui::SameLine(offset);
|
||||||
|
imgui.text(buf);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto add_counter = [this, &imgui](const std::string& label, long long counter) {
|
||||||
|
char buf[1024];
|
||||||
|
sprintf(buf, "%lld", counter);
|
||||||
|
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
|
||||||
|
ImGui::SameLine(offset);
|
||||||
|
imgui.text(buf);
|
||||||
|
};
|
||||||
|
|
||||||
imgui.set_next_window_pos(0.5f * wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_width(), 0.0f, ImGuiCond_Once, 0.5f, 0.0f);
|
imgui.set_next_window_pos(0.5f * wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_width(), 0.0f, ImGuiCond_Once, 0.5f, 0.0f);
|
||||||
|
ImGui::SetNextWindowSizeConstraints({ 300, -1 }, { 600, -1 });
|
||||||
imgui.begin(std::string("GCodeViewer Statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize);
|
imgui.begin(std::string("GCodeViewer Statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize);
|
||||||
ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow());
|
ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow());
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("GCodeProcessor time:"));
|
if (ImGui::CollapsingHeader("Time")) {
|
||||||
ImGui::SameLine(offset);
|
add_time(std::string("GCodeProcessor:"), m_statistics.results_time);
|
||||||
imgui.text(std::to_string(m_statistics.results_time) + " ms");
|
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
add_time(std::string("Load:"), m_statistics.load_time);
|
||||||
|
add_time(std::string("Refresh:"), m_statistics.refresh_time);
|
||||||
|
add_time(std::string("Refresh paths:"), m_statistics.refresh_paths_time);
|
||||||
|
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
|
||||||
|
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
|
||||||
|
}
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Load time:"));
|
if (ImGui::CollapsingHeader("OpenGL calls")) {
|
||||||
ImGui::SameLine(offset);
|
add_counter(std::string("Multi GL_POINTS:"), m_statistics.gl_multi_points_calls_count);
|
||||||
imgui.text(std::to_string(m_statistics.load_time) + " ms");
|
add_counter(std::string("Multi GL_LINES:"), m_statistics.gl_multi_lines_calls_count);
|
||||||
|
add_counter(std::string("Multi GL_TRIANGLES:"), m_statistics.gl_multi_triangles_calls_count);
|
||||||
|
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
|
||||||
|
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
|
||||||
|
}
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Refresh time:"));
|
if (ImGui::CollapsingHeader("CPU memory")) {
|
||||||
ImGui::SameLine(offset);
|
add_memory(std::string("GCodeProcessor results:"), m_statistics.results_size);
|
||||||
imgui.text(std::to_string(m_statistics.refresh_time) + " ms");
|
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Refresh paths time:"));
|
ImGui::Separator();
|
||||||
ImGui::SameLine(offset);
|
add_memory(std::string("Paths:"), m_statistics.paths_size);
|
||||||
imgui.text(std::to_string(m_statistics.refresh_paths_time) + " ms");
|
add_memory(std::string("Render paths:"), m_statistics.render_paths_size);
|
||||||
|
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
|
||||||
|
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::Separator();
|
if (ImGui::CollapsingHeader("GPU memory")) {
|
||||||
|
add_memory(std::string("Vertices:"), m_statistics.vertices_gpu_size);
|
||||||
|
add_memory(std::string("Indices:"), m_statistics.indices_gpu_size);
|
||||||
|
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
|
||||||
|
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
|
||||||
|
}
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Multi GL_POINTS calls:"));
|
if (ImGui::CollapsingHeader("Other")) {
|
||||||
ImGui::SameLine(offset);
|
add_counter(std::string("Travel segments count:"), m_statistics.travel_segments_count);
|
||||||
imgui.text(std::to_string(m_statistics.gl_multi_points_calls_count));
|
add_counter(std::string("Extrude segments count:"), m_statistics.extrude_segments_count);
|
||||||
|
add_counter(std::string("Max vertices in vertex buffer:"), m_statistics.max_vertices_in_vertex_buffer);
|
||||||
|
add_counter(std::string("Max indices in index buffer:"), m_statistics.max_indices_in_index_buffer);
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Multi GL_LINES calls:"));
|
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
|
||||||
ImGui::SameLine(offset);
|
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
|
||||||
imgui.text(std::to_string(m_statistics.gl_multi_lines_calls_count));
|
}
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Multi GL_TRIANGLES calls:"));
|
|
||||||
ImGui::SameLine(offset);
|
|
||||||
imgui.text(std::to_string(m_statistics.gl_multi_triangles_calls_count));
|
|
||||||
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("GCodeProcessor results:"));
|
|
||||||
ImGui::SameLine(offset);
|
|
||||||
imgui.text(std::to_string(m_statistics.results_size) + " bytes");
|
|
||||||
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Paths CPU:"));
|
|
||||||
ImGui::SameLine(offset);
|
|
||||||
imgui.text(std::to_string(m_statistics.paths_size) + " bytes");
|
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Render paths CPU:"));
|
|
||||||
ImGui::SameLine(offset);
|
|
||||||
imgui.text(std::to_string(m_statistics.render_paths_size) + " bytes");
|
|
||||||
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Vertices GPU:"));
|
|
||||||
ImGui::SameLine(offset);
|
|
||||||
imgui.text(std::to_string(m_statistics.vertices_gpu_size) + " bytes");
|
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Indices GPU:"));
|
|
||||||
ImGui::SameLine(offset);
|
|
||||||
imgui.text(std::to_string(m_statistics.indices_gpu_size) + " bytes");
|
|
||||||
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Travel segments count:"));
|
|
||||||
ImGui::SameLine(offset);
|
|
||||||
imgui.text(std::to_string(m_statistics.travel_segments_count));
|
|
||||||
|
|
||||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, std::string("Extrude segments count:"));
|
|
||||||
ImGui::SameLine(offset);
|
|
||||||
imgui.text(std::to_string(m_statistics.extrude_segments_count));
|
|
||||||
|
|
||||||
imgui.end();
|
imgui.end();
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,7 +264,7 @@ class GCodeViewer
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
struct Statistics
|
struct Statistics
|
||||||
{
|
{
|
||||||
// times
|
// time
|
||||||
long long results_time{ 0 };
|
long long results_time{ 0 };
|
||||||
long long load_time{ 0 };
|
long long load_time{ 0 };
|
||||||
long long refresh_time{ 0 };
|
long long refresh_time{ 0 };
|
||||||
|
@ -279,15 +279,17 @@ class GCodeViewer
|
||||||
long long indices_gpu_size{ 0 };
|
long long indices_gpu_size{ 0 };
|
||||||
long long paths_size{ 0 };
|
long long paths_size{ 0 };
|
||||||
long long render_paths_size{ 0 };
|
long long render_paths_size{ 0 };
|
||||||
// others
|
// other
|
||||||
long long travel_segments_count{ 0 };
|
long long travel_segments_count{ 0 };
|
||||||
long long extrude_segments_count{ 0 };
|
long long extrude_segments_count{ 0 };
|
||||||
|
long long max_vertices_in_vertex_buffer{ 0 };
|
||||||
|
long long max_indices_in_index_buffer{ 0 };
|
||||||
|
|
||||||
void reset_all() {
|
void reset_all() {
|
||||||
reset_times();
|
reset_times();
|
||||||
reset_opengl();
|
reset_opengl();
|
||||||
reset_sizes();
|
reset_sizes();
|
||||||
reset_counters();
|
reset_others();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_times() {
|
void reset_times() {
|
||||||
|
@ -311,9 +313,11 @@ class GCodeViewer
|
||||||
render_paths_size = 0;
|
render_paths_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_counters() {
|
void reset_others() {
|
||||||
travel_segments_count = 0;
|
travel_segments_count = 0;
|
||||||
extrude_segments_count = 0;
|
extrude_segments_count = 0;
|
||||||
|
max_vertices_in_vertex_buffer = 0;
|
||||||
|
max_indices_in_index_buffer = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
|
Loading…
Reference in a new issue