diff options
author | Evelina Dumitrescu <evelinad@google.com> | 2016-10-20 16:05:38 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-02-01 18:13:44 -0800 |
commit | 731ad0791050f4070b3d30fd859f6fd43892247c (patch) | |
tree | 363fe48d65517c553ba395859b7e40aa28e26e3d | |
parent | 45a52fb3586d4fbaf6ffc5f3595ae417b5d148be (diff) | |
download | toolchain-utils-731ad0791050f4070b3d30fd859f6fd43892247c.tar.gz |
user_activity: Moved some functions to the utils module.
Moved ComputeCWPCummulativeInclusiveStatistics and ComputeCWPChildFunctionsFractions
from the process_hot_functions module to the utils module.
BUG=None
TEST=None
Change-Id: Ib5968ae722cc8a775744418f24512e3d727d3936
Reviewed-on: https://chrome-internal-review.googlesource.com/298618
Commit-Queue: Evelina Dumitrescu <evelinad@google.com>
Tested-by: Evelina Dumitrescu <evelinad@google.com>
Reviewed-by: Evelina Dumitrescu <evelinad@google.com>
Reviewed-by: Luis Lozano <llozano@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/435919
Commit-Ready: Luis Lozano <llozano@chromium.org>
Tested-by: Luis Lozano <llozano@chromium.org>
-rwxr-xr-x | user_activity_benchmarks/process_hot_functions.py | 81 | ||||
-rw-r--r-- | user_activity_benchmarks/utils.py | 75 |
2 files changed, 77 insertions, 79 deletions
diff --git a/user_activity_benchmarks/process_hot_functions.py b/user_activity_benchmarks/process_hot_functions.py index 13d228bb..2fbf3f93 100755 --- a/user_activity_benchmarks/process_hot_functions.py +++ b/user_activity_benchmarks/process_hot_functions.py @@ -103,83 +103,6 @@ class HotFunctionsProcessor(object): self._extra_cwp_functions_groups_path, self._extra_cwp_functions_groups_file) - @staticmethod - def ComputeCWPCummulativeInclusiveStatistics(cwp_inclusive_count_statistics): - """Computes the cumulative inclusive count value of a function. - - A function might appear declared in multiple files or objects. When - computing the fraction of the inclusive count value from a child function to - the parent function, we take into consideration the sum of the - inclusive_count - count values from all the ocurences of that function. - - Args: - cwp_inclusive_count_statistics: A dict containing the inclusive count - statistics extracted by the ParseCWPInclusiveCountFile method. - - Returns: - A dict having as a ket the name of the function and as a value the sum of - the inclusive count values of the occurences of the functions from all - the files and objects. - """ - cwp_inclusive_count_statistics_cumulative = defaultdict(int) - - for function_key, function_statistics \ - in cwp_inclusive_count_statistics.iteritems(): - function_name, _ = function_key.split(',') - cwp_inclusive_count_statistics_cumulative[function_name] += \ - function_statistics[1] - - return cwp_inclusive_count_statistics_cumulative - - @staticmethod - def ComputeCWPChildFunctionsFractions( - cwp_inclusive_count_statistics_cumulative, - cwp_pairwise_inclusive_count_statistics): - """Computes the fractions of the inclusive count values for child functions. - - The fraction represents the inclusive count value of a child function over - the one of the parent function. - - Args: - cwp_inclusive_count_statistics_cumulative: A dict containing the - cumulative inclusive count values of the CWP functions. - cwp_pairwise_inclusive_count_statistics: A dict containing the inclusive - count statistics for pairs of parent and child functions. The key is the - parent function. The value is a dict with the key the name of the child - function and the file name, comma separated, and the value is the - inclusive count value of the pair of parent and child functions. - - Returns: - A dict containing the inclusive count statistics for pairs of parent - and child functions. The key is the parent function. The value is a - dict with the key the name of the child function and the file name, - comma separated, and the value is the inclusive count fraction of the - child function out of the parent function. - """ - - pairwise_inclusive_count_fractions = {} - - for parent_function_key, child_functions_metrics in \ - cwp_pairwise_inclusive_count_statistics.iteritems(): - child_functions_fractions = {} - parent_function_inclusive_count = \ - cwp_inclusive_count_statistics_cumulative.get(parent_function_key, 0.0) - - if parent_function_key in cwp_inclusive_count_statistics_cumulative: - for child_function_key, child_function_inclusive_count \ - in child_functions_metrics.iteritems(): - child_functions_fractions[child_function_key] = \ - child_function_inclusive_count / parent_function_inclusive_count - else: - for child_function_key, child_function_inclusive_count \ - in child_functions_metrics.iteritems(): - child_functions_fractions[child_function_key] = 0.0 - pairwise_inclusive_count_fractions[parent_function_key] = \ - child_functions_fractions - - return pairwise_inclusive_count_fractions - def ExtractCommonFunctions(self, pprof_top_path, pprof_tree_path, cwp_inclusive_count_file, cwp_pairwise_inclusive_count_file, @@ -241,10 +164,10 @@ class HotFunctionsProcessor(object): utils.ParseCWPPairwiseInclusiveCountFile( cwp_pairwise_inclusive_count_file) cwp_inclusive_count_statistics_cumulative = \ - self.ComputeCWPCummulativeInclusiveStatistics( + utils.ComputeCWPCummulativeInclusiveStatistics( cwp_inclusive_count_statistics) cwp_pairwise_inclusive_count_fractions = \ - self.ComputeCWPChildFunctionsFractions( + utils.ComputeCWPChildFunctionsFractions( cwp_inclusive_count_statistics_cumulative, cwp_pairwise_inclusive_count_statistics) benchmark_set_metrics = {} diff --git a/user_activity_benchmarks/utils.py b/user_activity_benchmarks/utils.py index ead56df6..eea2bfc6 100644 --- a/user_activity_benchmarks/utils.py +++ b/user_activity_benchmarks/utils.py @@ -98,6 +98,81 @@ def MakePprofFunctionKey(function_and_file_name): return MakeCWPAndPprofFileNamesConsistent(function_and_file_name) + +def ComputeCWPCummulativeInclusiveStatistics(cwp_inclusive_count_statistics): + """Computes the cumulative inclusive count value of a function. + + A function might appear declared in multiple files or objects. When + computing the fraction of the inclusive count value from a child function to + the parent function, we take into consideration the sum of the + inclusive_count + count values from all the ocurences of that function. + + Args: + cwp_inclusive_count_statistics: A dict containing the inclusive count + statistics extracted by the ParseCWPInclusiveCountFile method. + + Returns: + A dict having as a ket the name of the function and as a value the sum of + the inclusive count values of the occurences of the functions from all + the files and objects. + """ + cwp_inclusive_count_statistics_cumulative = defaultdict(int) + + for function_key, function_statistics \ + in cwp_inclusive_count_statistics.iteritems(): + function_name, _ = function_key.split(',') + cwp_inclusive_count_statistics_cumulative[function_name] += \ + function_statistics[1] + + return cwp_inclusive_count_statistics_cumulative + +def ComputeCWPChildFunctionsFractions(cwp_inclusive_count_statistics_cumulative, + cwp_pairwise_inclusive_count_statistics): + """Computes the fractions of the inclusive count values for child functions. + + The fraction represents the inclusive count value of a child function over + the one of the parent function. + + Args: + cwp_inclusive_count_statistics_cumulative: A dict containing the + cumulative inclusive count values of the CWP functions. + cwp_pairwise_inclusive_count_statistics: A dict containing the inclusive + count statistics for pairs of parent and child functions. The key is the + parent function. The value is a dict with the key the name of the child + function and the file name, comma separated, and the value is the + inclusive count value of the pair of parent and child functions. + + Returns: + A dict containing the inclusive count statistics for pairs of parent + and child functions. The key is the parent function. The value is a + dict with the key the name of the child function and the file name, + comma separated, and the value is the inclusive count fraction of the + child function out of the parent function. + """ + + pairwise_inclusive_count_fractions = {} + + for parent_function_key, child_functions_metrics in \ + cwp_pairwise_inclusive_count_statistics.iteritems(): + child_functions_fractions = {} + parent_function_inclusive_count = \ + cwp_inclusive_count_statistics_cumulative.get(parent_function_key, 0.0) + + if parent_function_key in cwp_inclusive_count_statistics_cumulative: + for child_function_key, child_function_inclusive_count \ + in child_functions_metrics.iteritems(): + child_functions_fractions[child_function_key] = \ + child_function_inclusive_count / parent_function_inclusive_count + else: + for child_function_key, child_function_inclusive_count \ + in child_functions_metrics.iteritems(): + child_functions_fractions[child_function_key] = 0.0 + pairwise_inclusive_count_fractions[parent_function_key] = \ + child_functions_fractions + + return pairwise_inclusive_count_fractions + def ParseFunctionGroups(cwp_function_groups_lines): """Parses the contents of the function groups file. |