From patchwork Tue Dec 17 05:15:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cleber Rosa X-Patchwork-Id: 11296691 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5305B921 for ; Tue, 17 Dec 2019 05:28:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 284B52072B for ; Tue, 17 Dec 2019 05:28:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HaS25IoO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 284B52072B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ih5Pl-0005iM-Sm for patchwork-qemu-devel@patchwork.kernel.org; Tue, 17 Dec 2019 00:28:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52261) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ih5DJ-0003Kz-U5 for qemu-devel@nongnu.org; Tue, 17 Dec 2019 00:16:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ih5DI-0003cj-Ge for qemu-devel@nongnu.org; Tue, 17 Dec 2019 00:16:05 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:28556 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ih5DI-0003bC-DK for qemu-devel@nongnu.org; Tue, 17 Dec 2019 00:16:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576559763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jnxf8sfzIAVFpqegiNwwqTzgx0xhyT5dLDF1Z50dmzM=; b=HaS25IoO696Uhc6BNZFao/EL591fk5l5A3NrJOe53X9902e8+eDU2XlbeZmcO9UMlIyYzO gh5HkMqKw0vnr6aS/FvRvN8U5YgDOxQbI+POceYg23R5JB0nNbTnf9nrj6Zkm+IHmh0aUU +3Yd18S6ztxAgmNy5GWr1i+j3P9eMc0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-1VB2ToWuMsW5DgTq33ZYxQ-1; Tue, 17 Dec 2019 00:15:58 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A3BB8017DF; Tue, 17 Dec 2019 05:15:57 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-6.gru2.redhat.com [10.97.116.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A17F419C4F; Tue, 17 Dec 2019 05:15:48 +0000 (UTC) From: Cleber Rosa To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 04/15] analyze-migration.py: replace numpy with python 3.2 Date: Tue, 17 Dec 2019 00:15:10 -0500 Message-Id: <20191217051521.1239-5-crosa@redhat.com> In-Reply-To: <20191217051521.1239-1-crosa@redhat.com> References: <20191217051521.1239-1-crosa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 1VB2ToWuMsW5DgTq33ZYxQ-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Beraldo Leal , =?utf-8?q?A?= =?utf-8?q?lex_Benn=C3=A9e?= , Fabien Chouteau , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , KONRAD Frederic , qemu-ppc@nongnu.org, Wainer dos Santos Moschetta , Willian Rampazzo , Cleber Rosa , =?utf-8?q?Herv=C3=A9_Poussineau?= , Aleksandar Rikalo , =?utf-8?q?Philippe_Mathieu?= =?utf-8?q?-Daud=C3=A9?= , Aurelien Jarno , Eduardo Habkost Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Use int.from_bytes() from python 3.2 instead. Signed-off-by: Marc-André Lureau Message-Id: <20191127101038.327080-3-marcandre.lureau@redhat.com> Reviewed-by: Eduardo Habkost Signed-off-by: Eduardo Habkost Signed-off-by: Cleber Rosa --- scripts/analyze-migration.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py index 2b835d9b70..96a31d3974 100755 --- a/scripts/analyze-migration.py +++ b/scripts/analyze-migration.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Migration Stream Analyzer # @@ -17,12 +17,18 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, see . -from __future__ import print_function -import numpy as np import json import os import argparse import collections +import struct +import sys + + +MIN_PYTHON = (3, 2) +if sys.version_info < MIN_PYTHON: + sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON) + def mkdir_p(path): try: @@ -30,29 +36,26 @@ def mkdir_p(path): except OSError: pass + class MigrationFile(object): def __init__(self, filename): self.filename = filename self.file = open(self.filename, "rb") def read64(self): - return np.asscalar(np.fromfile(self.file, count=1, dtype='>i8')[0]) + return int.from_bytes(self.file.read(8), byteorder='big', signed=True) def read32(self): - return np.asscalar(np.fromfile(self.file, count=1, dtype='>i4')[0]) + return int.from_bytes(self.file.read(4), byteorder='big', signed=True) def read16(self): - return np.asscalar(np.fromfile(self.file, count=1, dtype='>i2')[0]) + return int.from_bytes(self.file.read(2), byteorder='big', signed=True) def read8(self): - return np.asscalar(np.fromfile(self.file, count=1, dtype='>i1')[0]) + return int.from_bytes(self.file.read(1), byteorder='big', signed=True) def readstr(self, len = None): - if len is None: - len = self.read8() - if len == 0: - return "" - return np.fromfile(self.file, count=1, dtype=('S%d' % len))[0] + return self.readvar(len).decode('utf-8') def readvar(self, size = None): if size is None: @@ -275,7 +278,7 @@ class VMSDFieldGeneric(object): return str(self.__str__()) def __str__(self): - return " ".join("{0:02x}".format(ord(c)) for c in self.data) + return " ".join("{0:02x}".format(c) for c in self.data) def getDict(self): return self.__str__() @@ -307,8 +310,8 @@ class VMSDFieldInt(VMSDFieldGeneric): def read(self): super(VMSDFieldInt, self).read() - self.sdata = np.fromstring(self.data, count=1, dtype=(self.sdtype))[0] - self.udata = np.fromstring(self.data, count=1, dtype=(self.udtype))[0] + self.sdata = int.from_bytes(self.data, byteorder='big', signed=True) + self.udata = int.from_bytes(self.data, byteorder='big', signed=False) self.data = self.sdata return self.data @@ -363,7 +366,7 @@ class VMSDFieldStruct(VMSDFieldGeneric): array_len = field.pop('array_len') field['index'] = 0 new_fields.append(field) - for i in xrange(1, array_len): + for i in range(1, array_len): c = field.copy() c['index'] = i new_fields.append(c)