linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Pantyukhin <apantykhin@gmail.com>
To: mark.rutland@arm.com
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	namhyung@kernel.org, linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Alexander Pantyukhin <apantykhin@gmail.com>
Subject: [PATCH] tools:perf:scripts:python:mem-phys-addr fix performance
Date: Mon,  9 Jan 2023 14:33:47 +0500	[thread overview]
Message-ID: <20230109093347.6639-1-apantykhin@gmail.com> (raw)

Avoid double strip() calls for getting memory type.

Signed-off-by: Alexander Pantyukhin <apantykhin@gmail.com>
---
 tools/perf/scripts/python/mem-phys-addr.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/perf/scripts/python/mem-phys-addr.py b/tools/perf/scripts/python/mem-phys-addr.py
index 1f332e72b9b0..f267d8382eda 100644
--- a/tools/perf/scripts/python/mem-phys-addr.py
+++ b/tools/perf/scripts/python/mem-phys-addr.py
@@ -8,7 +8,6 @@ from __future__ import print_function
 
 import os
 import sys
-import struct
 import re
 import bisect
 import collections
@@ -30,12 +29,14 @@ event_name = None
 def parse_iomem():
 	global f
 	f = open('/proc/iomem', 'r')
-	for i, j in enumerate(f):
+	for _, j in enumerate(f):
 		m = re.split('-|:',j,2)
-		if m[2].strip() == 'System RAM':
+		memory_type = m[2].strip()
+
+		if memory_type == 'System RAM':
 			system_ram.append(int(m[0], 16))
 			system_ram.append(int(m[1], 16))
-		if m[2].strip() == 'Persistent Memory':
+		elif memory_type == 'Persistent Memory':
 			pmem.append(int(m[0], 16))
 			pmem.append(int(m[1], 16))
 
@@ -75,6 +76,7 @@ def is_persistent_mem(phys_addr):
 def find_memory_type(phys_addr):
 	if phys_addr == 0:
 		return "N/A"
+
 	if is_system_ram(phys_addr):
 		return "System RAM"
 
-- 
2.25.1


             reply	other threads:[~2023-01-09  9:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09  9:33 Alexander Pantyukhin [this message]
2023-01-09 20:44 ` [PATCH] tools:perf:scripts:python:mem-phys-addr fix performance Alexander Pantyukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230109093347.6639-1-apantykhin@gmail.com \
    --to=apantykhin@gmail.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).