Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
update loggin (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
mclarsen authored Jan 21, 2020
1 parent db2e756 commit a480862
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/tests/vtkh/t_vtk-h_volume_renderer_par.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ TEST(vtkh_volume_renderer, vtkh_parallel_render)
tracer.SetInput(&data_set);
tracer.SetField("point_data_Float64");

tracer.Update();

vtkh::Scene scene;
scene.AddRender(render);
scene.AddRenderer(&tracer);
Expand Down
32 changes: 29 additions & 3 deletions src/vtkh/Logger.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <vtkh/vtkh.hpp>
#include <vtkh/Logger.hpp>

#include <iomanip>
#include <cstdlib>

namespace vtkh
{
std::map<std::string, Logger*> Logger::Loggers;
Expand Down Expand Up @@ -54,6 +57,7 @@ DataLogger::DataLogger()
Rank(0)
{
Blocks.push(Block(0));
KeyCounters.push(std::map<std::string,int>());
}

DataLogger::~DataLogger()
Expand Down Expand Up @@ -109,11 +113,20 @@ void
DataLogger::WriteLog()
{
std::stringstream log_name;
log_name<<"vtkh_data_"<<Rank;

std::string log_prefix = "vtkh_data";
if(const char* log_p = std::getenv("VTKH_LOG_PREFIX"))
{
log_prefix = std::string(log_p);
}

log_name<<log_prefix<<"_";
log_name<<std::setfill('0')<<std::setw(6)<<Rank;
log_name<<".yaml";

std::ofstream stream;
stream.open(log_name.str().c_str(), std::ofstream::out);
stream.open(log_name.str().c_str(), std::ofstream::app);

if(!stream.is_open())
{
std::cerr<<"Warning: could not open the vtkh data log file\n";
Expand All @@ -127,9 +140,21 @@ void
DataLogger::OpenLogEntry(const std::string &entryName)
{
WriteIndent();
Stream<<entryName<<":"<<"\n";
// ensure that we have unique keys for valid yaml
int key_count = KeyCounters.top()[entryName]++;

if(key_count != 0)
{
Stream<<entryName<<"_"<<key_count<<":"<<"\n";
}
else
{
Stream<<entryName<<":"<<"\n";
}

int indent = this->CurrentBlock().Indent;
Blocks.push(Block(indent+1));
KeyCounters.push(std::map<std::string,int>());

Timer timer;
Timers.push(timer);
Expand All @@ -143,6 +168,7 @@ DataLogger::CloseLogEntry()
this->Stream<<"time : "<<Timers.top().elapsed()<<"\n";
Timers.pop();
Blocks.pop();
KeyCounters.pop();
AtBlockStart = false;
}
};
1 change: 1 addition & 0 deletions src/vtkh/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class VTKH_API DataLogger
static class DataLogger Instance;
std::stack<Block> Blocks;
std::stack<Timer> Timers;
std::stack<std::map<std::string,int>> KeyCounters;
bool AtBlockStart;
int Rank;
};
Expand Down
21 changes: 21 additions & 0 deletions src/vtkh/rendering/VolumeRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <vtkh/utils/vtkm_array_utils.hpp>
#include <vtkh/rendering/compositing/Compositor.hpp>
#include <vtkh/Logger.hpp>

#include <vtkm/rendering/CanvasRayTracer.h>

Expand Down Expand Up @@ -73,9 +74,29 @@ VolumeRenderer::~VolumeRenderer()
void
VolumeRenderer::Update()
{
VTKH_DATA_OPEN(this->GetName());
#ifdef VTKH_ENABLE_LOGGING
VTKH_DATA_ADD("device", GetCurrentDevice());
long long int in_cells = this->m_input->GetNumberOfCells();
VTKH_DATA_ADD("input_cells", in_cells);
VTKH_DATA_ADD("input_domains", this->m_input->GetNumberOfDomains());
int in_topo_dims;
bool in_structured = this->m_input->IsStructured(in_topo_dims);
if(in_structured)
{
VTKH_DATA_ADD("in_topology", "structured");
}
else
{
VTKH_DATA_ADD("in_topology", "unstructured");
}
#endif

PreExecute();
Renderer::DoExecute();
PostExecute();

VTKH_DATA_CLOSE();
}

void VolumeRenderer::SetColorTable(const vtkm::cont::ColorTable &color_table)
Expand Down

0 comments on commit a480862

Please sign in to comment.