Hi Arnaldo, On Fri, Mar 04, 2016 at 06:48:48PM -0300, Arnaldo Carvalho de Melo wrote: > Em Fri, Mar 04, 2016 at 11:59:38PM +0900, Namhyung Kim escreveu: > > This implements having multiple sort keys in a single hierarchy level. > > > +++ b/tools/perf/util/sort.c > > @@ -2310,18 +2310,40 @@ static int setup_sort_list(char *str, struct > > perf_evlist *evlist) > > char *tmp, *tok; > > int ret = 0; > > int level = 0; > > + int next_level = 1; > > + bool in_group = false; > > + > > + do { > > + tok = str; > > + tmp = strpbrk(str, "{}, "); > > Ok, I'll test this, but since we use lex/yacc for parsing event > descriptions, perhaps we should use it here as well? Or do you think > we're stopping at this level of complexity (I doubt) :-)
I'm not sure how the syntax of sort keys will become more complex. But I don't think we should use lex/yacc at this level of complexity Thanks, Namhyung > > > + if (tmp) { > > + if (in_group) > > + next_level = level; > > + else > > + next_level = level + 1; > > + > > + if (*tmp == '{') > > + in_group = true; > > + else if (*tmp == '}') > > + in_group = false; > > + > > + *tmp = '\0'; > > + str = tmp + 1; > > + } > > > > - for (tok = strtok_r(str, ", ", &tmp); > > - tok; tok = strtok_r(NULL, ", ", &tmp)) { > > - ret = sort_dimension__add(tok, evlist, level++); > > - if (ret == -EINVAL) { > > - error("Invalid --sort key: `%s'", tok); > > - break; > > - } else if (ret == -ESRCH) { > > - error("Unknown --sort key: `%s'", tok); > > - break; > > + if (*tok) { > > + ret = sort_dimension__add(tok, evlist, level); > > + if (ret == -EINVAL) { > > + error("Invalid --sort key: `%s'", tok); > > + break; > > + } else if (ret == -ESRCH) { > > + error("Unknown --sort key: `%s'", tok); > > + break; > > + } > > } > > - } > > + > > + level = next_level; > > + } while (tmp); > > > > return ret; > > } > > -- > > 2.7.2