Skip to content

Commit a122e54

Browse files
authored
Merge pull request #2529 from SCIInstitute/amorris/expand-profiling
Add TIME_SCOPE profiling instrumentation across major C++ pipelines
2 parents 48f9c6a + 94cab3e commit a122e54

16 files changed

Lines changed: 91 additions & 5 deletions

File tree

Applications/shapeworks/Command.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Command.h"
2+
#include <Profiling.h>
23
#include <sstream>
34

45
namespace shapeworks {
@@ -22,6 +23,7 @@ std::vector<std::string> Command::parse_args(const std::vector<std::string> &arg
2223
///////////////////////////////////////////////////////////////////////////////
2324
int Command::run(SharedCommandData &sharedData)
2425
{
26+
TIME_SCOPE(QString::fromStdString(name()));
2527
const optparse::Values &options = parser.get_parsed_options();
2628

2729
return this->execute(options, sharedData) ? EXIT_SUCCESS : EXIT_FAILURE;

Libs/Alignment/Procrustes3D.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Procrustes3D.h"
22

3+
#include <Profiling.h>
34
#include <vnl/algo/vnl_svd.h>
45

56
#include <iostream>
@@ -44,6 +45,7 @@ void Procrustes3D::RemoveTranslation(SimilarityTransformListType& transforms, Sh
4445

4546
//---------------------------------------------------------------------------
4647
void Procrustes3D::AlignShapes(SimilarityTransformListType& transforms, ShapeListType& shapes) {
48+
TIME_SCOPE("Procrustes3D::AlignShapes");
4749
const RealType SOS_EPSILON = 1.0e-8;
4850

4951
PointType center;

Libs/Analyze/Analyze.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <Groom/GroomParameters.h>
44
#include <Logging.h>
5+
#include <Profiling.h>
56
#include <MeshWarper.h>
67
#include <Particles/ParticleNormalEvaluation.h>
78
#include <StringUtils.h>
@@ -167,6 +168,7 @@ Analyze::Analyze(ProjectHandle project) : project_(project), mesh_manager_(new M
167168

168169
//---------------------------------------------------------------------------
169170
void Analyze::run_offline_analysis(std::string outfile, float range, float steps) {
171+
TIME_SCOPE("Analyze::run_offline_analysis");
170172
SW_LOG("ShapeWorks Offline Analysis");
171173
if (!project_->get_particles_present()) {
172174
throw std::runtime_error("Project has not been optimized, please run optimize first");
@@ -478,6 +480,7 @@ bool Analyze::update_shapes() {
478480

479481
//---------------------------------------------------------------------------
480482
bool Analyze::compute_stats() {
483+
TIME_SCOPE("Analyze::compute_stats");
481484
if (stats_ready_) {
482485
return true;
483486
}

Libs/Analyze/Reconstruction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "itkNrrdImageIOFactory.h"
2424
#include "itkMetaImageIOFactory.h"
2525
#include "Reconstruction.h"
26+
#include <Profiling.h>
2627

2728
#include <vtkLoopSubdivisionFilter.h>
2829
#include <vtkButterflySubdivisionFilter.h>
@@ -67,6 +68,7 @@ vtkSmartPointer<vtkPolyData> Reconstruction<TTransformType,TInterpolatorType, TC
6768
std::vector< PointArrayType > local_pts,
6869
std::vector< PointArrayType > global_pts,
6970
std::vector<std::string> distance_transform) {
71+
TIME_SCOPE("Reconstruction::getDenseMean");
7072
if (!this->denseDone_ || !local_pts.empty() ||
7173
!distance_transform.empty() || !global_pts.empty()) {
7274
this->denseDone_ = false;
@@ -439,6 +441,7 @@ void Reconstruction<TTransformType,TInterpolatorType, TCoordRep, PixelType, Imag
439441
std::vector< PointArrayType > local_pts,
440442
std::vector< PointArrayType > global_pts,
441443
std::vector<std::string> distance_transform) {
444+
TIME_SCOPE("Reconstruction::computeDenseMean");
442445
try {
443446
//turn the sets of global points to one sparse global mean.
444447
float init[] = { 0.f,0.f,0.f };

Libs/Application/Job/Job.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <Job/Job.h>
2+
#include <Profiling.h>
23
namespace shapeworks {
34

45
//---------------------------------------------------------------------------
@@ -19,6 +20,12 @@ QString Job::get_abort_message() {
1920
return name() + " aborted. Duration: " + duration + " seconds";
2021
}
2122

23+
//---------------------------------------------------------------------------
24+
void Job::execute() {
25+
TIME_SCOPE(name());
26+
run();
27+
}
28+
2229
//---------------------------------------------------------------------------
2330
void Job::start_timer() { this->timer_.start(); }
2431

Libs/Application/Job/Job.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Job : public QObject {
1515
//! run the job
1616
virtual void run() = 0;
1717

18+
//! execute the job with profiling instrumentation
19+
void execute();
20+
1821
//! get the name of the job
1922
virtual QString name() = 0;
2023

Libs/Application/Job/PythonWorker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void PythonWorker::start_job(QSharedPointer<Job> job) {
104104
}
105105
Q_EMIT job->progress(0);
106106
current_job_ = job;
107-
current_job_->run();
107+
current_job_->execute();
108108
current_job_->set_complete(true);
109109
if (!job->get_quiet_mode()) {
110110
SW_LOG(current_job_->get_completion_message().toStdString());

Libs/Groom/Groom.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <GroomParameters.h>
33
#include <Image/Image.h>
44
#include <Logging.h>
5+
#include <Profiling.h>
56
#include <Mesh/Mesh.h>
67
#include <Mesh/MeshUtils.h>
78
#include <Optimize/Constraints/Constraints.h>
@@ -32,6 +33,7 @@ Groom::Groom(ProjectHandle project) : project_{project} {}
3233

3334
//---------------------------------------------------------------------------
3435
bool Groom::run() {
36+
TIME_SCOPE("Groom::run");
3537
ShapeWorksUtils::setup_threads();
3638

3739
used_names_.clear();
@@ -124,6 +126,7 @@ bool Groom::run() {
124126

125127
//---------------------------------------------------------------------------
126128
bool Groom::image_pipeline(std::shared_ptr<Subject> subject, size_t domain) {
129+
TIME_SCOPE("Groom::image_pipeline");
127130
// grab parameters
128131
auto params = GroomParameters(project_, project_->get_domain_names()[domain]);
129132

@@ -321,6 +324,7 @@ bool Groom::run_image_pipeline(Image& image, GroomParameters params) {
321324

322325
//---------------------------------------------------------------------------
323326
bool Groom::mesh_pipeline(std::shared_ptr<Subject> subject, size_t domain) {
327+
TIME_SCOPE("Groom::mesh_pipeline");
324328
// grab parameters
325329
auto params = GroomParameters(project_, project_->get_domain_names()[domain]);
326330

@@ -557,6 +561,7 @@ bool Groom::get_aborted() { return abort_; }
557561

558562
//---------------------------------------------------------------------------
559563
bool Groom::run_alignment() {
564+
TIME_SCOPE("Groom::run_alignment");
560565
size_t num_domains = project_->get_number_of_domains_per_subject();
561566
SW_DEBUG("Running alignment, number of domains = {}", num_domains);
562567
auto subjects = project_->get_subjects();

Libs/Image/Image.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Image.h"
22

33
#include <Logging.h>
4+
#include <Profiling.h>
45
#include <itkAntiAliasBinaryImageFilter.h>
56
#include <itkBinaryFillholeImageFilter.h>
67
#include <itkBinaryThresholdImageFilter.h>
@@ -104,6 +105,7 @@ Image& Image::operator=(Image&& img) {
104105
}
105106

106107
Image::ImageType::Pointer Image::read(const std::string& pathname) {
108+
TIME_SCOPE("Image::read");
107109
ImageUtils::register_itk_factories();
108110

109111
if (pathname.empty()) {
@@ -327,6 +329,7 @@ Image::ImageType::Pointer Image::readDICOMImage(const std::string& pathname) {
327329
}
328330

329331
Image& Image::write(const std::string& filename, bool compressed) {
332+
TIME_SCOPE("Image::write");
330333
if (!this->itk_image_) {
331334
throw std::invalid_argument("Image invalid");
332335
}
@@ -351,6 +354,7 @@ Image& Image::write(const std::string& filename, bool compressed) {
351354
}
352355

353356
Image& Image::antialias(unsigned iterations, double maxRMSErr, int layers) {
357+
TIME_SCOPE("Image::antialias");
354358
if (layers < 0) {
355359
throw std::invalid_argument("layers must be >= 0");
356360
}
@@ -405,6 +409,7 @@ Image& Image::resample(const TransformPtr transform, const Point3 origin, Dims d
405409
}
406410

407411
Image& Image::resample(const Vector3& spacing, Image::InterpolationType interp) {
412+
TIME_SCOPE("Image::resample");
408413
// compute logical dimensions that keep all image data for this spacing
409414
Dims inputDims(this->dims());
410415
Vector3 inputSpacing(this->spacing());
@@ -518,6 +523,7 @@ Image& Image::pad(IndexRegion& region, PixelType value) {
518523
}
519524

520525
Image& Image::pad(Dims lowerExtendRegion, Dims upperExtendRegion, PixelType value) {
526+
TIME_SCOPE("Image::pad");
521527
using FilterType = itk::ConstantPadImageFilter<ImageType, ImageType>;
522528
FilterType::Pointer filter = FilterType::New();
523529

@@ -632,6 +638,7 @@ Image& Image::binarize(PixelType minVal, PixelType maxVal, PixelType innerVal, P
632638
}
633639

634640
Image& Image::computeDT(PixelType isoValue) {
641+
TIME_SCOPE("Image::computeDT");
635642
using FilterType = itk::ReinitializeLevelSetImageFilter<ImageType>;
636643
FilterType::Pointer filter = FilterType::New();
637644

@@ -732,6 +739,7 @@ Image& Image::applyIntensityFilter(double minVal, double maxVal) {
732739
}
733740

734741
Image& Image::gaussianBlur(double sigma) {
742+
TIME_SCOPE("Image::gaussianBlur");
735743
using BlurType = itk::DiscreteGaussianImageFilter<ImageType, ImageType>;
736744
BlurType::Pointer blur = BlurType::New();
737745

@@ -744,6 +752,7 @@ Image& Image::gaussianBlur(double sigma) {
744752
}
745753

746754
Image& Image::crop(PhysicalRegion region, const int padding) {
755+
TIME_SCOPE("Image::crop");
747756
region.shrink(physicalBoundingBox()); // clip region to fit inside image
748757
if (!region.valid()) {
749758
throw std::invalid_argument("Invalid region specified (it may lie outside physical bounds of image).");
@@ -862,6 +871,7 @@ Image& Image::setCoordsys(ImageType::DirectionType coordsys) {
862871
}
863872

864873
Image& Image::isolate() {
874+
TIME_SCOPE("Image::isolate");
865875
typedef itk::Image<unsigned char, 3> IsolateType;
866876
typedef itk::CastImageFilter<ImageType, IsolateType> ToIntType;
867877
ToIntType::Pointer filter = ToIntType::New();

Libs/Mesh/Mesh.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "Image.h"
6464
#include "Libs/Optimize/Domain/Surface.h"
6565
#include "Logging.h"
66+
#include "Profiling.h"
6667
#include "MeshComputeThickness.h"
6768
#include "MeshUtils.h"
6869
#include "PreviewMeshQC/FEAreaCoverage.h"
@@ -273,6 +274,7 @@ Mesh& Mesh::coverage(const Mesh& otherMesh, bool allowBackIntersections, double
273274
}
274275

275276
Mesh& Mesh::smooth(int iterations, double relaxation) {
277+
TIME_SCOPE("Mesh::smooth");
276278
auto smoother = vtkSmartPointer<vtkSmoothPolyDataFilter>::New();
277279

278280
smoother->SetInputData(this->poly_data_);
@@ -293,6 +295,7 @@ Mesh& Mesh::smooth(int iterations, double relaxation) {
293295
}
294296

295297
Mesh& Mesh::smoothSinc(int iterations, double passband) {
298+
TIME_SCOPE("Mesh::smoothSinc");
296299
auto smoother = vtkSmartPointer<vtkWindowedSincPolyDataFilter>::New();
297300
smoother->SetInputData(this->poly_data_);
298301
// minimum of 2. See docs of vtkWindowedSincPolyDataFilter for explanation
@@ -316,6 +319,7 @@ Mesh& Mesh::smoothSinc(int iterations, double passband) {
316319
}
317320

318321
Mesh& Mesh::remesh(int numVertices, double adaptivity) {
322+
TIME_SCOPE("Mesh::remesh");
319323
// ACVD is very noisy to std::cout, even with console output set to zero
320324
// setting the failbit on std::cout will silence this until it's cleared below
321325
// std::cout.setstate(std::ios_base::failbit);
@@ -385,6 +389,7 @@ Mesh& Mesh::reflect(const Axis& axis, const Vector3& origin) {
385389
}
386390

387391
MeshTransform Mesh::createTransform(const Mesh& target, Mesh::AlignmentType align, unsigned iterations) {
392+
TIME_SCOPE("Mesh::createTransform");
388393
return createRegistrationTransform(target, align, iterations);
389394
}
390395

@@ -413,6 +418,7 @@ Mesh& Mesh::rotate(const double angle, const Axis axis) {
413418
}
414419

415420
Mesh& Mesh::fillHoles(double hole_size) {
421+
TIME_SCOPE("Mesh::fillHoles");
416422
auto filter = vtkSmartPointer<vtkFillHolesFilter>::New();
417423
filter->SetInputData(this->poly_data_);
418424
filter->SetHoleSize(hole_size);
@@ -430,6 +436,7 @@ Mesh& Mesh::fillHoles(double hole_size) {
430436
}
431437

432438
Mesh& Mesh::clean() {
439+
TIME_SCOPE("Mesh::clean");
433440
auto clean = vtkSmartPointer<vtkCleanPolyData>::New();
434441
clean->ConvertPolysToLinesOff();
435442
clean->ConvertLinesToPointsOff();
@@ -669,6 +676,7 @@ bool Mesh::detectTriangular() {
669676
}
670677

671678
std::vector<Field> Mesh::distance(const Mesh& target, const DistanceMethod method) const {
679+
TIME_SCOPE("Mesh::distance");
672680
if (target.numPoints() == 0 || numPoints() == 0) {
673681
throw std::invalid_argument("meshes must have points");
674682
}
@@ -832,6 +840,7 @@ bool Mesh::isPointInside(const Point3 point) const {
832840
}
833841

834842
double Mesh::geodesicDistance(int source, int target) const {
843+
TIME_SCOPE("Mesh::geodesicDistance");
835844
if (source < 0 || target < 0 || numPoints() < source || numPoints() < target) {
836845
throw std::invalid_argument("requested point ids outside range of points available in mesh");
837846
}
@@ -841,6 +850,7 @@ double Mesh::geodesicDistance(int source, int target) const {
841850
}
842851

843852
Field Mesh::geodesicDistance(const Point3 landmark) const {
853+
TIME_SCOPE("Mesh::geodesicDistance");
844854
auto distance = vtkSmartPointer<vtkDoubleArray>::New();
845855
distance->SetNumberOfComponents(1);
846856
distance->SetNumberOfTuples(numPoints());
@@ -856,6 +866,7 @@ Field Mesh::geodesicDistance(const Point3 landmark) const {
856866
}
857867

858868
Field Mesh::geodesicDistance(const std::vector<Point3> curve) const {
869+
TIME_SCOPE("Mesh::geodesicDistance");
859870
auto minDistance = vtkSmartPointer<vtkDoubleArray>::New();
860871
minDistance->SetNumberOfComponents(1);
861872
minDistance->SetNumberOfTuples(numPoints());
@@ -875,6 +886,7 @@ Field Mesh::geodesicDistance(const std::vector<Point3> curve) const {
875886
}
876887

877888
Field Mesh::curvature(const CurvatureType type) const {
889+
TIME_SCOPE("Mesh::curvature");
878890
Eigen::MatrixXd V = points();
879891
Eigen::MatrixXi F = faces();
880892

0 commit comments

Comments
 (0)