From 3b51b0fb756fbd11305c9d3fed17647848fc71d9 Mon Sep 17 00:00:00 2001 From: Tovin Seven Date: Tue, 24 Jan 2017 15:26:21 +0700 Subject: [PATCH] Remove extra white spaces in json output json.dumps adds one space after colon by default. However, if we work with large trace, this will increase file size a lot. TrivialFix Change-Id: I46241ead0a09db4a32281f65a86bde2a413655b4 --- osprofiler/cmd/commands.py | 2 ++ osprofiler/tests/unit/cmd/test_shell.py | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/osprofiler/cmd/commands.py b/osprofiler/cmd/commands.py index 27d3e5b..ff2a179 100644 --- a/osprofiler/cmd/commands.py +++ b/osprofiler/cmd/commands.py @@ -83,12 +83,14 @@ class TraceCommands(BaseCommand): if args.use_json: output = json.dumps(trace, default=datetime_json_serialize, + separators=(",", ": "), indent=2) elif args.use_html: with open(os.path.join(os.path.dirname(__file__), "template.html")) as html_template: output = html_template.read().replace( "$DATA", json.dumps(trace, indent=4, + separators=(",", ": "), default=datetime_json_serialize)) elif args.use_dot: dot_graph = self._create_dot_graph(trace) diff --git a/osprofiler/tests/unit/cmd/test_shell.py b/osprofiler/tests/unit/cmd/test_shell.py index 5baa6c8..d4ffaaf 100644 --- a/osprofiler/tests/unit/cmd/test_shell.py +++ b/osprofiler/tests/unit/cmd/test_shell.py @@ -199,7 +199,8 @@ class ShellTestCase(test.TestCase): mock_get.return_value = notifications self.run_command(self._trace_show_cmd(format_="json")) - self.assertEqual("%s\n" % json.dumps(notifications, indent=2), + self.assertEqual("%s\n" % json.dumps(notifications, indent=2, + separators=(",", ": "),), sys.stdout.getvalue()) @mock.patch("sys.stdout", six.StringIO()) @@ -227,7 +228,8 @@ class ShellTestCase(test.TestCase): "spaceships, striking from a hidden" "base, have won their first victory" "against the evil Galactic Empire." - "\n" % json.dumps(notifications, indent=4), + "\n" % json.dumps(notifications, indent=4, + separators=(",", ": ")), sys.stdout.getvalue()) @mock.patch("sys.stdout", six.StringIO()) @@ -242,5 +244,5 @@ class ShellTestCase(test.TestCase): self._trace_show_cmd(format_="json")) output = mock_open.return_value.__enter__.return_value - output.write.assert_called_once_with(json.dumps(notifications, - indent=2)) + output.write.assert_called_once_with( + json.dumps(notifications, indent=2, separators=(",", ": ")))