teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0094-tools-use-print-function-in-Python-3-code.patch

4bff0a
From 5adeea95a7310d97b98821322b51794a46199417 Mon Sep 17 00:00:00 2001
4bff0a
From: Lucas Werkmeister <mail@lucaswerkmeister.de>
4bff0a
Date: Sat, 25 Aug 2018 18:41:42 +0200
4bff0a
Subject: [PATCH] tools: use print function in Python 3 code
4bff0a
4bff0a
This GDB script was converted to use Python 3 along with all other
4bff0a
Python scripts in commit b95f5528cc, but still used the Python 2 print
4bff0a
statement syntax instead of the Python 3 print function. Fix that.
4bff0a
4bff0a
We also add the Python 2 compatibility statement, just in case some GDB
4bff0a
still uses Python 2 instead of Python 3.
4bff0a
---
4bff0a
 tools/gdb-sd_dump_hashmaps.py | 18 ++++++++++--------
4bff0a
 1 file changed, 10 insertions(+), 8 deletions(-)
4bff0a
4bff0a
diff --git a/tools/gdb-sd_dump_hashmaps.py b/tools/gdb-sd_dump_hashmaps.py
4bff0a
index e6ddd14ea7..ea15160107 100644
4bff0a
--- a/tools/gdb-sd_dump_hashmaps.py
4bff0a
+++ b/tools/gdb-sd_dump_hashmaps.py
4bff0a
@@ -2,6 +2,8 @@
4bff0a
 #  -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
4bff0a
 # SPDX-License-Identifier: LGPL-2.1+
4bff0a
 
4bff0a
+from __future__ import print_function
4bff0a
+
4bff0a
 import gdb
4bff0a
 
4bff0a
 class sd_dump_hashmaps(gdb.Command):
4bff0a
@@ -19,7 +21,7 @@ class sd_dump_hashmaps(gdb.Command):
4bff0a
                 ulong_t = gdb.lookup_type("unsigned long")
4bff0a
                 debug_offset = gdb.parse_and_eval("(unsigned long)&((HashmapBase*)0)->debug")
4bff0a
 
4bff0a
-                print "type, hash, indirect, entries, max_entries, buckets, creator"
4bff0a
+                print("type, hash, indirect, entries, max_entries, buckets, creator")
4bff0a
                 while d:
4bff0a
                         h = gdb.parse_and_eval("(HashmapBase*)((char*)%d - %d)" % (int(d.cast(ulong_t)), debug_offset))
4bff0a
 
4bff0a
@@ -34,7 +36,7 @@ class sd_dump_hashmaps(gdb.Command):
4bff0a
 
4bff0a
                         t = ["plain", "ordered", "set"][int(h["type"])]
4bff0a
 
4bff0a
-                        print "{}, {}, {}, {}, {}, {}, {} ({}:{})".format(t, h["hash_ops"], bool(h["has_indirect"]), n_entries, d["max_entries"], n_buckets, d["func"], d["file"], d["line"])
4bff0a
+                        print("{}, {}, {}, {}, {}, {}, {} ({}:{})".format(t, h["hash_ops"], bool(h["has_indirect"]), n_entries, d["max_entries"], n_buckets, d["func"], d["file"], d["line"]))
4bff0a
 
4bff0a
                         if arg != "" and n_entries > 0:
4bff0a
                                 dib_raw_addr = storage_ptr + (all_entry_sizes[h["type"]] * n_buckets)
4bff0a
@@ -46,10 +48,10 @@ class sd_dump_hashmaps(gdb.Command):
4bff0a
 
4bff0a
                                 for dib in sorted(iter(histogram)):
4bff0a
                                         if dib != 255:
4bff0a
-                                                print "{:>3} {:>8} {} of entries".format(dib, histogram[dib], 100.0*histogram[dib]/n_entries)
4bff0a
+                                                print("{:>3} {:>8} {} of entries".format(dib, histogram[dib], 100.0*histogram[dib]/n_entries))
4bff0a
                                         else:
4bff0a
-                                                print "{:>3} {:>8} {} of slots".format(dib, histogram[dib], 100.0*histogram[dib]/n_buckets)
4bff0a
-                                print "mean DIB of entries: {}".format(sum([dib*histogram[dib] for dib in iter(histogram) if dib != 255])*1.0/n_entries)
4bff0a
+                                                print("{:>3} {:>8} {} of slots".format(dib, histogram[dib], 100.0*histogram[dib]/n_buckets))
4bff0a
+                                print("mean DIB of entries: {}".format(sum([dib*histogram[dib] for dib in iter(histogram) if dib != 255])*1.0/n_entries))
4bff0a
 
4bff0a
                                 blocks = []
4bff0a
                                 current_len = 1
4bff0a
@@ -70,9 +72,9 @@ class sd_dump_hashmaps(gdb.Command):
4bff0a
                                 if len(blocks) > 1 and blocks[0][0] == blocks[0][1] and blocks[-1][0] == n_buckets - 1:
4bff0a
                                         blocks[0][1] += blocks[-1][1]
4bff0a
                                         blocks = blocks[0:-1]
4bff0a
-                                print "max block: {}".format(max(blocks, key=lambda a: a[1]))
4bff0a
-                                print "sum block lens: {}".format(sum(b[1] for b in blocks))
4bff0a
-                                print "mean block len: {}".format((1.0 * sum(b[1] for b in blocks) / len(blocks)))
4bff0a
+                                print("max block: {}".format(max(blocks, key=lambda a: a[1])))
4bff0a
+                                print("sum block lens: {}".format(sum(b[1] for b in blocks)))
4bff0a
+                                print("mean block len: {}".format((1.0 * sum(b[1] for b in blocks) / len(blocks))))
4bff0a
 
4bff0a
                         d = d["debug_list_next"]
4bff0a