Updating ATRACE_ASYNC_FOR_TRACK_END to not require a name argument
Bug: 230399626 Test: atest TraceDevTest Change-Id: Ia1b39f55c96011a9672f4d5c8763044f849d0bb2
This commit is contained in:
parent
a85c719661
commit
6507f8adc3
5 changed files with 36 additions and 96 deletions
|
@ -214,6 +214,7 @@ static inline void atrace_async_end(uint64_t tag, const char* name, int32_t cook
|
|||
* provided, which is the name of the row where this async event should be
|
||||
* recorded. The track name, name, and cookie used to begin an event must be
|
||||
* used to end it.
|
||||
* The cookie here must be unique on the track_name level, not the name level.
|
||||
*/
|
||||
#define ATRACE_ASYNC_FOR_TRACK_BEGIN(track_name, name, cookie) \
|
||||
atrace_async_for_track_begin(ATRACE_TAG, track_name, name, cookie)
|
||||
|
@ -229,13 +230,13 @@ static inline void atrace_async_for_track_begin(uint64_t tag, const char* track_
|
|||
* Trace the end of an asynchronous event.
|
||||
* This should correspond to a previous ATRACE_ASYNC_FOR_TRACK_BEGIN.
|
||||
*/
|
||||
#define ATRACE_ASYNC_FOR_TRACK_END(track_name, name, cookie) \
|
||||
atrace_async_for_track_end(ATRACE_TAG, track_name, name, cookie)
|
||||
#define ATRACE_ASYNC_FOR_TRACK_END(track_name, cookie) \
|
||||
atrace_async_for_track_end(ATRACE_TAG, track_name, cookie)
|
||||
static inline void atrace_async_for_track_end(uint64_t tag, const char* track_name,
|
||||
const char* name, int32_t cookie) {
|
||||
int32_t cookie) {
|
||||
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
|
||||
void atrace_async_for_track_end_body(const char*, const char*, int32_t);
|
||||
atrace_async_for_track_end_body(track_name, name, cookie);
|
||||
void atrace_async_for_track_end_body(const char*, int32_t);
|
||||
atrace_async_for_track_end_body(track_name, cookie);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -231,24 +231,24 @@ void atrace_async_end_body(const char* name, int32_t cookie)
|
|||
|
||||
void atrace_async_for_track_begin_body(const char* track_name, const char* name, int32_t cookie) {
|
||||
if (CC_LIKELY(atrace_use_container_sock)) {
|
||||
WRITE_MSG_IN_CONTAINER("T", "|", "|%d", track_name, name, cookie);
|
||||
WRITE_MSG_IN_CONTAINER("G", "|", "|%d", track_name, name, cookie);
|
||||
return;
|
||||
}
|
||||
|
||||
if (atrace_marker_fd < 0) return;
|
||||
|
||||
WRITE_MSG("T|%d|", "|%" PRId32, track_name, name, cookie);
|
||||
WRITE_MSG("G|%d|", "|%" PRId32, track_name, name, cookie);
|
||||
}
|
||||
|
||||
void atrace_async_for_track_end_body(const char* track_name, const char* name, int32_t cookie) {
|
||||
void atrace_async_for_track_end_body(const char* track_name, int32_t cookie) {
|
||||
if (CC_LIKELY(atrace_use_container_sock)) {
|
||||
WRITE_MSG_IN_CONTAINER("U", "|", "|%d", track_name, name, cookie);
|
||||
WRITE_MSG_IN_CONTAINER("H", "|", "|%d", "", track_name, cookie);
|
||||
return;
|
||||
}
|
||||
|
||||
if (atrace_marker_fd < 0) return;
|
||||
|
||||
WRITE_MSG("U|%d|", "|%" PRId32, track_name, name, cookie);
|
||||
WRITE_MSG("H|%d|", "|%" PRId32, "", track_name, cookie);
|
||||
}
|
||||
|
||||
void atrace_instant_body(const char* name) {
|
||||
|
|
|
@ -90,11 +90,11 @@ void atrace_async_end_body(const char* name, int32_t cookie)
|
|||
}
|
||||
|
||||
void atrace_async_for_track_begin_body(const char* track_name, const char* name, int32_t cookie) {
|
||||
WRITE_MSG("T|%d|", "|%" PRId32, track_name, name, cookie);
|
||||
WRITE_MSG("G|%d|", "|%" PRId32, track_name, name, cookie);
|
||||
}
|
||||
|
||||
void atrace_async_for_track_end_body(const char* track_name, const char* name, int32_t cookie) {
|
||||
WRITE_MSG("U|%d|", "|%" PRId32, track_name, name, cookie);
|
||||
void atrace_async_for_track_end_body(const char* track_name, int32_t cookie) {
|
||||
WRITE_MSG("H|%d|", "|%" PRId32, "", track_name, cookie);
|
||||
}
|
||||
|
||||
void atrace_instant_body(const char* name) {
|
||||
|
|
|
@ -202,13 +202,13 @@ TEST_F(TraceDevTest, atrace_async_for_track_begin_body_normal) {
|
|||
|
||||
std::string actual;
|
||||
ASSERT_TRUE(android::base::ReadFdToString(atrace_marker_fd, &actual));
|
||||
std::string expected = android::base::StringPrintf("T|%d|fake_track|fake_name|12345", getpid());
|
||||
std::string expected = android::base::StringPrintf("G|%d|fake_track|fake_name|12345", getpid());
|
||||
ASSERT_STREQ(expected.c_str(), actual.c_str());
|
||||
}
|
||||
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_begin_body_exact_track_name) {
|
||||
const int name_size = 5;
|
||||
std::string expected = android::base::StringPrintf("T|%d|", getpid());
|
||||
std::string expected = android::base::StringPrintf("G|%d|", getpid());
|
||||
std::string track_name =
|
||||
MakeName(ATRACE_MESSAGE_LENGTH - expected.length() - 1 - name_size - 6);
|
||||
atrace_async_for_track_begin_body(track_name.c_str(), "name", 12345);
|
||||
|
@ -224,7 +224,7 @@ TEST_F(TraceDevTest, atrace_async_for_track_begin_body_exact_track_name) {
|
|||
// Add a single character and verify name truncation
|
||||
ASSERT_EQ(0, lseek(atrace_marker_fd, 0, SEEK_SET));
|
||||
track_name += '*';
|
||||
expected = android::base::StringPrintf("T|%d|", getpid());
|
||||
expected = android::base::StringPrintf("G|%d|", getpid());
|
||||
expected += track_name + "|nam|12345";
|
||||
atrace_async_for_track_begin_body(track_name.c_str(), "name", 12345);
|
||||
EXPECT_EQ(ATRACE_MESSAGE_LENGTH - 1, lseek(atrace_marker_fd, 0, SEEK_CUR));
|
||||
|
@ -234,7 +234,7 @@ TEST_F(TraceDevTest, atrace_async_for_track_begin_body_exact_track_name) {
|
|||
}
|
||||
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_begin_body_truncated_track_name) {
|
||||
std::string expected = android::base::StringPrintf("T|%d|", getpid());
|
||||
std::string expected = android::base::StringPrintf("G|%d|", getpid());
|
||||
std::string track_name = MakeName(2 * ATRACE_MESSAGE_LENGTH);
|
||||
atrace_async_for_track_begin_body(track_name.c_str(), "name", 12345);
|
||||
|
||||
|
@ -250,7 +250,7 @@ TEST_F(TraceDevTest, atrace_async_for_track_begin_body_truncated_track_name) {
|
|||
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_begin_body_exact_name) {
|
||||
const int track_name_size = 11;
|
||||
std::string expected = android::base::StringPrintf("T|%d|", getpid());
|
||||
std::string expected = android::base::StringPrintf("G|%d|", getpid());
|
||||
std::string name =
|
||||
MakeName(ATRACE_MESSAGE_LENGTH - expected.length() - 1 - track_name_size - 6);
|
||||
atrace_async_for_track_begin_body("track_name", name.c_str(), 12345);
|
||||
|
@ -274,7 +274,7 @@ TEST_F(TraceDevTest, atrace_async_for_track_begin_body_exact_name) {
|
|||
}
|
||||
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_begin_body_truncated_name) {
|
||||
std::string expected = android::base::StringPrintf("T|%d|track_name|", getpid());
|
||||
std::string expected = android::base::StringPrintf("G|%d|track_name|", getpid());
|
||||
std::string name = MakeName(2 * ATRACE_MESSAGE_LENGTH);
|
||||
atrace_async_for_track_begin_body("track_name", name.c_str(), 12345);
|
||||
|
||||
|
@ -289,7 +289,7 @@ TEST_F(TraceDevTest, atrace_async_for_track_begin_body_truncated_name) {
|
|||
}
|
||||
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_begin_body_truncated_both) {
|
||||
std::string expected = android::base::StringPrintf("T|%d|", getpid());
|
||||
std::string expected = android::base::StringPrintf("G|%d|", getpid());
|
||||
std::string name = MakeName(2 * ATRACE_MESSAGE_LENGTH);
|
||||
std::string track_name = MakeName(2 * ATRACE_MESSAGE_LENGTH);
|
||||
atrace_async_for_track_begin_body(track_name.c_str(), name.c_str(), 12345);
|
||||
|
@ -306,112 +306,52 @@ TEST_F(TraceDevTest, atrace_async_for_track_begin_body_truncated_both) {
|
|||
}
|
||||
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_end_body_normal) {
|
||||
atrace_async_for_track_end_body("fake_track", "fake_name", 12345);
|
||||
atrace_async_for_track_end_body("fake_track", 12345);
|
||||
|
||||
ASSERT_EQ(0, lseek(atrace_marker_fd, 0, SEEK_SET));
|
||||
|
||||
std::string actual;
|
||||
ASSERT_TRUE(android::base::ReadFdToString(atrace_marker_fd, &actual));
|
||||
std::string expected = android::base::StringPrintf("U|%d|fake_track|fake_name|12345", getpid());
|
||||
std::string expected = android::base::StringPrintf("H|%d|fake_track|12345", getpid());
|
||||
ASSERT_STREQ(expected.c_str(), actual.c_str());
|
||||
}
|
||||
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_end_body_exact_track_name) {
|
||||
const int name_size = 5;
|
||||
std::string expected = android::base::StringPrintf("U|%d|", getpid());
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_end_body_exact) {
|
||||
std::string expected = android::base::StringPrintf("H|%d|", getpid());
|
||||
std::string track_name =
|
||||
MakeName(ATRACE_MESSAGE_LENGTH - expected.length() - 1 - name_size - 6);
|
||||
atrace_async_for_track_end_body(track_name.c_str(), "name", 12345);
|
||||
MakeName(ATRACE_MESSAGE_LENGTH - expected.length() - 7);
|
||||
atrace_async_for_track_end_body(track_name.c_str(), 12345);
|
||||
|
||||
ASSERT_EQ(ATRACE_MESSAGE_LENGTH - 1, lseek(atrace_marker_fd, 0, SEEK_CUR));
|
||||
ASSERT_EQ(0, lseek(atrace_marker_fd, 0, SEEK_SET));
|
||||
|
||||
std::string actual;
|
||||
ASSERT_TRUE(android::base::ReadFdToString(atrace_marker_fd, &actual));
|
||||
expected += track_name + "|name|12345";
|
||||
expected += track_name + "|12345";
|
||||
ASSERT_STREQ(expected.c_str(), actual.c_str());
|
||||
|
||||
// Add a single character and verify name truncation
|
||||
// Add a single character and verify we get the exact same value as before.
|
||||
ASSERT_EQ(0, lseek(atrace_marker_fd, 0, SEEK_SET));
|
||||
track_name += '*';
|
||||
expected = android::base::StringPrintf("U|%d|", getpid());
|
||||
expected += track_name + "|nam|12345";
|
||||
atrace_async_for_track_end_body(track_name.c_str(), "name", 12345);
|
||||
atrace_async_for_track_end_body(track_name.c_str(), 12345);
|
||||
EXPECT_EQ(ATRACE_MESSAGE_LENGTH - 1, lseek(atrace_marker_fd, 0, SEEK_CUR));
|
||||
ASSERT_EQ(0, lseek(atrace_marker_fd, 0, SEEK_SET));
|
||||
ASSERT_TRUE(android::base::ReadFdToString(atrace_marker_fd, &actual));
|
||||
ASSERT_STREQ(expected.c_str(), actual.c_str());
|
||||
}
|
||||
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_end_body_truncated_track_name) {
|
||||
std::string expected = android::base::StringPrintf("U|%d|", getpid());
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_end_body_truncated) {
|
||||
std::string expected = android::base::StringPrintf("H|%d|", getpid());
|
||||
std::string track_name = MakeName(2 * ATRACE_MESSAGE_LENGTH);
|
||||
atrace_async_for_track_end_body(track_name.c_str(), "name", 12345);
|
||||
atrace_async_for_track_end_body(track_name.c_str(), 12345);
|
||||
|
||||
ASSERT_EQ(ATRACE_MESSAGE_LENGTH - 1, lseek(atrace_marker_fd, 0, SEEK_CUR));
|
||||
ASSERT_EQ(0, lseek(atrace_marker_fd, 0, SEEK_SET));
|
||||
|
||||
std::string actual;
|
||||
ASSERT_TRUE(android::base::ReadFdToString(atrace_marker_fd, &actual));
|
||||
int expected_len = ATRACE_MESSAGE_LENGTH - expected.length() - 9;
|
||||
expected += android::base::StringPrintf("%.*s|n|12345", expected_len, track_name.c_str());
|
||||
ASSERT_STREQ(expected.c_str(), actual.c_str());
|
||||
}
|
||||
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_end_body_exact_name) {
|
||||
const int track_name_size = 11;
|
||||
std::string expected = android::base::StringPrintf("U|%d|", getpid());
|
||||
std::string name =
|
||||
MakeName(ATRACE_MESSAGE_LENGTH - expected.length() - 1 - track_name_size - 6);
|
||||
atrace_async_for_track_end_body("track_name", name.c_str(), 12345);
|
||||
|
||||
ASSERT_EQ(ATRACE_MESSAGE_LENGTH - 1, lseek(atrace_marker_fd, 0, SEEK_CUR));
|
||||
ASSERT_EQ(0, lseek(atrace_marker_fd, 0, SEEK_SET));
|
||||
|
||||
std::string actual;
|
||||
ASSERT_TRUE(android::base::ReadFdToString(atrace_marker_fd, &actual));
|
||||
expected += "track_name|" + name + "|12345";
|
||||
ASSERT_STREQ(expected.c_str(), actual.c_str());
|
||||
|
||||
// Add a single character and verify we get the same value as before.
|
||||
ASSERT_EQ(0, lseek(atrace_marker_fd, 0, SEEK_SET));
|
||||
name += '*';
|
||||
atrace_async_for_track_end_body("track_name", name.c_str(), 12345);
|
||||
EXPECT_EQ(ATRACE_MESSAGE_LENGTH - 1, lseek(atrace_marker_fd, 0, SEEK_CUR));
|
||||
ASSERT_EQ(0, lseek(atrace_marker_fd, 0, SEEK_SET));
|
||||
ASSERT_TRUE(android::base::ReadFdToString(atrace_marker_fd, &actual));
|
||||
ASSERT_STREQ(expected.c_str(), actual.c_str());
|
||||
}
|
||||
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_end_body_truncated_name) {
|
||||
std::string expected = android::base::StringPrintf("U|%d|track_name|", getpid());
|
||||
std::string name = MakeName(2 * ATRACE_MESSAGE_LENGTH);
|
||||
atrace_async_for_track_end_body("track_name", name.c_str(), 12345);
|
||||
|
||||
ASSERT_EQ(ATRACE_MESSAGE_LENGTH - 1, lseek(atrace_marker_fd, 0, SEEK_CUR));
|
||||
ASSERT_EQ(0, lseek(atrace_marker_fd, 0, SEEK_SET));
|
||||
|
||||
std::string actual;
|
||||
ASSERT_TRUE(android::base::ReadFdToString(atrace_marker_fd, &actual));
|
||||
int expected_len = ATRACE_MESSAGE_LENGTH - expected.length() - 1 - 6;
|
||||
expected += android::base::StringPrintf("%.*s|12345", expected_len, name.c_str());
|
||||
ASSERT_STREQ(expected.c_str(), actual.c_str());
|
||||
}
|
||||
|
||||
TEST_F(TraceDevTest, atrace_async_for_track_end_body_truncated_both) {
|
||||
std::string expected = android::base::StringPrintf("U|%d|", getpid());
|
||||
std::string name = MakeName(2 * ATRACE_MESSAGE_LENGTH);
|
||||
std::string track_name = MakeName(2 * ATRACE_MESSAGE_LENGTH);
|
||||
atrace_async_for_track_end_body(track_name.c_str(), name.c_str(), 12345);
|
||||
|
||||
ASSERT_EQ(ATRACE_MESSAGE_LENGTH - 1, lseek(atrace_marker_fd, 0, SEEK_CUR));
|
||||
ASSERT_EQ(0, lseek(atrace_marker_fd, 0, SEEK_SET));
|
||||
|
||||
std::string actual;
|
||||
ASSERT_TRUE(android::base::ReadFdToString(atrace_marker_fd, &actual));
|
||||
int expected_len = ATRACE_MESSAGE_LENGTH - expected.length() - 3 - 6;
|
||||
expected += android::base::StringPrintf("%.*s|%.1s|12345", expected_len, track_name.c_str(),
|
||||
name.c_str());
|
||||
int expected_len = ATRACE_MESSAGE_LENGTH - expected.length() - 7;
|
||||
expected += android::base::StringPrintf("%.*s|12345", expected_len, track_name.c_str());
|
||||
ASSERT_STREQ(expected.c_str(), actual.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,7 @@ void atrace_async_begin_body(const char* /*name*/, int32_t /*cookie*/) {}
|
|||
void atrace_async_end_body(const char* /*name*/, int32_t /*cookie*/) {}
|
||||
void atrace_async_for_track_begin_body(const char* /*track_name*/, const char* /*name*/,
|
||||
int32_t /*cookie*/) {}
|
||||
void atrace_async_for_track_end_body(const char* /*track_name*/, const char* /*name*/,
|
||||
int32_t /*cookie*/) {}
|
||||
void atrace_async_for_track_end_body(const char* /*track_name*/, int32_t /*cookie*/) {}
|
||||
void atrace_instant_body(const char* /*name*/) {}
|
||||
void atrace_instant_for_track_body(const char* /*track_name*/, const char* /*name*/) {}
|
||||
void atrace_int_body(const char* /*name*/, int32_t /*value*/) {}
|
||||
|
|
Loading…
Reference in a new issue