Skip to content

Commit

Permalink
Per #2724, wrap each call to sdebug_examine() with a check of the ver…
Browse files Browse the repository at this point in the history
…bosity level to avoid unnecessary loops through the data. Note that all calls to the logger would actually create the log message and the logger decides whether or not to print it. Wrapping expensive debugging log messages in vebosity level check is more efficient.
  • Loading branch information
JohnHalleyGotway committed Nov 6, 2023
1 parent aa80374 commit 93f50ce
Showing 1 changed file with 56 additions and 28 deletions.
84 changes: 56 additions & 28 deletions src/libcode/vx_shapedata/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,17 @@ void ModeFuzzyEngine::do_fcst_convolution() {
// Apply a circular convolution to the raw field
//

mlog << Debug(4) << " Before fcst convolution: "
<< fcst_conv->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " Before fcst convolution: "
<< fcst_conv->sdebug_examine() << "\n";
}

if(r > 0) fcst_conv->conv_filter_circ(2*r + 1, conf_info.Fcst->vld_thresh);

mlog << Debug(4) << " After fcst convolution: "
<< fcst_conv->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After fcst convolution: "
<< fcst_conv->sdebug_examine() << "\n";
}

need_fcst_conv = false;
need_fcst_thresh = true;
Expand Down Expand Up @@ -627,16 +631,20 @@ void ModeFuzzyEngine::do_obs_convolution() {
mlog << Debug(3) << "Applying circular convolution of radius "
<< r << " to the observation field.\n";

mlog << Debug(4) << " Before obs convolution: "
<< obs_conv->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " Before obs convolution: "
<< obs_conv->sdebug_examine() << "\n";
}

//
// Apply a circular convolution to the raw field
//
if(r > 0) obs_conv->conv_filter_circ(2*r + 1, conf_info.Obs->vld_thresh);

mlog << Debug(4) << " After obs convolution: "
<< obs_conv->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After obs convolution: "
<< obs_conv->sdebug_examine() << "\n";
}

need_obs_conv = false;
need_obs_thresh = true;
Expand All @@ -662,16 +670,20 @@ void ModeFuzzyEngine::do_fcst_thresholding() {
*fcst_thresh = *fcst_raw;
fcst_thresh->threshold(conf_info.Fcst->conv_thresh);

mlog << Debug(4) << " After thresholding raw fcst field: "
<< fcst_thresh->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After thresholding raw fcst field: "
<< fcst_thresh->sdebug_examine() << "\n";
}

//
// Threshold the convolved field
//
fcst_mask->threshold(conf_info.Fcst->conv_thresh);

mlog << Debug(4) << " After thresholding convolved fcst field: "
<< fcst_mask->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After thresholding convolved fcst field: "
<< fcst_mask->sdebug_examine() << "\n";
}

mlog << Debug(3) << "Applying convolution threshold "
<< conf_info.Fcst->conv_thresh.get_str()
Expand Down Expand Up @@ -701,16 +713,20 @@ void ModeFuzzyEngine::do_obs_thresholding() {
*obs_thresh = *obs_raw;
obs_thresh->threshold(conf_info.Obs->conv_thresh);

mlog << Debug(4) << " After thresholding raw obs field: "
<< obs_thresh->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After thresholding raw obs field: "
<< obs_thresh->sdebug_examine() << "\n";
}

//
// Threshold the convolved field
//
obs_mask->threshold(conf_info.Obs->conv_thresh);

mlog << Debug(4) << " After thresholding convolved obs field: "
<< obs_mask->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After thresholding convolved obs field: "
<< obs_mask->sdebug_examine() << "\n";
}

mlog << Debug(3) << "Applying convolution threshold "
<< conf_info.Obs->conv_thresh.get_str()
Expand Down Expand Up @@ -745,8 +761,10 @@ void ModeFuzzyEngine::do_fcst_filtering() {
fcst_raw, conf_info.Fcst->conv_thresh, grid,
conf_info.Fcst->var_info->is_precipitation());

mlog << Debug(4) << " After attribute filtering of fcst field: "
<< fcst_mask->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After attribute filtering of fcst field: "
<< fcst_mask->sdebug_examine() << "\n";
}

mlog << Debug(3) << "Applying object attribute filtering"
<< " resulted in " << fcst_mask->n_objects()
Expand Down Expand Up @@ -783,8 +801,10 @@ void ModeFuzzyEngine::do_obs_filtering() {
obs_raw, conf_info.Obs->conv_thresh, grid,
conf_info.Obs->var_info->is_precipitation());

mlog << Debug(4) << " After attribute filtering of obs field: "
<< obs_mask->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After attribute filtering of obs field: "
<< obs_mask->sdebug_examine() << "\n";
}

mlog << Debug(3) << "Applying object attribute filtering"
<< " resulted in " << obs_mask->n_objects()
Expand Down Expand Up @@ -814,8 +834,10 @@ void ModeFuzzyEngine::do_fcst_splitting() {

*fcst_split = split(*fcst_mask, n_fcst);

mlog << Debug(4) << " After splitting of fcst field: "
<< fcst_split->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After splitting of fcst field: "
<< fcst_split->sdebug_examine() << "\n";
}

need_fcst_split = false;
need_fcst_merge = true;
Expand All @@ -835,8 +857,10 @@ void ModeFuzzyEngine::do_obs_splitting() {

*obs_split = split(*obs_mask, n_obs);

mlog << Debug(4) << " After splitting of obs field: "
<< obs_split->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After splitting of obs field: "
<< obs_split->sdebug_examine() << "\n";
}

need_obs_split = false;
need_obs_merge = true;
Expand Down Expand Up @@ -1544,8 +1568,10 @@ void ModeFuzzyEngine::do_fcst_merge_thresh(const ShapeData &merge_data) {

} // end for mid

mlog << Debug(4) << " After merging of fcst field: "
<< fcst_split->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After merging of fcst field: "
<< fcst_split->sdebug_examine() << "\n";
}

return;
}
Expand Down Expand Up @@ -1633,8 +1659,10 @@ void ModeFuzzyEngine::do_obs_merge_thresh(const ShapeData &merge_data) {

} // end for mid

mlog << Debug(4) << " After merging of obs field: "
<< obs_split->sdebug_examine() << "\n";
if(mlog.verbosity_level() >= 4) {
mlog << Debug(4) << " After merging of obs field: "
<< obs_split->sdebug_examine() << "\n";
}

return;
}
Expand Down

0 comments on commit 93f50ce

Please sign in to comment.