Skip to content

Commit 299eac8

Browse files
authored
dynamic tracing compiler refactor for json output support (#278)
* dtrace refactor for json output support Signed-off-by: advanaik <AdvaitHemant.Naik@amd.com> * address copilot comments Signed-off-by: advanaik <AdvaitHemant.Naik@amd.com> * optimize action serialize Signed-off-by: advanaik <AdvaitHemant.Naik@amd.com> --------- Signed-off-by: advanaik <AdvaitHemant.Naik@amd.com>
1 parent bcadd38 commit 299eac8

29 files changed

Lines changed: 1240 additions & 582 deletions

src/cpp/dtrace/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ set_target_properties(dtrace_library_objects PROPERTIES
4646
POSITION_INDEPENDENT_CODE ON
4747
)
4848

49-
add_library(cert_dtrace SHARED
50-
$<TARGET_OBJECTS:dtrace_library_objects>
51-
)
52-
5349
add_library(cert_dtrace_static STATIC
5450
$<TARGET_OBJECTS:dtrace_library_objects>
5551
)
@@ -60,8 +56,8 @@ if (NOT WIN32)
6056
set_target_properties(cert_dtrace_static PROPERTIES OUTPUT_NAME "cert_dtrace")
6157
endif()
6258

63-
# As long as we support static linking of targets that depend on static cert,
64-
# the cert static library must be released.
59+
# As long as we support static linking of targets that depend on static cert dtrace,
60+
# the cert dtrace static library must be released.
6561
install(TARGETS cert_dtrace_static
6662
EXPORT aiebu-targets
6763
ARCHIVE DESTINATION ${AIEBU_INSTALL_LIB_DIR} COMPONENT ${AIEBU_DEV_COMPONENT}

src/cpp/dtrace/action/action_control.h

Lines changed: 181 additions & 46 deletions
Large diffs are not rendered by default.

src/cpp/dtrace/action/break.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,29 @@ actionize(uint32_t last, std::vector<uint32_t>& control_buffer, std::vector<uint
5050
* @param result_buffer
5151
* @param mem_buffer
5252
* @param mapping
53+
* @param script_output
54+
*/
55+
void
56+
break_action::
57+
serialize(std::vector<uint32_t>&, std::vector<uint32_t>&,
58+
const std::unordered_map<uint32_t, uint32_t>&, std::ostream&) const
59+
{
60+
}
61+
62+
//-------------------------break_action::serialize-------------------------//
63+
/**
64+
* serialize() - Serializes the break action into json format.
5365
*
54-
* @return
55-
* String representing the serialized break action.
66+
* @param result_buffer
67+
* @param mem_buffer
68+
* @param mapping
69+
* @param json_output
5670
*/
57-
std::string
71+
void
5872
break_action::
5973
serialize(std::vector<uint32_t>&, std::vector<uint32_t>&,
60-
const std::unordered_map<uint32_t, uint32_t>&) const
74+
const std::unordered_map<uint32_t, uint32_t>&, json&) const
6175
{
62-
std::ostringstream output_action;
63-
output_action << "#" << " " << m_token << "\n";
64-
return output_action.str();
6576
}
6677

6778
} // namespace dtrace::action

src/cpp/dtrace/action/count.cpp

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ count_action(std::string token, uint32_t probe_type, const std::string& probe_na
2626
std::stringstream token_stream(token);
2727
std::string item;
2828
while (std::getline(token_stream, item, '='))
29-
fields.push_back(strip(item));
29+
fields.push_back(action::strip(item));
3030

3131
if (fields.size() != 2)
3232
DTRACE_ERROR("DTRACE_ACTION_INVALID_TOKEN",
@@ -65,28 +65,65 @@ actionize(uint32_t last, std::vector<uint32_t>& control_buffer, std::vector<uint
6565
control_buffer.push_back(dtrace::dtrace_ctrl::result_value_init);
6666
}
6767

68-
//-------------------------count_action::serialize-------------------------//
68+
//-------------------------count_action::serialize_helper-------------------------//
6969
/**
70-
* serialize() - Serializes the count action into a string format.
70+
* serialize_helper() - Helper function to serialize action.
7171
*
7272
* @param result_buffer
73-
* @param mem_buffer
7473
* @param mapping
7574
*
7675
* @return
77-
* String representing the serialized count action.
76+
* The value from the result buffer based on the location mapping and
77+
* resets the value in the result buffer after serialization.
7878
*/
79-
std::string
79+
uint32_t
8080
count_action::
81-
serialize(std::vector<uint32_t>& result_buffer, std::vector<uint32_t>&,
81+
serialize_helper(std::vector<uint32_t>& result_buffer,
8282
const std::unordered_map<uint32_t, uint32_t>& mapping) const
8383
{
84-
std::ostringstream output_action;
8584
uint32_t location = mapping.at(get_location(false));
86-
output_action << " " << m_result << " = " << result_buffer[location] << "\n";
85+
uint32_t result = result_buffer[location] - dtrace::dtrace_ctrl::result_value_init;
8786
// reset value after serialization
88-
result_buffer[location] = 0;
89-
return output_action.str();
87+
result_buffer[location] = dtrace::dtrace_ctrl::result_value_init;
88+
return result;
89+
}
90+
91+
//-------------------------count_action::serialize-------------------------//
92+
/**
93+
* serialize() - Serializes the count action into a string format.
94+
*
95+
* @param result_buffer
96+
* @param mem_buffer
97+
* @param mapping
98+
* @param script_output
99+
*/
100+
void
101+
count_action::
102+
serialize(std::vector<uint32_t>& result_buffer, std::vector<uint32_t>&,
103+
const std::unordered_map<uint32_t, uint32_t>& mapping, std::ostream& script_output) const
104+
{
105+
uint32_t result = count_action::serialize_helper(result_buffer, mapping);
106+
// serialize string format
107+
script_output << " " << m_result << " = " << result << "\n";
108+
}
109+
110+
//-------------------------count_action::serialize-------------------------//
111+
/**
112+
* serialize() - Serializes the count action into json format.
113+
*
114+
* @param result_buffer
115+
* @param mem_buffer
116+
* @param mapping
117+
* @param json_output
118+
*/
119+
void
120+
count_action::
121+
serialize(std::vector<uint32_t>& result_buffer, std::vector<uint32_t>&,
122+
const std::unordered_map<uint32_t, uint32_t>& mapping, json& json_output) const
123+
{
124+
uint32_t result = count_action::serialize_helper(result_buffer, mapping);
125+
// serialize json format
126+
json_output[m_probe_name][m_result] = result;
90127
}
91128

92129
} // namespace dtrace::action

src/cpp/dtrace/action/host_timestamp.cpp

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ host_timestamp_action(std::string token, uint32_t probe_type, const std::string&
2626
std::stringstream token_stream(token);
2727
std::string item;
2828
while (std::getline(token_stream, item, '='))
29-
fields.push_back(strip(item));
29+
fields.push_back(action::strip(item));
3030

3131
if (fields.size() != 2)
3232
DTRACE_ERROR("DTRACE_ACTION_INVALID_TOKEN",
@@ -67,33 +67,69 @@ actionize(uint32_t last, std::vector<uint32_t>& control_buffer, std::vector<uint
6767
control_buffer.push_back(dtrace::dtrace_ctrl::result_value_init);
6868
}
6969

70-
//-------------------------host_timestamp_action::serialize-------------------------//
70+
//-------------------------host_timestamp_action::serialize_helper-------------------------//
7171
/**
72-
* serialize() - Serializes the timestamp action into a string format.
72+
* serialize_helper() - Helper function to serialize action.
7373
*
7474
* @param result_buffer
75-
* @param mem_buffer
7675
* @param mapping
7776
*
7877
* @return
79-
* String representing the serialized timestamp action.
78+
* The value from the result buffer based on the location mapping and
79+
* resets the value in the result buffer after serialization.
8080
*/
81-
std::string
81+
uint64_t
8282
host_timestamp_action::
83-
serialize(std::vector<uint32_t>& result_buffer, std::vector<uint32_t>&,
83+
serialize_helper(std::vector<uint32_t>& result_buffer,
8484
const std::unordered_map<uint32_t, uint32_t>& mapping) const
8585
{
86-
std::ostringstream output_action;
8786
uint32_t location_h = mapping.at(get_location(false));
8887
uint32_t location_l = mapping.at(get_location(false) + 1);
8988
uint64_t high =
9089
static_cast<uint64_t>(result_buffer[location_h]) << dtrace::dtrace_ctrl::forth_byte_shift;
9190
uint64_t low = result_buffer[location_l];
92-
output_action << " " << m_result << " = " << (high + low) << "\n";
9391
// reset value after serialization
94-
result_buffer[location_h] = 0;
95-
result_buffer[location_l] = 0;
96-
return output_action.str();
92+
result_buffer[location_h] = dtrace::dtrace_ctrl::result_value_init;
93+
result_buffer[location_l] = dtrace::dtrace_ctrl::result_value_init;
94+
return (high + low);
95+
}
96+
97+
//-------------------------host_timestamp_action::serialize-------------------------//
98+
/**
99+
* serialize() - Serializes the timestamp action into a string format.
100+
*
101+
* @param result_buffer
102+
* @param mem_buffer
103+
* @param mapping
104+
* @param script_output
105+
*/
106+
void
107+
host_timestamp_action::
108+
serialize(std::vector<uint32_t>& result_buffer, std::vector<uint32_t>&,
109+
const std::unordered_map<uint32_t, uint32_t>& mapping, std::ostream& script_output) const
110+
{
111+
uint64_t result = host_timestamp_action::serialize_helper(result_buffer, mapping);
112+
// serialize string format
113+
script_output << " " << m_result << " = " << result << "\n";
114+
}
115+
116+
//-------------------------host_timestamp_action::serialize-------------------------//
117+
/**
118+
* serialize() - Serializes the timestamp action into json format.
119+
*
120+
* @param result_buffer
121+
* @param mem_buffer
122+
* @param mapping
123+
* @param json_output
124+
*/
125+
void
126+
host_timestamp_action::
127+
serialize(std::vector<uint32_t>& result_buffer, std::vector<uint32_t>&,
128+
const std::unordered_map<uint32_t, uint32_t>& mapping, json& json_output) const
129+
{
130+
uint64_t result = host_timestamp_action::serialize_helper(result_buffer, mapping);
131+
// serialize json format
132+
json_output[m_probe_name][m_result] = result;
97133
}
98134

99135
} // namespace dtrace::action

src/cpp/dtrace/action/host_timestamps.cpp

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ host_timestamps_action(std::string token, uint32_t probe_type, const std::string
2626
std::stringstream token_stream(token);
2727
std::string item;
2828
while (std::getline(token_stream, item, '='))
29-
fields.push_back(strip(item));
29+
fields.push_back(action::strip(item));
3030

3131
if (fields.size() != 2)
3232
DTRACE_ERROR("DTRACE_ACTION_INVALID_TOKEN",
@@ -81,45 +81,84 @@ actionize(uint32_t last, std::vector<uint32_t>& control_buffer, std::vector<uint
8181
}
8282
}
8383

84-
//-------------------------host_timestamps_action::serialize-------------------------//
84+
//-------------------------host_timestamps_action::serialize_helper-------------------------//
8585
/**
86-
* serialize() - Serializes the timestamp action into a string format.
86+
* serialize_helper() - Helper function to serialize action.
8787
*
8888
* @param result_buffer
89-
* @param mem_buffer
9089
* @param mapping
9190
*
9291
* @return
93-
* String representing the serialized timestamp action.
92+
* The value from the result buffer based on the location mapping and
93+
* resets the value in the result buffer after serialization.
9494
*/
95-
std::string
95+
std::vector<uint64_t>
9696
host_timestamps_action::
97-
serialize(std::vector<uint32_t>& result_buffer, std::vector<uint32_t>&,
97+
serialize_helper(std::vector<uint32_t>& result_buffer,
9898
const std::unordered_map<uint32_t, uint32_t>& mapping) const
9999
{
100-
101100
std::vector<uint64_t> result;
102-
for (uint32_t i = 0; i < m_length; ++i) {
101+
for (uint32_t i = 0; i < m_length; ++i)
102+
{
103103
// action location + length word + high and low value
104104
uint32_t location = mapping.at(get_location(false)) + 1 + i*2;
105105
uint64_t high = static_cast<uint64_t>(result_buffer[location]) << dtrace::dtrace_ctrl::forth_byte_shift;
106106
uint64_t low = result_buffer[location + 1];
107107
result.push_back(high + low);
108108
// reset value after serialization
109-
result_buffer[location] = 0;
110-
result_buffer[location + 1] = 0;
109+
result_buffer[location] = dtrace::dtrace_ctrl::result_value_init;
110+
result_buffer[location + 1] = dtrace::dtrace_ctrl::result_value_init;
111111
}
112+
return result;
113+
}
112114

113-
std::ostringstream output_action;
114-
output_action << " " << m_result << " = [";
115-
for (size_t i = 0; i < result.size(); ++i) {
116-
output_action << result[i];
115+
//-------------------------host_timestamps_action::serialize-------------------------//
116+
/**
117+
* serialize() - Serializes the timestamp action into a string format.
118+
*
119+
* @param result_buffer
120+
* @param mem_buffer
121+
* @param mapping
122+
* @param script_output
123+
*/
124+
void
125+
host_timestamps_action::
126+
serialize(std::vector<uint32_t>& result_buffer, std::vector<uint32_t>&,
127+
const std::unordered_map<uint32_t, uint32_t>& mapping, std::ostream& script_output) const
128+
{
129+
std::vector<uint64_t> result = host_timestamps_action::serialize_helper(result_buffer, mapping);
130+
// serialize string format
131+
script_output << " " << m_result << " = [";
132+
for (size_t i = 0; i < result.size(); ++i)
133+
{
134+
script_output << result[i];
117135
if (i != result.size() - 1)
118-
output_action << ", ";
136+
script_output << ", ";
119137
}
120-
output_action << "]\n";
121-
122-
return output_action.str();
138+
script_output << "]\n";
139+
}
140+
141+
//-------------------------host_timestamps_action::serialize-------------------------//
142+
/**
143+
* serialize() - Serializes the timestamp action into json format.
144+
*
145+
* @param result_buffer
146+
* @param mem_buffer
147+
* @param mapping
148+
* @param json_output
149+
*/
150+
void
151+
host_timestamps_action::
152+
serialize(std::vector<uint32_t>& result_buffer, std::vector<uint32_t>&,
153+
const std::unordered_map<uint32_t, uint32_t>& mapping, json& json_output) const
154+
{
155+
std::vector<uint64_t> result = host_timestamps_action::serialize_helper(result_buffer, mapping);
156+
// serialize json format
157+
json json_result = json::array();
158+
for (uint32_t i = 0; i < result.size(); ++i)
159+
json_result.push_back(result[i]);
160+
161+
json_output[m_probe_name][m_result] = json_result;
123162
}
124163

125164
} // namespace dtrace::action

0 commit comments

Comments
 (0)