Skip to content

Commit ed2c237

Browse files
nv-hwoomc-nv
authored andcommitted
Add more metadata to profile export JSON file (#627)
* Add more metadata to profile export data * Fix minor bug * refactor
1 parent b9641d0 commit ed2c237

File tree

5 files changed

+158
-12
lines changed

5 files changed

+158
-12
lines changed

src/c++/perf_analyzer/mock_profile_data_exporter.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ class NaggyMockProfileDataExporter : public ProfileDataExporter {
3434
public:
3535
NaggyMockProfileDataExporter()
3636
{
37-
ON_CALL(*this, ConvertToJson(testing::_, testing::_))
37+
ON_CALL(
38+
*this, ConvertToJson(testing::_, testing::_, testing::_, testing::_))
3839
.WillByDefault(
3940
[this](
4041
const std::vector<Experiment>& raw_experiments,
41-
std::string& raw_version) -> void {
42+
std::string& raw_version, cb::BackendKind& service_kind,
43+
std::string& endpoint) -> void {
4244
return this->ProfileDataExporter::ConvertToJson(
43-
raw_experiments, raw_version);
45+
raw_experiments, raw_version, service_kind, endpoint);
4446
});
4547

4648
ON_CALL(*this, OutputToFile(testing::_))
@@ -56,15 +58,34 @@ class NaggyMockProfileDataExporter : public ProfileDataExporter {
5658
this->ProfileDataExporter::AddExperiment(
5759
entry, experiment, raw_experiment);
5860
});
61+
62+
ON_CALL(*this, AddServiceKind(testing::_))
63+
.WillByDefault([this](cb::BackendKind& service_kind) -> void {
64+
this->ProfileDataExporter::AddServiceKind(service_kind);
65+
});
66+
67+
ON_CALL(*this, AddEndpoint(testing::_))
68+
.WillByDefault([this](std::string& endpoint) -> void {
69+
this->ProfileDataExporter::AddEndpoint(endpoint);
70+
});
71+
72+
ON_CALL(*this, ClearDocument()).WillByDefault([this]() -> void {
73+
this->ProfileDataExporter::ClearDocument();
74+
});
5975
}
6076

6177
MOCK_METHOD(
62-
void, ConvertToJson, (const std::vector<Experiment>&, std::string&),
78+
void, ConvertToJson,
79+
(const std::vector<Experiment>&, std::string&, cb::BackendKind&,
80+
std::string&),
6381
(override));
6482
MOCK_METHOD(
6583
void, AddExperiment,
6684
(rapidjson::Value&, rapidjson::Value&, const Experiment&), (override));
6785
MOCK_METHOD(void, OutputToFile, (std::string&), (override));
86+
MOCK_METHOD(void, AddServiceKind, (cb::BackendKind&));
87+
MOCK_METHOD(void, AddEndpoint, (std::string&));
88+
MOCK_METHOD(void, ClearDocument, ());
6889

6990
rapidjson::Document& document_{ProfileDataExporter::document_};
7091
};

src/c++/perf_analyzer/perf_analyzer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ PerfAnalyzer::GenerateProfileExport()
452452
if (!params_->profile_export_file.empty()) {
453453
exporter_->Export(
454454
collector_->GetData(), collector_->GetVersion(),
455-
params_->profile_export_file);
455+
params_->profile_export_file, params_->kind, params_->endpoint);
456456
}
457457
}
458458

src/c++/perf_analyzer/profile_data_exporter.cc

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ ProfileDataExporter::Create(std::shared_ptr<ProfileDataExporter>* exporter)
4747
void
4848
ProfileDataExporter::Export(
4949
const std::vector<Experiment>& raw_experiments, std::string& raw_version,
50-
std::string& file_path)
50+
std::string& file_path, cb::BackendKind& service_kind,
51+
std::string& endpoint)
5152
{
52-
ConvertToJson(raw_experiments, raw_version);
53+
ConvertToJson(raw_experiments, raw_version, service_kind, endpoint);
5354
OutputToFile(file_path);
5455
}
5556

5657
void
5758
ProfileDataExporter::ConvertToJson(
58-
const std::vector<Experiment>& raw_experiments, std::string& raw_version)
59+
const std::vector<Experiment>& raw_experiments, std::string& raw_version,
60+
cb::BackendKind& service_kind, std::string& endpoint)
5961
{
6062
ClearDocument();
6163
rapidjson::Value experiments(rapidjson::kArrayType);
@@ -75,6 +77,8 @@ ProfileDataExporter::ConvertToJson(
7577

7678
document_.AddMember("experiments", experiments, document_.GetAllocator());
7779
AddVersion(raw_version);
80+
AddServiceKind(service_kind);
81+
AddEndpoint(endpoint);
7882
}
7983

8084
void
@@ -245,6 +249,39 @@ ProfileDataExporter::AddVersion(std::string& raw_version)
245249
document_.AddMember("version", version, document_.GetAllocator());
246250
}
247251

252+
void
253+
ProfileDataExporter::AddServiceKind(cb::BackendKind& kind)
254+
{
255+
std::string raw_service_kind{""};
256+
if (kind == cb::BackendKind::TRITON) {
257+
raw_service_kind = "triton";
258+
} else if (kind == cb::BackendKind::TENSORFLOW_SERVING) {
259+
raw_service_kind = "tfserving";
260+
} else if (kind == cb::BackendKind::TORCHSERVE) {
261+
raw_service_kind = "torchserve";
262+
} else if (kind == cb::BackendKind::TRITON_C_API) {
263+
raw_service_kind = "triton_c_api";
264+
} else if (kind == cb::BackendKind::OPENAI) {
265+
raw_service_kind = "openai";
266+
} else {
267+
std::cerr << "Unknown service kind detected. The 'service_kind' will not "
268+
"be specified."
269+
<< std::endl;
270+
}
271+
272+
rapidjson::Value service_kind;
273+
service_kind.SetString(raw_service_kind.c_str(), document_.GetAllocator());
274+
document_.AddMember("service_kind", service_kind, document_.GetAllocator());
275+
}
276+
277+
void
278+
ProfileDataExporter::AddEndpoint(std::string& raw_endpoint)
279+
{
280+
rapidjson::Value endpoint;
281+
endpoint = rapidjson::StringRef(raw_endpoint.c_str());
282+
document_.AddMember("endpoint", endpoint, document_.GetAllocator());
283+
}
284+
248285
void
249286
ProfileDataExporter::OutputToFile(std::string& file_path)
250287
{

src/c++/perf_analyzer/profile_data_exporter.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ class ProfileDataExporter {
4949
/// @param raw_version String containing the version number for the json
5050
/// output
5151
/// @param file_path File path to export profile data to.
52+
/// @param service_kind Service that Perf Analyzer generates load for.
53+
/// @param endpoint Endpoint to send the requests.
5254
void Export(
5355
const std::vector<Experiment>& raw_experiments, std::string& raw_version,
54-
std::string& file_path);
56+
std::string& file_path, cb::BackendKind& service_kind,
57+
std::string& endpoint);
5558

5659
private:
5760
ProfileDataExporter() = default;
@@ -60,8 +63,11 @@ class ProfileDataExporter {
6063
/// analyzer
6164
/// @param raw_version String containing the version number for the json
6265
/// output
66+
/// @param service_kind Service that Perf Analyzer generates load for.
67+
/// @param endpoint Endpoint to send the requests.
6368
virtual void ConvertToJson(
64-
const std::vector<Experiment>& raw_experiments, std::string& raw_version);
69+
const std::vector<Experiment>& raw_experiments, std::string& raw_version,
70+
cb::BackendKind& service_kind, std::string& endpoint);
6571
virtual void OutputToFile(std::string& file_path);
6672
virtual void AddExperiment(
6773
rapidjson::Value& entry, rapidjson::Value& experiment,
@@ -83,6 +89,8 @@ class ProfileDataExporter {
8389
rapidjson::Value& entry, rapidjson::Value& window_boundaries,
8490
const Experiment& raw_experiment);
8591
void AddVersion(std::string& raw_version);
92+
void AddServiceKind(cb::BackendKind& service_kind);
93+
void AddEndpoint(std::string& endpoint);
8694
void ClearDocument();
8795

8896
rapidjson::Document document_{};

src/c++/perf_analyzer/test_profile_data_exporter.cc

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ TEST_CASE("profile_data_exporter: ConvertToJson")
102102
std::vector<Experiment> experiments{experiment};
103103

104104
std::string version{"1.2.3"};
105+
cb::BackendKind service_kind = cb::BackendKind::TRITON;
106+
std::string endpoint{""};
105107

106-
exporter.ConvertToJson(experiments, version);
108+
exporter.ConvertToJson(experiments, version, service_kind, endpoint);
107109

108110
std::string json{R"(
109111
{
@@ -125,7 +127,9 @@ TEST_CASE("profile_data_exporter: ConvertToJson")
125127
"window_boundaries" : [ 1, 5, 6 ]
126128
}
127129
],
128-
"version" : "1.2.3"
130+
"version" : "1.2.3",
131+
"service_kind": "triton",
132+
"endpoint": ""
129133
}
130134
)"};
131135

@@ -244,4 +248,80 @@ TEST_CASE("profile_data_exporter: OutputToFile")
244248
}
245249
}
246250

251+
TEST_CASE("profile_data_exporter: AddServiceKind")
252+
{
253+
MockProfileDataExporter exporter{};
254+
exporter.ClearDocument();
255+
256+
cb::BackendKind service_kind;
257+
std::string json{""};
258+
259+
SUBCASE("Backend kind: TRITON")
260+
{
261+
service_kind = cb::BackendKind::TRITON;
262+
json = R"({ "service_kind": "triton" })";
263+
}
264+
265+
SUBCASE("Backend kind: TENSORFLOW_SERVING")
266+
{
267+
service_kind = cb::BackendKind::TENSORFLOW_SERVING;
268+
json = R"({ "service_kind": "tfserving" })";
269+
}
270+
271+
SUBCASE("Backend kind: TORCHSERVE")
272+
{
273+
service_kind = cb::BackendKind::TORCHSERVE;
274+
json = R"({ "service_kind": "torchserve" })";
275+
}
276+
277+
SUBCASE("Backend kind: TRITON_C_API")
278+
{
279+
service_kind = cb::BackendKind::TRITON_C_API;
280+
json = R"({ "service_kind": "triton_c_api" })";
281+
}
282+
283+
SUBCASE("Backend kind: OPENAI")
284+
{
285+
service_kind = cb::BackendKind::OPENAI;
286+
json = R"({ "service_kind": "openai" })";
287+
}
288+
289+
exporter.AddServiceKind(service_kind);
290+
rapidjson::Document expected_document;
291+
expected_document.Parse(json.c_str());
292+
293+
const rapidjson::Value& expected_kind{expected_document["service_kind"]};
294+
const rapidjson::Value& actual_kind{exporter.document_["service_kind"]};
295+
CHECK(actual_kind == expected_kind);
296+
}
297+
298+
TEST_CASE("profile_data_exporter: AddEndpoint")
299+
{
300+
MockProfileDataExporter exporter{};
301+
exporter.ClearDocument();
302+
303+
std::string endpoint{""};
304+
std::string json{""};
305+
306+
SUBCASE("Endpoint: OpenAI Chat Completions")
307+
{
308+
endpoint = "v1/chat/completions";
309+
json = R"({ "endpoint": "v1/chat/completions" })";
310+
}
311+
312+
SUBCASE("Endpoint: OpenAI Completions")
313+
{
314+
endpoint = "v1/completions";
315+
json = R"({ "endpoint": "v1/completions" })";
316+
}
317+
318+
exporter.AddEndpoint(endpoint);
319+
rapidjson::Document expected_document;
320+
expected_document.Parse(json.c_str());
321+
322+
const rapidjson::Value& expected_endpoint{expected_document["endpoint"]};
323+
const rapidjson::Value& actual_endpoint{exporter.document_["endpoint"]};
324+
CHECK(actual_endpoint == expected_endpoint);
325+
}
326+
247327
}} // namespace triton::perfanalyzer

0 commit comments

Comments
 (0)