diff options
author | Ruben Rodriguez Buchillon <coconutruben@chromium.org> | 2018-07-24 18:37:00 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-01 00:05:03 -0700 |
commit | b3b220a8869479aad5dbfd0a11903ce5d28c6c4b (patch) | |
tree | 192ea5542e42c5ef9340ec233483a7888edd2ac2 /extra/usb_power/stats_manager.py | |
parent | fa96abba710e10638d783e1c753c3dc523b0226c (diff) | |
download | chrome-ec-b3b220a8869479aad5dbfd0a11903ce5d28c6c4b.tar.gz |
stats_manager: StatsManager returns file save locations
Some test code currently duplicates knowledge by telling StatsManager
where to save a file and then having to figure out where it stored the
files again. This CL has StatsManager return the save locations to
simplfy code. This potentially allows for informative logging on where
information was stored.
BRANCH=None
BUG=chromium:760267
TEST=unit tests still pass
Change-Id: I54b5873a4a3ddade9a73da0792c1947445759ad4
Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1140028
Reviewed-by: Mengqi Guo <mqg@chromium.org>
Diffstat (limited to 'extra/usb_power/stats_manager.py')
-rw-r--r-- | extra/usb_power/stats_manager.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/extra/usb_power/stats_manager.py b/extra/usb_power/stats_manager.py index 92d15098bc..cc663ecce0 100644 --- a/extra/usb_power/stats_manager.py +++ b/extra/usb_power/stats_manager.py @@ -174,6 +174,9 @@ class StatsManager(object): directory: directory to save the summary in. fname: filename to save summary under. prefix: start every row in summary string with prefix, for easier reading. + + Returns: + full path of summary save location """ summary_str = self.SummaryToString(prefix=prefix) + '\n' @@ -182,6 +185,7 @@ class StatsManager(object): fname = os.path.join(directory, fname) with open(fname, 'w') as f: f.write(summary_str) + return fname def SaveSummaryJSON(self, directory, fname='summary.json'): """Save summary (only MEAN) into a JSON file. @@ -189,6 +193,9 @@ class StatsManager(object): Args: directory: directory to save the JSON summary in. fname: filename to save summary under. + + Returns: + full path of summary save location """ data = {} for domain in self._summary: @@ -200,6 +207,7 @@ class StatsManager(object): fname = os.path.join(directory, fname) with open(fname, 'w') as f: json.dump(data, f) + return fname def GetRawData(self): """Getter for all raw_data.""" @@ -211,12 +219,16 @@ class StatsManager(object): Args: directory: directory to create the raw data folder in. dirname: folder in which raw data live. + + Returns: + list of full path of each domain's raw data save location """ if not os.path.exists(directory): os.makedirs(directory) dirname = os.path.join(directory, dirname) if not os.path.exists(dirname): os.makedirs(dirname) + fnames = [] for domain, data in self._data.iteritems(): if not domain.endswith(self._unit[domain]): domain = '%s_%s' % (domain, self._unit[domain]) @@ -224,3 +236,5 @@ class StatsManager(object): fname = os.path.join(dirname, fname) with open(fname, 'w') as f: f.write('\n'.join('%.2f' % sample for sample in data) + '\n') + fnames.append(fname) + return fnames |