From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id EA8982B84 for ; Fri, 14 Apr 2017 07:40:34 +0200 (CEST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Apr 2017 22:40:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,197,1488873600"; d="scan'208";a="88893258" Received: from shwdeisgchi083.ccr.corp.intel.com (HELO [10.239.67.171]) ([10.239.67.171]) by fmsmga005.fm.intel.com with ESMTP; 13 Apr 2017 22:40:31 -0700 To: Olivier Matz , dev@dpdk.org Cc: david.marchand@6wind.com, bruce.richardson@intel.com, thomas.monjalon@6wind.com, keith.wiles@intel.com, stephen@networkplumber.org, "De Lara Guarch, Pablo" References: <20170329155323.4760-1-olivier.matz@6wind.com> <20170404164040.24132-1-olivier.matz@6wind.com> <20170404164040.24132-4-olivier.matz@6wind.com> From: "Tan, Jianfeng" Message-ID: <9f3e0c9e-9e95-1c7e-7f68-d74c731e6313@intel.com> Date: Fri, 14 Apr 2017 13:40:31 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <20170404164040.24132-4-olivier.matz@6wind.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Subject: Re: [dpdk-dev] [PATCH v3 3/8] eal: change several log levels matching a regexp X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Apr 2017 05:40:35 -0000 Hi Olivier, On 4/5/2017 12:40 AM, Olivier Matz wrote: > Introduce a function to set the log level of several log types that > match a regular expression. > > Signed-off-by: Olivier Matz > --- > lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + > lib/librte_eal/common/eal_common_log.c | 21 +++++++++++++++++++++ > lib/librte_eal/common/include/rte_log.h | 12 ++++++++++++ > lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + > 4 files changed, 35 insertions(+) > > diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map > index bd63ea66b..de74ff9ff 100644 > --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map > +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map > @@ -189,5 +189,6 @@ DPDK_17.05 { > rte_log_dump; > rte_log_register; > rte_log_set_level; > + rte_log_set_level_regexp; > > } DPDK_17.02; > diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c > index 90326215b..d02689390 100644 > --- a/lib/librte_eal/common/eal_common_log.c > +++ b/lib/librte_eal/common/eal_common_log.c > @@ -37,6 +37,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -132,6 +133,26 @@ rte_log_set_level(uint32_t type, uint32_t level) > return 0; > } > > +/* set level */ > +int > +rte_log_set_level_regexp(const char *pattern, uint32_t level) > +{ > + regex_t r; > + size_t i; > + > + if (level > RTE_LOG_DEBUG) > + return -1; > + > + for (i = 0; i < rte_logs.dynamic_types_len; i++) { > + if (rte_logs.dynamic_types[i].name == NULL) > + continue; > + if (regexec(&r, pattern, 0, NULL, 0) == 0) > + rte_logs.dynamic_types[i].loglevel = level; When I try this option, it causes segment fault. The problem might lie in this function. As far as I know, when we use regexec(), we need to compile a regular expression firstly using regcomp(); and then call regexec() with the compiled pattern with the full string. In other words: regcomp(&r, pattern, 0); for (i = 0; i < rte_logs.dynamic_types_len; i++) { ... if (regexec(&r, rte_logs.dynamic_types[i].name, 0, NULL, 0) == 0) rte_logs.dynamic_types[i].loglevel = level; } Thanks, Jianfeng > + } > + > + return 0; > +} > + > /* get the current loglevel for the message beeing processed */ > int rte_log_cur_msg_loglevel(void) > { > diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h > index 97e0c5e52..ce48b0785 100644 > --- a/lib/librte_eal/common/include/rte_log.h > +++ b/lib/librte_eal/common/include/rte_log.h > @@ -157,6 +157,18 @@ uint32_t rte_get_log_type(void); > /** > * Set the log level for a given type. > * > + * @param pattern > + * The regexp identifying the log type. > + * @param level > + * The level to be set. > + * @return > + * 0 on success, a negative value if level is invalid. > + */ > +int rte_log_set_level_regexp(const char *pattern, uint32_t level); > + > +/** > + * Set the log level for a given type. > + * > * @param logtype > * The log type identifier. > * @param level > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map > index ef48500e9..f70b4b937 100644 > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map > @@ -193,5 +193,6 @@ DPDK_17.05 { > rte_log_dump; > rte_log_register; > rte_log_set_level; > + rte_log_set_level_regexp; > > } DPDK_17.02;