Skip to content

Commit

Permalink
Add test for nested RecordEvent. (#8773)
Browse files Browse the repository at this point in the history
* Add test for nested RecordEvent.

* Remove the debug information.

* Add log information for the 3 usages and reduce the loop counts of nested case.
  • Loading branch information
Xreki authored Mar 8, 2018
1 parent a9b9ec4 commit fecc9a3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions paddle/fluid/platform/profiler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ TEST(RecordEvent, RecordEvent) {
* ...
* PopEvent(evt_name, dev_ctx);
*/
LOG(INFO) << "Usage 1: PushEvent & PopEvent";
for (int loop = 0; loop < 3; ++loop) {
for (int i = 1; i < 5; ++i) {
std::string name = "op_" + std::to_string(i);
Expand All @@ -93,13 +94,42 @@ TEST(RecordEvent, RecordEvent) {
* ...
* }
*/
LOG(INFO) << "Usage 2: RecordEvent";
for (int i = 1; i < 5; ++i) {
std::string name = "evs_op_" + std::to_string(i);
RecordEvent record_event(name, dev_ctx);
int counter = 1;
while (counter != i * 1000) counter++;
}

/* Usage 3
* {
* RecordEvent record_event(name1, dev_ctx);
* ...
* code to be analyzed
* ...
* {
* RecordEvent nested_record_event(name2, dev_ctx);
* ...
* code to be analyzed
* ...
* }
* }
*/
LOG(INFO) << "Usage 3: nested RecordEvent";
for (int i = 1; i < 5; ++i) {
std::string name = "ano_evs_op_" + std::to_string(i);
RecordEvent record_event(name, dev_ctx);
int counter = 1;
while (counter != i * 100) counter++;
{
std::string nested_name = "nested_ano_evs_op_" + std::to_string(i);
RecordEvent nested_record_event(nested_name, dev_ctx);
int nested_counter = 1;
while (nested_counter != i * 100) nested_counter++;
}
}

// Bad Usage:
PushEvent("event_without_pop", dev_ctx);
PopEvent("event_without_push", dev_ctx);
Expand Down

0 comments on commit fecc9a3

Please sign in to comment.