Skip to content

Commit fecc9a3

Browse files
authored
Add test for nested RecordEvent. (#8773)
* Add test for nested RecordEvent. * Remove the debug information. * Add log information for the 3 usages and reduce the loop counts of nested case.
1 parent a9b9ec4 commit fecc9a3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

paddle/fluid/platform/profiler_test.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ TEST(RecordEvent, RecordEvent) {
7575
* ...
7676
* PopEvent(evt_name, dev_ctx);
7777
*/
78+
LOG(INFO) << "Usage 1: PushEvent & PopEvent";
7879
for (int loop = 0; loop < 3; ++loop) {
7980
for (int i = 1; i < 5; ++i) {
8081
std::string name = "op_" + std::to_string(i);
@@ -93,13 +94,42 @@ TEST(RecordEvent, RecordEvent) {
9394
* ...
9495
* }
9596
*/
97+
LOG(INFO) << "Usage 2: RecordEvent";
9698
for (int i = 1; i < 5; ++i) {
9799
std::string name = "evs_op_" + std::to_string(i);
98100
RecordEvent record_event(name, dev_ctx);
99101
int counter = 1;
100102
while (counter != i * 1000) counter++;
101103
}
102104

105+
/* Usage 3
106+
* {
107+
* RecordEvent record_event(name1, dev_ctx);
108+
* ...
109+
* code to be analyzed
110+
* ...
111+
* {
112+
* RecordEvent nested_record_event(name2, dev_ctx);
113+
* ...
114+
* code to be analyzed
115+
* ...
116+
* }
117+
* }
118+
*/
119+
LOG(INFO) << "Usage 3: nested RecordEvent";
120+
for (int i = 1; i < 5; ++i) {
121+
std::string name = "ano_evs_op_" + std::to_string(i);
122+
RecordEvent record_event(name, dev_ctx);
123+
int counter = 1;
124+
while (counter != i * 100) counter++;
125+
{
126+
std::string nested_name = "nested_ano_evs_op_" + std::to_string(i);
127+
RecordEvent nested_record_event(nested_name, dev_ctx);
128+
int nested_counter = 1;
129+
while (nested_counter != i * 100) nested_counter++;
130+
}
131+
}
132+
103133
// Bad Usage:
104134
PushEvent("event_without_pop", dev_ctx);
105135
PopEvent("event_without_push", dev_ctx);

0 commit comments

Comments
 (0)