lkml.org 
[lkml]   [2023]   [Jan]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] tools:perf:scripts:python:mem-phys-addr fix performance
Date
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
\
 
 \ /
  Last update: 2023-03-26 23:32    [W:0.025 / U:0.868 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site