Skip to content

Commit

Permalink
BUG: Small bugs, doc fixes, StopWatch class added (#894)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored Mar 22, 2024
1 parent 3a9c87d commit 327e4b6
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ set(SIMPLNX_SRCS
${SIMPLNX_SOURCE_DIR}/Utilities/Math/MatrixMath.cpp
${SIMPLNX_SOURCE_DIR}/Utilities/SampleSurfaceMesh.cpp
${SIMPLNX_SOURCE_DIR}/Utilities/MontageUtilities.cpp
${SIMPLNX_SOURCE_DIR}/Utilities/TimeUtilities.cpp

${SIMPLNX_SOURCE_DIR}/Utilities/Parsing/DREAM3D/Dream3dIO.cpp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FindKernelAvgMisorientationsImpl
if(counter > increment)
{
auto now = std::chrono::steady_clock::now();
if(std::chrono::duration_cast<std::chrono::milliseconds>(now - start).count() < 1000)
if(std::chrono::duration_cast<std::chrono::milliseconds>(now - start).count() > 1000)
{
m_Filter->sendThreadSafeProgressMessage(counter);
counter = 0;
Expand Down Expand Up @@ -186,7 +186,7 @@ void FindKernelAvgMisorientations::sendThreadSafeProgressMessage(usize counter)

m_ProgressCounter += counter;
auto now = std::chrono::steady_clock::now();
if(std::chrono::duration_cast<std::chrono::milliseconds>(now - m_InitialPoint).count() < 1000)
if(std::chrono::duration_cast<std::chrono::milliseconds>(now - m_InitialPoint).count() > 1000)
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Vtk Rectilinear Grid Exporter
# Write Vtk Rectilinear Grid

## Group (Subgroup)

I/O Filters

## Description

This Filter reads the **Feature** and phase ids together with image parameters required by Vtk to an output file named by the user. The file is used to generate the image of the **Features** and phases of the **Features**.
This Filter writes a VTK legacy file with a Dataset type of `RECTILINEAR_GRID`. The user can select which arrays from the Image Geometry will be written to the file.

% Auto generated parameter table will be inserted here

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void FeatureFaceCurvature::sendThreadSafeProgressMessage(usize counter)

m_ProgressCounter += counter;
auto now = std::chrono::steady_clock::now();
// We DO NOT Want to print at more than once a second. Hey. Don't copy/paste this line.
if(std::chrono::duration_cast<std::chrono::milliseconds>(now - m_InitialPoint).count() < 1000)
{
return;
Expand Down
33 changes: 33 additions & 0 deletions src/simplnx/Utilities/TimeUtilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "TimeUtilities.hpp"

#include <chrono>
#include <iostream>

#include <fmt/chrono.h>

using namespace nx::core;

// -----------------------------------------------------------------------------
void StopWatch::start()
{
start_time = std::chrono::steady_clock::now();
}

// -----------------------------------------------------------------------------
void StopWatch::stop()
{
end_time = std::chrono::steady_clock::now();
}

// -----------------------------------------------------------------------------
void StopWatch::print(std::ostream& os) const
{
os << toString();
}

// -----------------------------------------------------------------------------
std::string StopWatch::toString() const
{
auto elapsed = end_time - start_time;
return fmt::format("{:%H:%M:%S}.{:03}", elapsed, std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count() % 1000);
}
58 changes: 58 additions & 0 deletions src/simplnx/Utilities/TimeUtilities.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "simplnx/simplnx_export.hpp"

#include <fmt/core.h>
#include <fmt/ranges.h>

Expand All @@ -25,4 +27,60 @@ inline std::string ConvertMillisToHrsMinSecs(unsigned long long int millis)
return fmt::format("{:0>2}:{:0>2}:{:0>2}", hours, minutes, seconds);
}

/**
* @brief A stopwatch class for measuring durations with high precision.
*
* The StopWatch class utilizes the std::chrono library to measure time intervals.
* It can be started and stopped to measure specific durations, and the elapsed time
* can be printed to an output stream in a formatted manner.
*/
class SIMPLNX_EXPORT StopWatch
{
public:
StopWatch() = default;
~StopWatch() = default;

StopWatch(const StopWatch&) = default; // Copy Constructor Not Implemented
StopWatch(StopWatch&&) = default; // Move Constructor Not Implemented
StopWatch& operator=(const StopWatch&) = default; // Copy Assignment Not Implemented
StopWatch& operator=(StopWatch&&) = default; // Move Assignment Not Implemented

/**
* @brief Start the stopwatch.
*
* Captures the current time as the start point of the duration measurement.
* This function must be called before calling stop().
*/
void start();

/**
* @brief Stop the stopwatch.
*
* Captures the current time as the end point of the duration measurement.
* This function should be called after start().
*/
void stop();

/**
* @brief Print the elapsed time to a given output stream.
*
* Calculates the elapsed time between the start and stop points and formats it as
* "Hours:Minutes:Seconds.Milliseconds". This formatted string is then written to
* the provided std::ostream object.
*
* @param os The output stream to which the elapsed time will be written.
*/
void print(std::ostream& os) const;

/**
* @brief Returns a generated string of the elapsed time
* @return
*/
std::string toString() const;

private:
std::chrono::steady_clock::time_point start_time; ///< The start time point of the measurement.
std::chrono::steady_clock::time_point end_time; ///< The end time point of the measurement.
};

} // namespace nx::core

0 comments on commit 327e4b6

Please sign in to comment.