From patchwork Tue Apr 21 17:04:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luka Perkov X-Patchwork-Id: 463408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 241141401AD for ; Wed, 22 Apr 2015 03:08:14 +1000 (AEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id AA2F328BEEC; Tue, 21 Apr 2015 19:05:18 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable version=3.3.2 Received: from localhost (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 3BD3328BC75; Tue, 21 Apr 2015 19:04:52 +0200 (CEST) X-Virus-Scanned: at arrakis.dune.hu Received: from t530.lan (cpe-94-253-155-145.zg.cable.xnet.hr [94.253.155.145]) by arrakis.dune.hu (Postfix) with ESMTPSA id DCBF228BEDD; Tue, 21 Apr 2015 19:04:44 +0200 (CEST) From: Luka Perkov To: openwrt-devel@lists.openwrt.org Date: Tue, 21 Apr 2015 19:04:46 +0200 Message-Id: <1429635886-4895-4-git-send-email-luka@openwrt.org> X-Mailer: git-send-email 2.3.5 In-Reply-To: <1429635886-4895-1-git-send-email-luka@openwrt.org> References: <1429635886-4895-1-git-send-email-luka@openwrt.org> Cc: Luka Perkov Subject: [OpenWrt-Devel] [PATCH 4/4] [ubox] logd: optimize notify function X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" No need to construct every time the same blob_buf for each client in the list. Signed-off-by: Luka Perkov --- log/logd.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/log/logd.c b/log/logd.c index a4335ea..27d3cac 100644 --- a/log/logd.c +++ b/log/logd.c @@ -147,15 +147,17 @@ ubus_notify_log(struct log_head *l) if (list_empty(&clients)) return; - list_for_each_entry(c, &clients, list) { - blob_buf_init(&b, 0); - blobmsg_add_string(&b, "msg", l->data); - blobmsg_add_u32(&b, "id", l->id); - blobmsg_add_u32(&b, "priority", l->priority); - blobmsg_add_u32(&b, "source", l->source); - blobmsg_add_u64(&b, "time", (((__u64) l->ts.tv_sec) * 1000) + (l->ts.tv_nsec / 1000000)); + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "msg", l->data); + blobmsg_add_u32(&b, "id", l->id); + blobmsg_add_u32(&b, "priority", l->priority); + blobmsg_add_u32(&b, "source", l->source); + blobmsg_add_u64(&b, "time", (((__u64) l->ts.tv_sec) * 1000) + (l->ts.tv_nsec / 1000000)); + + list_for_each_entry(c, &clients, list) ustream_write(&c->s.stream, (void *) b.head, blob_len(b.head) + sizeof(struct blob_attr), false); - } + + blob_buf_free(&b); } static void