Skip to content

Commit

Permalink
[ML] Soft column limit of 80 for clang-format (#50)
Browse files Browse the repository at this point in the history
Adjusted clang-format configuration to use a soft column limit of 80.

This seems preferable on the whole to having a higher hard column-limit
as it results in code that is easier to read (in particular it makes
mathematical expressions easier to visually parse)

Standardising on clang-format 5.0 to avoid a bug in version 6.0 where
the PenaltyBreakString directive appears to be ignored
  • Loading branch information
edsavage committed Apr 12, 2018
1 parent 47a47bb commit 78e15c4
Show file tree
Hide file tree
Showing 758 changed files with 38,677 additions and 26,009 deletions.
21 changes: 10 additions & 11 deletions .clang-format
Expand Up @@ -4,21 +4,20 @@ AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: InlineOnly
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 140
ConstructorInitializerAllOnOneLineOrOnePerLine: true
FixNamespaceComments: false
IndentCaseLabels: false
IndentWidth: 4
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 4
TabWidth: 4
BinPackParameters: false
PenaltyBreakAssignment: 20
PenaltyBreakBeforeFirstCallParameter: 15
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 2
PenaltyBreakString: 1000000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyBreakFirstLessLess: 1
PenaltyBreakString: 30
PenaltyExcessCharacter: 1
PenaltyReturnTypeOnItsOwnLine: 30
PointerAlignment: Left
TabWidth: 4
SpaceAfterTemplateKeyword: false
ReflowComments: false
SortIncludes: true
BreakStringLiterals: false
3 changes: 2 additions & 1 deletion bin/autoconfig/CCmdLineParser.cc
Expand Up @@ -66,7 +66,8 @@ bool CCmdLineParser::parse(int argc,
// clang-format on

boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::store(
boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);

if (vm.count("help") > 0) {
Expand Down
25 changes: 7 additions & 18 deletions bin/autoconfig/Main.cc
Expand Up @@ -52,27 +52,17 @@ int main(int argc, char** argv) {
bool isOutputFileNamedPipe(false);
bool verbose(false);
bool writeDetectorConfigs(false);
if (ml::autoconfig::CCmdLineParser::parse(argc,
argv,
logProperties,
logPipe,
delimiter,
lengthEncodedInput,
timeField,
timeFormat,
configFile,
inputFileName,
isInputFileNamedPipe,
outputFileName,
isOutputFileNamedPipe,
verbose,
writeDetectorConfigs) == false) {
if (ml::autoconfig::CCmdLineParser::parse(
argc, argv, logProperties, logPipe, delimiter, lengthEncodedInput, timeField,
timeFormat, configFile, inputFileName, isInputFileNamedPipe, outputFileName,
isOutputFileNamedPipe, verbose, writeDetectorConfigs) == false) {
return EXIT_FAILURE;
}

// Construct the IO manager before reconfiguring the logger, as it performs
// std::ios actions that only work before first use
ml::api::CIoManager ioMgr(inputFileName, isInputFileNamedPipe, outputFileName, isOutputFileNamedPipe);
ml::api::CIoManager ioMgr(inputFileName, isInputFileNamedPipe,
outputFileName, isOutputFileNamedPipe);

if (ml::core::CLogger::instance().reconfigure(logPipe, logProperties) == false) {
LOG_FATAL(<< "Could not reconfigure logging");
Expand Down Expand Up @@ -112,8 +102,7 @@ int main(int argc, char** argv) {
// The skeleton avoids the need to duplicate a lot of boilerplate code
ml::api::CCmdSkeleton skeleton(nullptr, // no restoration at present
nullptr, // no persistence at present
*inputParser,
configurer);
*inputParser, configurer);
if (skeleton.ioLoop() == false) {
LOG_FATAL(<< "Ml autoconfig failed");
return EXIT_FAILURE;
Expand Down
15 changes: 11 additions & 4 deletions bin/autodetect/CCmdLineParser.cc
Expand Up @@ -126,16 +126,21 @@ bool CCmdLineParser::parse(int argc,

boost::program_options::variables_map vm;
boost::program_options::parsed_options parsed =
boost::program_options::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
boost::program_options::command_line_parser(argc, argv)
.options(desc)
.allow_unregistered()
.run();
boost::program_options::store(parsed, vm);

if (vm.count("help") > 0) {
std::cerr << desc << std::endl;
return false;
}
if (vm.count("version") > 0) {
std::cerr << "Model State Version " << model::CAnomalyDetector::STATE_VERSION << std::endl
<< "Quantile State Version " << model::CAnomalyScore::CURRENT_FORMAT_VERSION << std::endl
std::cerr << "Model State Version "
<< model::CAnomalyDetector::STATE_VERSION << std::endl
<< "Quantile State Version "
<< model::CAnomalyScore::CURRENT_FORMAT_VERSION << std::endl
<< ver::CBuildInfo::fullInfo() << std::endl;
return false;
}
Expand Down Expand Up @@ -236,7 +241,9 @@ bool CCmdLineParser::parse(int argc,
perPartitionNormalization = true;
}

boost::program_options::collect_unrecognized(parsed.options, boost::program_options::include_positional).swap(clauseTokens);
boost::program_options::collect_unrecognized(
parsed.options, boost::program_options::include_positional)
.swap(clauseTokens);
} catch (std::exception& e) {
std::cerr << "Error processing command line: " << e.what() << std::endl;
return false;
Expand Down
109 changes: 42 additions & 67 deletions bin/autodetect/Main.cc
Expand Up @@ -90,54 +90,24 @@ int main(int argc, char** argv) {
std::string multipleBucketspans;
bool perPartitionNormalization(false);
TStrVec clauseTokens;
if (ml::autodetect::CCmdLineParser::parse(argc,
argv,
limitConfigFile,
modelConfigFile,
fieldConfigFile,
modelPlotConfigFile,
jobId,
logProperties,
logPipe,
bucketSpan,
latency,
summaryCountFieldName,
delimiter,
lengthEncodedInput,
timeField,
timeFormat,
quantilesStateFile,
deleteStateFiles,
persistInterval,
maxQuantileInterval,
inputFileName,
isInputFileNamedPipe,
outputFileName,
isOutputFileNamedPipe,
restoreFileName,
isRestoreFileNamedPipe,
persistFileName,
isPersistFileNamedPipe,
maxAnomalyRecords,
memoryUsage,
bucketResultsDelay,
multivariateByFields,
multipleBucketspans,
perPartitionNormalization,
clauseTokens) == false) {
if (ml::autodetect::CCmdLineParser::parse(
argc, argv, limitConfigFile, modelConfigFile, fieldConfigFile,
modelPlotConfigFile, jobId, logProperties, logPipe, bucketSpan, latency,
summaryCountFieldName, delimiter, lengthEncodedInput, timeField,
timeFormat, quantilesStateFile, deleteStateFiles, persistInterval,
maxQuantileInterval, inputFileName, isInputFileNamedPipe, outputFileName,
isOutputFileNamedPipe, restoreFileName, isRestoreFileNamedPipe,
persistFileName, isPersistFileNamedPipe, maxAnomalyRecords, memoryUsage,
bucketResultsDelay, multivariateByFields, multipleBucketspans,
perPartitionNormalization, clauseTokens) == false) {
return EXIT_FAILURE;
}

// Construct the IO manager before reconfiguring the logger, as it performs
// std::ios actions that only work before first use
ml::api::CIoManager ioMgr(inputFileName,
isInputFileNamedPipe,
outputFileName,
isOutputFileNamedPipe,
restoreFileName,
isRestoreFileNamedPipe,
persistFileName,
isPersistFileNamedPipe);
ml::api::CIoManager ioMgr(inputFileName, isInputFileNamedPipe, outputFileName,
isOutputFileNamedPipe, restoreFileName, isRestoreFileNamedPipe,
persistFileName, isPersistFileNamedPipe);

if (ml::core::CLogger::instance().reconfigure(logPipe, logProperties) == false) {
LOG_FATAL(<< "Could not reconfigure logging");
Expand Down Expand Up @@ -169,20 +139,27 @@ int main(int argc, char** argv) {

ml::api::CFieldConfig fieldConfig;

ml::model_t::ESummaryMode summaryMode(summaryCountFieldName.empty() ? ml::model_t::E_None : ml::model_t::E_Manual);
ml::model::CAnomalyDetectorModelConfig modelConfig = ml::model::CAnomalyDetectorModelConfig::defaultConfig(
bucketSpan, summaryMode, summaryCountFieldName, latency, bucketResultsDelay, multivariateByFields, multipleBucketspans);
ml::model_t::ESummaryMode summaryMode(
summaryCountFieldName.empty() ? ml::model_t::E_None : ml::model_t::E_Manual);
ml::model::CAnomalyDetectorModelConfig modelConfig =
ml::model::CAnomalyDetectorModelConfig::defaultConfig(
bucketSpan, summaryMode, summaryCountFieldName, latency,
bucketResultsDelay, multivariateByFields, multipleBucketspans);
modelConfig.perPartitionNormalization(perPartitionNormalization);
modelConfig.detectionRules(ml::model::CAnomalyDetectorModelConfig::TIntDetectionRuleVecUMapCRef(fieldConfig.detectionRules()));
modelConfig.scheduledEvents(ml::model::CAnomalyDetectorModelConfig::TStrDetectionRulePrVecCRef(fieldConfig.scheduledEvents()));
modelConfig.detectionRules(ml::model::CAnomalyDetectorModelConfig::TIntDetectionRuleVecUMapCRef(
fieldConfig.detectionRules()));
modelConfig.scheduledEvents(ml::model::CAnomalyDetectorModelConfig::TStrDetectionRulePrVecCRef(
fieldConfig.scheduledEvents()));

if (!modelConfigFile.empty() && modelConfig.init(modelConfigFile) == false) {
LOG_FATAL(<< "Ml model config file '" << modelConfigFile << "' could not be loaded");
return EXIT_FAILURE;
}

if (!modelPlotConfigFile.empty() && modelConfig.configureModelPlot(modelPlotConfigFile) == false) {
LOG_FATAL(<< "Ml model plot config file '" << modelPlotConfigFile << "' could not be loaded");
if (!modelPlotConfigFile.empty() &&
modelConfig.configureModelPlot(modelPlotConfigFile) == false) {
LOG_FATAL(<< "Ml model plot config file '" << modelPlotConfigFile
<< "' could not be loaded");
return EXIT_FAILURE;
}

Expand Down Expand Up @@ -212,8 +189,10 @@ int main(int argc, char** argv) {
TScopedBackgroundPersisterP periodicPersister;
if (persistInterval >= 0) {
if (persister == nullptr) {
LOG_FATAL(<< "Periodic persistence cannot be enabled using the 'persistInterval' argument "
"unless a place to persist to has been specified using the 'persist' argument");
LOG_FATAL(<< "Periodic persistence cannot be enabled using the "
"'persistInterval' argument "
"unless a place to persist to has been specified "
"using the 'persist' argument");
return EXIT_FAILURE;
}

Expand All @@ -237,17 +216,11 @@ int main(int argc, char** argv) {
}

// The anomaly job knows how to detect anomalies
ml::api::CAnomalyJob job(jobId,
limits,
fieldConfig,
modelConfig,
wrappedOutputStream,
boost::bind(&ml::api::CModelSnapshotJsonWriter::write, &modelSnapshotWriter, _1),
periodicPersister.get(),
maxQuantileInterval,
timeField,
timeFormat,
maxAnomalyRecords);
ml::api::CAnomalyJob job(jobId, limits, fieldConfig, modelConfig, wrappedOutputStream,
boost::bind(&ml::api::CModelSnapshotJsonWriter::write,
&modelSnapshotWriter, _1),
periodicPersister.get(), maxQuantileInterval,
timeField, timeFormat, maxAnomalyRecords);

if (!quantilesStateFile.empty()) {
if (job.initNormalizer(quantilesStateFile) == false) {
Expand All @@ -267,20 +240,22 @@ int main(int argc, char** argv) {
ml::api::CJsonOutputWriter fieldDataTyperOutputWriter(jobId, wrappedOutputStream);

// The typer knows how to assign categories to records
ml::api::CFieldDataTyper typer(jobId, fieldConfig, limits, outputChainer, fieldDataTyperOutputWriter);
ml::api::CFieldDataTyper typer(jobId, fieldConfig, limits, outputChainer,
fieldDataTyperOutputWriter);

if (fieldConfig.fieldNameSuperset().count(ml::api::CFieldDataTyper::MLCATEGORY_NAME) > 0) {
LOG_DEBUG(<< "Applying the categorization typer for anomaly detection");
firstProcessor = &typer;
}

if (periodicPersister != nullptr) {
periodicPersister->firstProcessorPeriodicPersistFunc(
boost::bind(&ml::api::CDataProcessor::periodicPersistState, firstProcessor, _1));
periodicPersister->firstProcessorPeriodicPersistFunc(boost::bind(
&ml::api::CDataProcessor::periodicPersistState, firstProcessor, _1));
}

// The skeleton avoids the need to duplicate a lot of boilerplate code
ml::api::CCmdSkeleton skeleton(restoreSearcher.get(), persister.get(), *inputParser, *firstProcessor);
ml::api::CCmdSkeleton skeleton(restoreSearcher.get(), persister.get(),
*inputParser, *firstProcessor);
bool ioLoopSucceeded(skeleton.ioLoop());

// Unfortunately we cannot rely on destruction to finalise the output writer
Expand Down
3 changes: 2 additions & 1 deletion bin/categorize/CCmdLineParser.cc
Expand Up @@ -73,7 +73,8 @@ bool CCmdLineParser::parse(int argc,
// clang-format on

boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::store(
boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);

if (vm.count("help") > 0) {
Expand Down

0 comments on commit 78e15c4

Please sign in to comment.