From patchwork Thu Oct 26 12:14:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joannah Nanjekye X-Patchwork-Id: 10028073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C97EE6022E for ; Thu, 26 Oct 2017 12:52:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B95DF28DCD for ; Thu, 26 Oct 2017 12:52:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE1C328DEB; Thu, 26 Oct 2017 12:52:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 90B93283C5 for ; Thu, 26 Oct 2017 12:52:46 +0000 (UTC) Received: from localhost ([::1]:52721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7heP-00031z-9j for patchwork-qemu-devel@patchwork.kernel.org; Thu, 26 Oct 2017 08:52:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7h3k-0000Gx-1e for qemu-devel@nongnu.org; Thu, 26 Oct 2017 08:14:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7h3f-0007Cj-AZ for qemu-devel@nongnu.org; Thu, 26 Oct 2017 08:14:52 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:45778) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7h3f-0007Bx-3L for qemu-devel@nongnu.org; Thu, 26 Oct 2017 08:14:47 -0400 Received: by mail-wm0-x241.google.com with SMTP id q124so7592221wmb.0 for ; Thu, 26 Oct 2017 05:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=5zCqZ5cnnhR8Kly9YvjuSyQHpyj2VaSfbxN+udB/OJQ=; b=MR3bfX/MelGKkvkm8N3yR5QA6Vbw8SldeUv9EVuyRn706fxebJ6feWCSThNGBNkvMN 6gpJDD6araM0xOMQHtu23I+BXSaZ3QFN8jftrPdglnRGQ/4umF0RKqjbe6MKO0xJWWaH wabw9KyY4zJ/PfjtMCGuBQWlMFBC2xlvOm/Hy7KTkOzgs9DZtvhnsSSPG25R6LRT0R+j DIpFLT4j46vdoPgB4ONaJA0qdnFM6W1FgtYlQ5l725dPkmm+rzYsi893Kdakl0+8ACDJ e5S6lXqjS1hJq5lGiqFMar3Z7f4RltRAKjr991OuvF84JHCYXqSBq4+mFKu4RJHV3Bhn aWjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=5zCqZ5cnnhR8Kly9YvjuSyQHpyj2VaSfbxN+udB/OJQ=; b=bYbkBQJRFos3PglVW2J5LQd284sZlyFsSluG8NbEM8+uvsG7UE4pRn9NyxlUaOZSVB pEHJyiZZxR2axYTU0b7h33GOkUT3dGKd9HFrpkg+QQTCLIMnHEI++ConDVr82+atcBqc HdCseDqQBRmOh1mj0nCxx9TLZgwNcwMy9MVH+AsrxsS8q+CmP2+TfXh8owbFlwmrXLyn r7G0Y5RRpcIdqE323qMA+780x84+PiBRj0LWT6MmQKMdXmpvIbIm9NYEGN6+p2IRIaxw FwWT7IsRwmWudm4im5o9D8RZiviWCEATucLXladC15oSgT5QuN1J93+yhRVwqmGAL7UL 4p4w== X-Gm-Message-State: AMCzsaXcD0I2lmgq8pPKvlkPmd27aYbtmpXaPpATJhJrdohYF6/9hCPA PIavRGTHMycJuEiLXCKoAjo= X-Google-Smtp-Source: ABhQp+TgMUviyPT1kdtsIpwo2B5lJvl1cdTVFjsgf7otO3No+bJF3cby15LUJxViso3rOYEzUO2fYA== X-Received: by 10.28.134.149 with SMTP id i143mr1332052wmd.79.1509020085692; Thu, 26 Oct 2017 05:14:45 -0700 (PDT) Received: from localhost.localdomain ([129.205.2.155]) by smtp.googlemail.com with ESMTPSA id g25sm916975wmc.16.2017.10.26.05.14.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Oct 2017 05:14:44 -0700 (PDT) From: Joannah Nanjekye To: stefanha@redhat.com Date: Thu, 26 Oct 2017 15:14:14 +0300 Message-Id: <1509020054-25434-1-git-send-email-nanjekyejoannah@gmail.com> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 X-Mailman-Approved-At: Thu, 26 Oct 2017 08:51:02 -0400 Subject: [Qemu-devel] [PATCH WIP] replace numpy with struct X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joannah Nanjekye , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch replaces the use of numpy with the standard Library struct module where possible. Signed-off-by: Joannah Nanjekye --- scripts/analyze-migration.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py index 1455387..f421012 100755 --- a/scripts/analyze-migration.py +++ b/scripts/analyze-migration.py @@ -36,23 +36,28 @@ class MigrationFile(object): self.file = open(self.filename, "rb") def read64(self): - return np.asscalar(np.fromfile(self.file, count=1, dtype='>i8')[0]) + buffer = file.read(64) + return struct.unpack('>i16', buffer)[0] def read32(self): - return np.asscalar(np.fromfile(self.file, count=1, dtype='>i4')[0]) + buffer = file.read(32) + return struct.unpack('>i8', buffer)[0] def read16(self): - return np.asscalar(np.fromfile(self.file, count=1, dtype='>i2')[0]) + buffer = file.read(16) + return struct.unpack('>i4', buffer)[0] def read8(self): - return np.asscalar(np.fromfile(self.file, count=1, dtype='>i1')[0]) + buffer = file.read(8) + return struct.unpack('>i2', buffer)[0] def readstr(self, len = None): + buffer = file.read(8) if len is None: len = self.read8() if len == 0: return "" - return np.fromfile(self.file, count=1, dtype=('S%d' % len))[0] + return np.array(struct.unpack(str(len) + 'd', buffer)[0]) def readvar(self, size = None): if size is None: @@ -303,8 +308,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 = np.array(struct.unpack(self.sdtype, self.data)[0]) + self.udata = np.array(struct.unpack(self.udtype, self.data)[0]) self.data = self.sdata return self.data