Skip to content

Commit

Permalink
fix: init XXX_total_duration_ms to 0ms
Browse files Browse the repository at this point in the history
  • Loading branch information
sileht authored and mergify[bot] committed Dec 3, 2020
1 parent efc49de commit 292d891
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/service_stats.h
Expand Up @@ -74,10 +74,12 @@ namespace dd
int _predict_failure = 0;

std::chrono::steady_clock::time_point _predict_tstart;
std::chrono::duration<double, std::milli> _predict_total_duration_ms;
std::chrono::duration<double, std::milli> _predict_total_duration_ms
= std::chrono::milliseconds(0);

std::chrono::steady_clock::time_point _transform_tstart;
std::chrono::duration<double, std::milli> _transform_total_duration_ms;
std::chrono::duration<double, std::milli> _transform_total_duration_ms
= std::chrono::milliseconds(0);

double _avg_batch_size = -1;
double _avg_predict_duration_ms = -1;
Expand Down
43 changes: 38 additions & 5 deletions tests/ut-jsonapi.cc
Expand Up @@ -186,11 +186,44 @@ TEST(jsonapi, service_status)

ASSERT_TRUE(jd["body"].HasMember("service_stats"));
ASSERT_TRUE(jd["body"]["service_stats"].HasMember("predict_count"));
ASSERT_TRUE(jd["body"]["service_stats"]["predict_count"].GetInt() == 0);
ASSERT_TRUE(jd["body"]["service_stats"]["inference_count"].GetInt() == 0);
ASSERT_TRUE(jd["body"]["service_stats"]["predict_failure"].GetInt() == 0);
ASSERT_TRUE(jd["body"]["service_stats"]["predict_success"].GetInt() == 0);
ASSERT_TRUE(jd["body"]["service_stats"]["avg_batch_size"].GetDouble() == -1);
ASSERT_EQ(jd["body"]["service_stats"]["predict_count"].GetInt(), 0);
ASSERT_EQ(jd["body"]["service_stats"]["inference_count"].GetInt(), 0);
ASSERT_EQ(jd["body"]["service_stats"]["predict_failure"].GetInt(), 0);
ASSERT_EQ(jd["body"]["service_stats"]["predict_success"].GetInt(), 0);
ASSERT_EQ(
jd["body"]["service_stats"]["avg_transform_duration_ms"].GetDouble(),
-1);
ASSERT_EQ(jd["body"]["service_stats"]["avg_predict_duration_ms"].GetDouble(),
-1);
ASSERT_EQ(jd["body"]["service_stats"]["avg_batch_size"].GetDouble(), -1);

std::string jpredictstr
= "{\"service\":\"" + sname
+ "\",\"parameters\":{\"input\":{\"bw\":true}},\"data\":[\""
+ "../examples/caffe/mnist/sample_digit.png\"]}";
japi.service_predict(jpredictstr);

jstatstr = japi.jrender(japi.service_status(sname));
// std::cout << "jstatstr=" << jstatstr << std::endl;
jd.Parse<rapidjson::kParseNanAndInfFlag>(jstatstr.c_str());
ASSERT_TRUE(!jd.HasParseError());
ASSERT_TRUE(jd.HasMember("status"));
ASSERT_EQ(200, jd["status"]["code"]);
ASSERT_EQ("OK", jd["status"]["msg"]);
ASSERT_TRUE(jd.HasMember("body"));
ASSERT_TRUE(jd["body"].HasMember("description"));

ASSERT_TRUE(jd["body"].HasMember("service_stats"));
ASSERT_TRUE(jd["body"]["service_stats"].HasMember("predict_count"));
ASSERT_EQ(jd["body"]["service_stats"]["predict_count"].GetInt(), 1);
ASSERT_EQ(jd["body"]["service_stats"]["inference_count"].GetInt(), 0);
ASSERT_EQ(jd["body"]["service_stats"]["predict_failure"].GetInt(), 1);
ASSERT_EQ(jd["body"]["service_stats"]["predict_success"].GetInt(), 0);
ASSERT_EQ(
jd["body"]["service_stats"]["avg_transform_duration_ms"].GetDouble(), 0);
ASSERT_GT(jd["body"]["service_stats"]["avg_predict_duration_ms"].GetDouble(),
0);
ASSERT_EQ(jd["body"]["service_stats"]["avg_batch_size"].GetDouble(), 0);
}

TEST(jsonapi, service_purge)
Expand Down

0 comments on commit 292d891

Please sign in to comment.