(unused_argv=None)
| 138 | |
| 139 | |
| 140 | def main(unused_argv=None): |
| 141 | logging.set_verbosity(logging.INFO) |
| 142 | tf_version = versions.__version__ |
| 143 | print('TensorFlow version %s detected' % tf_version) |
| 144 | print('Welcome to the Cloud TPU Profiler v%s' % profiler_version.__version__) |
| 145 | |
| 146 | if LooseVersion(tf_version) < LooseVersion('1.14.0'): |
| 147 | sys.exit('You must install tensorflow >= 1.14.0 to use this plugin.') |
| 148 | |
| 149 | if not FLAGS.service_addr and not FLAGS.tpu: |
| 150 | sys.exit('You must specify either --service_addr or --tpu.') |
| 151 | |
| 152 | tpu_cluster_resolver = None |
| 153 | if FLAGS.service_addr: |
| 154 | if FLAGS.tpu: |
| 155 | logging.warn('Both --service_addr and --tpu are set. Ignoring ' |
| 156 | '--tpu and using --service_addr.') |
| 157 | service_addr = FLAGS.service_addr |
| 158 | else: |
| 159 | try: |
| 160 | tpu_cluster_resolver = ( |
| 161 | resolver.TPUClusterResolver([FLAGS.tpu], |
| 162 | zone=FLAGS.tpu_zone, |
| 163 | project=FLAGS.gcp_project)) |
| 164 | service_addr = tpu_cluster_resolver.get_master() |
| 165 | except (ValueError, TypeError): |
| 166 | sys.exit('Failed to find TPU %s in zone %s project %s. You may use ' |
| 167 | '--tpu_zone and --gcp_project to specify the zone and project of' |
| 168 | ' your TPU.' % (FLAGS.tpu, FLAGS.tpu_zone, FLAGS.gcp_project)) |
| 169 | service_addr = service_addr.replace('grpc://', '').replace(':8470', ':8466') |
| 170 | |
| 171 | workers_list = '' |
| 172 | if FLAGS.workers_list is not None: |
| 173 | workers_list = FLAGS.workers_list |
| 174 | elif tpu_cluster_resolver is not None: |
| 175 | workers_list = get_workers_list(tpu_cluster_resolver) |
| 176 | |
| 177 | # If profiling duration was not set by user or set to a non-positive value, |
| 178 | # we set it to a default value of 1000ms. |
| 179 | duration_ms = FLAGS.duration_ms if FLAGS.duration_ms > 0 else 1000 |
| 180 | |
| 181 | if FLAGS.monitoring_level > 0: |
| 182 | print('Since monitoring level is provided, profile', service_addr, ' for ', |
| 183 | FLAGS.duration_ms, ' ms and show metrics for ', FLAGS.num_queries, |
| 184 | ' time(s).') |
| 185 | monitoring_helper(service_addr, duration_ms, FLAGS.monitoring_level, |
| 186 | FLAGS.display_timestamp, FLAGS.num_queries) |
| 187 | else: |
| 188 | if not FLAGS.logdir: |
| 189 | sys.exit('You must specify either --logdir or --monitoring_level.') |
| 190 | |
| 191 | if not gfile.Exists(FLAGS.logdir): |
| 192 | gfile.MakeDirs(FLAGS.logdir) |
| 193 | |
| 194 | try: |
| 195 | profiler_client.start_tracing(service_addr, |
| 196 | os.path.expanduser(FLAGS.logdir), |
| 197 | duration_ms, workers_list, |
nothing calls this directly
no test coverage detected