Repository: pytorch/ignite

Issue:
Error printing BasicTimeProfiler results
## 🐛 Bug description

Don't know if it's normal (because not yet stable feature) but using the following code : 
```
profiler = BasicTimeProfiler()
profiler.attach(trainer)
...
results = profiler.get_results()
print(results)
BasicTimeProfiler.print_results(profiler.get_results())
```
and I got a runtime error (I put here stack including print msg)
```
OrderedDict([('processing_stats', OrderedDict([('min/index', (0.002581869950518012, 937)), ('max/index', (0.24407817423343658, 0)), ('mean', 0.005071939900517464), ('std', 0.005763144697993994), ('total', 9.514959335327148)])), ('dataflow_stats', OrderedDict([('min/index', (5.4130003263708204e-05, 1874)), ('max/index', (0.02181326039135456, 1875)), ('mean', 0.00013960782962385565), ('std', 0.0006590772536583245), ('total', 0.2619042992591858)])), ('event_handlers_stats', {'EPOCH_STARTED': OrderedDict([('min/index', (6.137001037131995e-06, 0)), ('max/index', (1.3475997548084706e-05, 1)), ('mean', 9.80649929260835e-06), ('std', 5.189453986531589e-06), ('total', 1.96129985852167e-05)]), 'EPOCH_COMPLETED': OrderedDict([('min/index', (3.951500654220581, 0)), ('max/index', (4.009259223937988, 1)), ('mean', 3.980380058288574), ('std', 0.0408414751291275), ('total', 7.960760116577148)]), 'STARTED': OrderedDict([('min/index', (4.647001333069056e-06, 0)), ('max/index', (4.647001333069056e-06, 0)), ('mean', 4.647001333069056e-06), ('std', nan), ('total', 4.647001333069056e-06)]), 'COMPLETED': OrderedDict([('min/index', (0.001252603018656373, 0)), ('max/index', (0.001252603018656373, 0)), ('mean', 0.001252603018656373), ('std', nan), ('total', 0.001252603018656373)]), 'ITERATION_STARTED': OrderedDict([('min/index', (1.2870004866272211e-06, 931)), ('max/index', (1.6206002328544855e-05, 784)), ('mean', 2.0810284695471637e-06), ('std', 1.0310620837117312e-06), ('total', 0.003904009470716119)]), 'ITERATION_COMPLETED': OrderedDict([('min/index', (0.00041244301246479154, 6)), ('max/index', (0.0033979369327425957, 1706)), ('mean', 0.0005990439676679671), ('std', 0.00017004708934109658), ('total', 1.1238064765930176)]), 'GET_BATCH_STARTED': OrderedDict([('min/index', (2.2699969122186303e-06, 1871)), ('max/index', (6.306700379354879e-05, 1627)), ('mean', 3.619041763158748e-06), ('std', 2.3099164536688477e-06), ('total', 0.006789322476834059)]), 'GET_BATCH_COMPLETED': OrderedDict([('min/index', (1.471998984925449e-06, 934)), ('max/index', (1.4063996786717325e-05, 918)), ('mean', 2.3078853246261133e-06), ('std', 8.762469292378228e-07), ('total', 0.0043295929208397865)]), 'total_time': tensor(9.1009)}), ('event_handlers_names', {'EPOCH_STARTED_names': ['Metric.started'], 'EPOCH_COMPLETED_names': ['ProgressBar._close', 'log_training_results_fn', 'log_validation_results_fn'], 'STARTED_names': ['BasicTimeProfiler._as_first_started'], 'COMPLETED_names': ['ModelCheckpoint'], 'ITERATION_STARTED_names': [], 'ITERATION_COMPLETED_names': ['Metric.iteration_completed', 'Metric.completed', 'LRScheduler', '_OutputHandler', 'Engine._handler_wrapper.<locals>.wrapper', 'Engine._handler_wrapper.<locals>.wrapper'], 'GET_BATCH_STARTED_names': [], 'GET_BATCH_COMPLETED_names': []})])
Traceback (most recent call last):
  File "tutorials/mnist/mnist.py", line 228, in <module>
    BasicTimeProfiler.print_results(profiler.get_results())
  File "/work/desrozis/Softwares/conda/envs/focus-light/lib/python3.7/site-packages/ignite/contrib/handlers/time_profilers.py", line 414, in print_results
    **others,
KeyError: 'Events_STARTED'
```
There is no key `Events_STARTED` and more generaly no one begins with the `Events_` prefix. Did I miss something ? Or is it the `output_message` variable in the `time_profilers.py` file which is corrupted ?

Thanks for your help !

## Environment

 - PyTorch Version (e.g., 1.4): 1.4
 - Ignite Version (e.g., 0.3.0): master
 - OS (e.g., Linux): Linux
 - How you installed Ignite (`conda`, `pip`, source): pip from sources 
 - Python version: 3.7
 - Any other relevant information: git tag 4dced08f4ee294c36f54c4c64c7d60adb6aefc72




Discussion:
@sdesrozis I can not reproduce your issue. Could you please provide a snippet to reproduce it.
Here is mine
```python
import ignite
print(ignite.__version__)

from ignite.contrib.handlers.time_profilers import BasicTimeProfiler
from ignite.engine import Engine


trainer = Engine(lambda e, b: None)
profiler = BasicTimeProfiler()
profiler.attach(trainer)

trainer.run(list(range(10)), max_epochs=2)

results = profiler.get_results()
# print(results)
BasicTimeProfiler.print_results(profiler.get_results());
```

<details>
<summary>
Output:
</summary>

```
0.4.0.dev20200206

--------------------------------------------
- Time profiling results:
--------------------------------------------

Processing function time stats (in seconds):
	min/index: (5.822163075208664e-06, 9)
	max/index: (7.409136742353439e-06, 0)
	mean: 6.1339001149463e-06
	std: 3.797724161813676e-07
	total: 0.0001226780004799366


Dataflow time stats (in seconds):
	min/index: (2.7878209948539734e-05, 7)
	max/index: (5.764095112681389e-05, 19)
	mean: 3.117644155281596e-05
	std: 8.162835001712665e-06
	total: 0.0006235288456082344


Time stats of event handlers (in seconds):
- Total time spent:
	0.00017259642481803894

- Events.STARTED:
	min/index: (6.504356861114502e-06, 0)
	max/index: (6.504356861114502e-06, 0)
	mean: 6.504356861114502e-06
	std: nan
	total: 6.504356861114502e-06

Handlers names:
['BasicTimeProfiler._as_first_started']

- Events.EPOCH_STARTED:
	min/index: (1.7439015209674835e-06, 1)
	max/index: (2.5997869670391083e-06, 0)
	mean: 2.171844244003296e-06
	std: 6.052023877600732e-07
	total: 4.343688488006592e-06

Handlers names:
[]

- Events.ITERATION_STARTED:
	min/index: (1.387670636177063e-06, 14)
	max/index: (1.7620623111724854e-06, 0)
	mean: 1.457263692827837e-06
	std: 8.268084883411575e-08
	total: 2.9145274311304092e-05

Handlers names:
[]

- Events.ITERATION_COMPLETED:
	min/index: (2.0246952772140503e-06, 19)
	max/index: (2.620276063680649e-06, 0)
	mean: 2.1990854293107986e-06
	std: 1.2816821026717662e-07
	total: 4.398170858621597e-05

Handlers names:
[]

- Events.EPOCH_COMPLETED:
	min/index: (1.810956746339798e-06, 1)
	max/index: (2.0372681319713593e-06, 0)
	mean: 1.9241124391555786e-06
	std: 1.600263175305372e-07
	total: 3.848224878311157e-06

Handlers names:
[]

- Events.COMPLETED:
	min/index: (2.1900050342082977e-06, 0)
	max/index: (2.1900050342082977e-06, 0)
	mean: 2.1900050342082977e-06
	std: nan
	total: 2.1900050342082977e-06

Handlers names:
[]
```

</details>



Thanks!
Your snippet doesn't work for me... I got the following stack (print uncommented) : 
```
0.4.0
OrderedDict([('processing_stats', OrderedDict([('min/index', (9.522002073936164e-06, 9)), ('max/index', (1.8264996469952166e-05, 0)), ('mean', 1.1144799827889074e-05), ('std', 2.6518816866882844e-06), ('total', 0.00022289599291980267)])), ('dataflow_stats', OrderedDict([('min/index', (3.320199903100729e-05, 16)), ('max/index', (6.911899981787428e-05, 19)), ('mean', 3.764329812838696e-05), ('std', 9.486548151471652e-06), ('total', 0.0007528659771196544)])), ('event_handlers_stats', {'EPOCH_STARTED': OrderedDict([('min/index', (1.1709998943842947e-06, 1)), ('max/index', (3.0340015655383468e-06, 0)), ('mean', 2.1025007299613208e-06), ('std', 1.3173411161915283e-06), ('total', 4.2050014599226415e-06)]), 'EPOCH_COMPLETED': OrderedDict([('min/index', (1.205000444315374e-06, 0)), ('max/index', (1.844004145823419e-06, 1)), ('mean', 1.5245022950693965e-06), ('std', 4.518438458944729e-07), ('total', 3.049004590138793e-06)]), 'STARTED': OrderedDict([('min/index', (5.816000339109451e-06, 0)), ('max/index', (5.816000339109451e-06, 0)), ('mean', 5.816000339109451e-06), ('std', nan), ('total', 5.816000339109451e-06)]), 'COMPLETED': OrderedDict([('min/index', (2.019995008595288e-06, 0)), ('max/index', (2.019995008595288e-06, 0)), ('mean', 2.019995008595288e-06), ('std', nan), ('total', 2.019995008595288e-06)]), 'ITERATION_STARTED': OrderedDict([('min/index', (1.005006197374314e-06, 2)), ('max/index', (1.915999746415764e-06, 19)), ('mean', 1.2187010725028813e-06), ('std', 2.936610314918653e-07), ('total', 2.4374021450057626e-05)]), 'ITERATION_COMPLETED': OrderedDict([('min/index', (1.400003384333104e-06, 9)), ('max/index', (2.659995516296476e-06, 19)), ('mean', 1.6214504512390704e-06), ('std', 3.4573065477161435e-07), ('total', 3.242900857003406e-05)]), 'GET_BATCH_STARTED': OrderedDict([('min/index', (1.7149941413663328e-06, 7)), ('max/index', (3.007000486832112e-06, 19)), ('mean', 1.9296999198559206e-06), ('std', 3.8654556533401774e-07), ('total', 3.8594000216107816e-05)]), 'GET_BATCH_COMPLETED': OrderedDict([('min/index', (1.1090014595538378e-06, 14)), ('max/index', (2.830005541909486e-06, 19)), ('mean', 1.2914995295432163e-06), ('std', 4.150766130806005e-07), ('total', 2.582999150035903e-05)]), 'total_time': tensor(0.0001)}), ('event_handlers_names', {'EPOCH_STARTED_names': [], 'EPOCH_COMPLETED_names': [], 'STARTED_names': ['BasicTimeProfiler._as_first_started'], 'COMPLETED_names': [], 'ITERATION_STARTED_names': [], 'ITERATION_COMPLETED_names': [], 'GET_BATCH_STARTED_names': [], 'GET_BATCH_COMPLETED_names': []})])
Traceback (most recent call last):
  File "bug.py", line 16, in <module>
    BasicTimeProfiler.print_results(profiler.get_results());
  File "/work/desrozis/Softwares/conda/envs/focus-light/lib/python3.7/site-packages/ignite/contrib/handlers/time_profilers.py", line 414, in print_results
    **others,
KeyError: 'Events_STARTED'
```

Ok, we don't have the same version (0.4.0 vs 0.4.0.dev20200206) maybe it could be a clue.

Any idea ? pytorch installed from conda (but I suppose it doesn't matter).
I got it, while updating to the `master`. Thanks for pointing out the bug !

cc @ykumards 

Resolving patch:
diff --git a/ignite/contrib/handlers/time_profilers.py b/ignite/contrib/handlers/time_profilers.py
--- a/ignite/contrib/handlers/time_profilers.py
+++ b/ignite/contrib/handlers/time_profilers.py
@@ -379,34 +379,34 @@ def odict_to_str(d):
 \t{total_time}
 
 - Events.STARTED:
-{Events_STARTED}
+{STARTED}
 Handlers names:
-{Events_STARTED_names}
+{STARTED_names}
 
 - Events.EPOCH_STARTED:
-{Events_EPOCH_STARTED}
+{EPOCH_STARTED}
 Handlers names:
-{Events_EPOCH_STARTED_names}
+{EPOCH_STARTED_names}
 
 - Events.ITERATION_STARTED:
-{Events_ITERATION_STARTED}
+{ITERATION_STARTED}
 Handlers names:
-{Events_ITERATION_STARTED_names}
+{ITERATION_STARTED_names}
 
 - Events.ITERATION_COMPLETED:
-{Events_ITERATION_COMPLETED}
+{ITERATION_COMPLETED}
 Handlers names:
-{Events_ITERATION_COMPLETED_names}
+{ITERATION_COMPLETED_names}
 
 - Events.EPOCH_COMPLETED:
-{Events_EPOCH_COMPLETED}
+{EPOCH_COMPLETED}
 Handlers names:
-{Events_EPOCH_COMPLETED_names}
+{EPOCH_COMPLETED_names}
 
 - Events.COMPLETED:
-{Events_COMPLETED}
+{COMPLETED}
 Handlers names:
-{Events_COMPLETED_names}
+{COMPLETED_names}
 
 """.format(
             processing_stats=odict_to_str(results["processing_stats"]),


Test patch:
diff --git a/tests/ignite/contrib/handlers/test_time_profilers.py b/tests/ignite/contrib/handlers/test_time_profilers.py
--- a/tests/ignite/contrib/handlers/test_time_profilers.py
+++ b/tests/ignite/contrib/handlers/test_time_profilers.py
@@ -358,3 +358,26 @@ def delay_get_batch_completed(engine):
 
     # cleanup test log directory
     shutil.rmtree(test_folder)
+
+
+def test_print_results(capsys):
+    true_event_handler_time = 0.
+    true_max_epochs = 1
+    true_num_iters = 1
+
+    profiler = BasicTimeProfiler()
+    dummy_trainer = Engine(_do_nothing_update_fn)
+    profiler.attach(dummy_trainer)
+
+    @dummy_trainer.on(Events.GET_BATCH_COMPLETED)
+    def delay_get_batch_completed(engine):
+        time.sleep(true_event_handler_time)
+
+    dummy_trainer.run(range(true_num_iters), max_epochs=true_max_epochs)
+    results = profiler.get_results()
+    BasicTimeProfiler.print_results(profiler.get_results())
+
+    captured = capsys.readouterr()
+    out = captured.out
+
+    assert out[0] == "\n"