| 79 | logging.getLogger("experiment_logger").info(str) |
| 80 | |
| 81 | def log(self, input_count, batch_count, additional_values): |
| 82 | logdict = OrderedDict() |
| 83 | delta_t = time.time() - self.last_time |
| 84 | delta_count = input_count - self.last_input_count |
| 85 | self.last_time = time.time() |
| 86 | self.last_input_count = input_count |
| 87 | |
| 88 | logdict['time_spent'] = delta_t |
| 89 | logdict['cumulative_time_spent'] = time.time() - self.start_time |
| 90 | logdict['input_count'] = delta_count |
| 91 | logdict['cumulative_input_count'] = input_count |
| 92 | logdict['cumulative_batch_count'] = batch_count |
| 93 | if delta_t > 0: |
| 94 | logdict['inputs_per_sec'] = delta_count / delta_t |
| 95 | else: |
| 96 | logdict['inputs_per_sec'] = 0.0 |
| 97 | |
| 98 | for k in sorted(additional_values.keys()): |
| 99 | logdict[k] = additional_values[k] |
| 100 | |
| 101 | # Write the headers if they are not written yet |
| 102 | if self.headers is None: |
| 103 | self.headers = list(logdict.keys()) |
| 104 | self.logstr(",".join(self.headers)) |
| 105 | |
| 106 | self.logstr(",".join(str(v) for v in logdict.values())) |
| 107 | |
| 108 | for logger in self.external_loggers: |
| 109 | try: |
| 110 | logger.log(logdict) |
| 111 | except Exception as e: |
| 112 | logging.warning( |
| 113 | "Failed to call ExternalLogger: {}".format(e), e) |