!11920 Refactor code under engine/cache/perf to pass lizard check

From: @lixiachen
Reviewed-by: @liucunwei,@pandoublefeng
Signed-off-by: @liucunwei
pull/11920/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit e258315885

File diff suppressed because it is too large Load Diff

@ -93,6 +93,10 @@ class CachePerfRun {
Status GetSession();
Status ListenToPipeline(int32_t workerId);
void PrintEpochSummary() const;
Status StartPipelines();
Status Cleanup();
int32_t SanityCheck(std::map<int32_t, int32_t> seen_opts);
int32_t ProcessArgsHelper(int32_t opt);
};
} // namespace dataset
} // namespace mindspore

@ -31,14 +31,9 @@ namespace mindspore {
namespace dataset {
void CachePipelineRun::PrintHelp() { std::cout << "Please run the executable cache_perf instead." << std::endl; }
int32_t CachePipelineRun::ProcessArgs(int argc, char **argv) {
if (argc != 3) {
PrintHelp();
return -1;
}
int32_t CachePipelineRun::ProcessPipelineArgs(char *argv) {
try {
std::stringstream cfg_ss(argv[1]);
std::stringstream cfg_ss(argv);
std::string s;
int32_t numArgs = 0;
while (std::getline(cfg_ss, s, ',')) {
@ -72,8 +67,18 @@ int32_t CachePipelineRun::ProcessArgs(int argc, char **argv) {
std::cerr << "Incomplete arguments. Expect 11. But get " << numArgs << std::endl;
return -1;
}
std::stringstream client_ss(argv[2]);
numArgs = 0;
} catch (const std::exception &e) {
std::cerr << "Parse error: " << e.what() << std::endl;
return -1;
}
return 0;
}
int32_t CachePipelineRun::ProcessClientArgs(char *argv) {
try {
std::stringstream client_ss(argv);
std::string s;
int32_t numArgs = 0;
while (std::getline(client_ss, s, ',')) {
if (numArgs == 0) {
cache_builder_.SetHostname(s);
@ -101,6 +106,17 @@ int32_t CachePipelineRun::ProcessArgs(int argc, char **argv) {
return 0;
}
int32_t CachePipelineRun::ProcessArgs(int argc, char **argv) {
if (argc != 3) {
PrintHelp();
return -1;
}
int32_t rc = ProcessPipelineArgs(argv[1]);
if (rc < 0) return rc;
rc = ProcessClientArgs(argv[2]);
return rc;
}
CachePipelineRun::CachePipelineRun()
: my_pipeline_(-1),
num_pipelines_(kDftNumOfPipelines),
@ -282,7 +298,7 @@ Status CachePipelineRun::WriterWorkerEntry(int32_t worker_id) {
std::shared_ptr<Tensor> element;
RETURN_IF_NOT_OK(Tensor::CreateEmpty(shape, col_desc->type(), &element));
row.setId(id);
// CreateEmpty allocates the memory but in virutal address. Let's commit the memory
// CreateEmpty allocates the memory but in virtual address. Let's commit the memory
// so we can get an accurate timing.
auto it = element->begin<int64_t>();
for (auto i = 0; i < num_elements; ++i, ++it) {

@ -52,6 +52,8 @@ class CachePipelineRun {
~CachePipelineRun();
static void PrintHelp();
int32_t ProcessArgs(int argc, char **argv);
int32_t ProcessPipelineArgs(char *argv);
int32_t ProcessClientArgs(char *argv);
void Print(std::ostream &out) const {
out << "Number of pipelines: " << num_pipelines_ << "\n"

Loading…
Cancel
Save