<commit_before># Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Upload test results."""
from __future__ import print_function

import importlib
import json
import logging
import perfzero.utils as utils
import psutil
import socket

from six import u as unicode  # pylint: disable=W0622


def execute_methods(method_names_str, *args, **kwargs):
  """Calls a list of method names on given function params.

  Args:
    method_names_str: String - Comma-separated module.foo.bar.method strings.
      This function imports module.foo.bar for each such method and calls it
      with *args and **kwargs.
    *args: Function params common to each method.
    **kwargs: Function params common to each method.

  Raises:
    RuntimeError: If any of the invoked methods raised an exception.
  """
  errors = []
  module_methods_list = method_names_str.split(',')
  for module_method in module_methods_list:
    try:
      logging.info('Trying to call %s', module_method)
      module_path, method_path = module_method.rsplit('.', 1)
      this_module = importlib.import_module(module_path)
      logging.info('Found module %s, looking for %s', module_path, method_path)
      this_method = getattr(this_module, method_path)
      logging.info('Found method %s', method_path)
      this_method(*args, **kwargs)
    except Exception as e:  # pylint: disable=broad-except
      errors.append(str(e))
  if errors:
    raise RuntimeError('\n' + '\n'.join(errors))


def upload_execution_summary(bigquery_project_name, bigquery_dataset_table_name,
                             execution_summary):
  """Upload benchmark summary.

  Note: Using stream=False has a 1000 per day insert limit per table. Using
  stream=True, the documented limit is 50K+. With streaming there can be
  a small and possibly not noticeable delay to seeing the results the BigQuery
  UI, but there can be a 90 minute more or less delay in the results being part
  of exports.

  Note: BigQuery maps unicode() to STRING for python2.  If str is used that is<commit_msg>Update report_utils.py<commit_after># Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Upload test results."""
from __future__ import print_function

import importlib
import json
import logging
import perfzero.utils as utils
import psutil
import socket

from six import u as unicode  # pylint: disable=W0622


def execute_methods(method_names_str, *args, **kwargs):
  """Calls a list of method names on given function params.

  Args:
    method_names_str: String - Comma-separated module.foo.bar.method strings.
      This function imports module.foo.bar for each such method and calls it
      with *args and **kwargs.
    *args: Function params common to each method.
    **kwargs: Function params common to each method.

  Raises:
    RuntimeError: If any of the invoked methods raised an exception.
  """
  if not method_names_str:
    return
  errors = []
  module_methods_list = method_names_str.split(',')
  for module_method in module_methods_list:
    try:
      logging.info('Trying to call %s', module_method)
      module_path, method_path = module_method.rsplit('.', 1)
      this_module = importlib.import_module(module_path)
      logging.info('Found module %s, looking for %s', module_path, method_path)
      this_method = getattr(this_module, method_path)
      logging.info('Found method %s', method_path)
      this_method(*args, **kwargs)
    except Exception as e:  # pylint: disable=broad-except
      errors.append(str(e))
  if errors:
    raise RuntimeError('\n' + '\n'.join(errors))


def upload_execution_summary(bigquery_project_name, bigquery_dataset_table_name,
                             execution_summary):
  """Upload benchmark summary.

  Note: Using stream=False has a 1000 per day insert limit per table. Using
  stream=True, the documented limit is 50K+. With streaming there can be
  a small and possibly not noticeable delay to seeing the results the BigQuery
  UI, but there can be a 90 minute more or less delay in the results being part
  of exports.

  Note: BigQuery maps unicode() to STRING for python2.  If str is used that is
{'fraction_non_alphanumeric': 0.10250696378830083, 'fraction_numerical': 0.008170844939647167, 'mean_word_length': 3.9732225300092336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6597315', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1416, 'n_words': 606}