From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759489AbcGKPzG (ORCPT ); Mon, 11 Jul 2016 11:55:06 -0400 Received: from smtprelay0089.hostedemail.com ([216.40.44.89]:57887 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755085AbcGKPzD (ORCPT ); Mon, 11 Jul 2016 11:55:03 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 50,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::,RULES_HIT:41:355:379:541:599:800:960:967:973:982:988:989:1260:1263:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2525:2553:2560:2563:2682:2685:2691:2693:2859:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3355:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4605:5007:6119:6261:7875:7901:7903:8603:8957:9025:10004:10400:10848:10967:11026:11232:11257:11473:11657:11658:11914:12043:12296:12438:12517:12519:12555:12740:13138:13231:13439:14106:14180:14181:14659:14721:21080:21433:30012:30036:30054:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: wash23_47eb683a1b919 X-Filterd-Recvd-Size: 4031 Date: Mon, 11 Jul 2016 11:54:52 -0400 From: Steven Rostedt To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , lkml , David Ahern , Ingo Molnar , Namhyung Kim , Peter Zijlstra Subject: Re: [PATCH 10/10] perf script python: Fix string vs byte array resolving Message-ID: <20160711115452.02ba1d6c@gandalf.local.home> In-Reply-To: <1468148882-10362-11-git-send-email-jolsa@kernel.org> References: <1468148882-10362-1-git-send-email-jolsa@kernel.org> <1468148882-10362-11-git-send-email-jolsa@kernel.org> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 10 Jul 2016 13:08:02 +0200 Jiri Olsa wrote: > Jirka reported that python code returns all arrays as strings. > This makes impossible to get all items for byte array tracepoint > field containing 0x00 value item. > > Fixing this by scanning full length of the array and returning > it as PyByteArray object in case non printable byte is found. > > Cc: Steven Rostedt (Red Hat) > Reported-and-tested-by: Jiri Pirko > Link: http://lkml.kernel.org/n/tip-22f4vhhz5uytegkggy1on8u3@git.kernel.org > Signed-off-by: Jiri Olsa > --- > .../util/scripting-engines/trace-event-python.c | 34 ++++++++++++++++++---- > 1 file changed, 28 insertions(+), 6 deletions(-) > > diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c > index ff134700bf30..75e9790ebb96 100644 > --- a/tools/perf/util/scripting-engines/trace-event-python.c > +++ b/tools/perf/util/scripting-engines/trace-event-python.c > @@ -386,6 +386,16 @@ exit: > return pylist; > } > > +static int is_printable_array(char *p, unsigned int len) > +{ > + unsigned int i; > + > + for (i = 0; i < len; i++) > + if (!isprint(p[i]) && !isspace(p[i])) > + return 0; I believe this will return the wrong result if you pass in a string that has '\0' in it. Try it out: char a[] = "hello"; printf("a=%s is %d\n", a, is_printable_array(a, sizeof(a))); and see what you get? -- Steve > + > + return 1; > +} > > static void python_process_tracepoint(struct perf_sample *sample, > struct perf_evsel *evsel, > @@ -457,14 +467,26 @@ static void python_process_tracepoint(struct perf_sample *sample, > pydict_set_item_string_decref(dict, "common_callchain", callchain); > } > for (field = event->format.fields; field; field = field->next) { > - if (field->flags & FIELD_IS_STRING) { > - int offset; > + unsigned int offset, len; > + unsigned long long val; > + > + if (field->flags & FIELD_IS_ARRAY) { > + offset = field->offset; > + len = field->size; > if (field->flags & FIELD_IS_DYNAMIC) { > - offset = *(int *)(data + field->offset); > + val = pevent_read_number(scripting_context->pevent, > + data + offset, len); > + offset = val; > + len = offset >> 16; > offset &= 0xffff; > - } else > - offset = field->offset; > - obj = PyString_FromString((char *)data + offset); > + } > + if (field->flags & FIELD_IS_STRING && > + is_printable_array(data + offset, len)) { > + obj = PyString_FromString((char *) data + offset); > + } else { > + obj = PyByteArray_FromStringAndSize((const char *) data + offset, len); > + field->flags &= ~FIELD_IS_STRING; > + } > } else { /* FIELD_IS_NUMERIC */ > obj = get_field_numeric_entry(event, field, data); > }