From patchwork Tue Sep 12 11:12:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Sojka X-Patchwork-Id: 812779 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="L00u9hfz"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xs2Ks6hYqz9s7g for ; Tue, 12 Sep 2017 21:16:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eJ2MGoPA9mhAZqF7cS4WKb4j2p/8gC+hRZdvuYvgSGU=; b=L00u9hfzGtfmA/ AwSmWyt81/PfqwwyiW2l2H9J+IfSKgaq6ZPrfBVdEWXvbAtQ4NYtsD91xZ2bbpJGy5FH96BY7iTuA syPX3BXERtH1PjSwoP1oRBBnD3GGI6VD+KdqIySpRmNul7jtwt5vBQc09KN5i4Yyp8b60JMYVIWAl Z1Ue18qn1wr3xWu5rTZjyAr5wrpEdZXq5xtBoRrd3ljS6C+3+DnNqA2qJAXnCFJesSL0FategS/bm UZftlix5krpIi9u/0LdbC9CWyQqG5bXFkkdtuwg4onOyxrQbPCK61JyucNXuGYaBbeHLuutiLYcmC QLrd6F1MvVUjyxHbskjw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1drjAp-0007Nw-BQ; Tue, 12 Sep 2017 11:16:11 +0000 Received: from smtpx.feld.cvut.cz ([147.32.192.33]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1drj8i-0004Yh-VU for lede-dev@lists.infradead.org; Tue, 12 Sep 2017 11:14:06 +0000 Received: from localhost (unknown [192.168.200.7]) by smtpx.feld.cvut.cz (Postfix) with ESMTP id E1429DC3DC; Tue, 12 Sep 2017 13:13:15 +0200 (CEST) X-Virus-Scanned: IMAP STYX AMAVIS Received: from smtpx.feld.cvut.cz ([192.168.200.6]) by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new, port 10054) with ESMTP id yRzERkUB0CTE; Tue, 12 Sep 2017 13:13:14 +0200 (CEST) Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34]) by smtpx.feld.cvut.cz (Postfix) with ESMTP id 2A4F4DC3D9; Tue, 12 Sep 2017 13:13:13 +0200 (CEST) Received: from wsh by steelpick.2x.cz with local (Exim 4.89) (envelope-from ) id 1drj7x-0008EM-3b; Tue, 12 Sep 2017 13:13:13 +0200 From: Michal Sojka To: lede-dev@lists.infradead.org Date: Tue, 12 Sep 2017 13:12:37 +0200 Message-Id: <20170912111250.31576-8-sojkam1@fel.cvut.cz> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170912111250.31576-1-sojkam1@fel.cvut.cz> References: <20170912111250.31576-1-sojkam1@fel.cvut.cz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170912_041401_264342_1D069AB0 X-CRM114-Status: UNSURE ( 9.28 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [147.32.192.33 listed in list.dnswl.org] -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Subject: [LEDE-DEV] [PATCH procd 05/17] utrace: Sort syscalls by number of invocations X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Sojka MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org seccomp and service jailing announce email [1] mentioned that "utrace tool will sort the syscalls by the number of invocations". The code did not do that until this commit. [1] https://lists.openwrt.org/pipermail/openwrt-devel/2015-March/032197.html Signed-off-by: Michal Sojka --- trace/trace.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/trace/trace.c b/trace/trace.c index 65fe067..35bc548 100644 --- a/trace/trace.c +++ b/trace/trace.c @@ -77,6 +77,16 @@ static void set_syscall(const char *name, int val) } } +struct syscall { + int syscall; + int count; +}; + +static int cmp_count(const void *a, const void *b) +{ + return ((struct syscall*)b)->count - ((struct syscall*)a)->count; +} + static void print_syscalls(int policy, const char *json) { void *c; @@ -88,19 +98,29 @@ static void print_syscalls(int policy, const char *json) set_syscall("exit_group", 1); set_syscall("exit", 1); + struct syscall sorted[ARRAY_SIZE(syscall_names)]; + + for (i = 0; i < ARRAY_SIZE(syscall_names); i++) { + sorted[i].syscall = i; + sorted[i].count = syscall_count[i]; + } + + qsort(sorted, ARRAY_SIZE(syscall_names), sizeof(sorted[0]), cmp_count); + blob_buf_init(&b, 0); c = blobmsg_open_array(&b, "whitelist"); for (i = 0; i < ARRAY_SIZE(syscall_names); i++) { - if (!syscall_count[i]) - continue; - if (syscall_names[i]) { + int sc = sorted[i].syscall; + if (!sorted[i].count) + break; + if (syscall_names[sc]) { if (debug) printf("syscall %d (%s) was called %d times\n", - i, syscall_names[i], syscall_count[i]); - blobmsg_add_string(&b, NULL, syscall_names[i]); + sc, syscall_names[sc], sorted[i].count); + blobmsg_add_string(&b, NULL, syscall_names[sc]); } else { - ERROR("no name found for syscall(%d)\n", i); + ERROR("no name found for syscall(%d)\n", sc); } } blobmsg_close_array(&b, c);