Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf metrictroup: Split the metricgroup__add_metric function

This patch refactors metricgroup__add_metric function where some part of
it move to function metricgroup__add_metric_param. No logic change.

Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Anju T Sudhakar <anju@linux.vnet.ibm.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Mamatha Inamdar <mamatha4@linux.vnet.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@ozlabs.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lore.kernel.org/lkml/20200401203340.31402-4-kjain@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Kajol Jain and committed by
Arnaldo Carvalho de Melo
47352aba 871f9f59

+35 -25
+35 -25
tools/perf/util/metricgroup.c
··· 485 485 return false; 486 486 } 487 487 488 + static int __metricgroup__add_metric(struct strbuf *events, 489 + struct list_head *group_list, struct pmu_event *pe) 490 + { 491 + 492 + const char **ids; 493 + int idnum; 494 + struct egroup *eg; 495 + 496 + if (expr__find_other(pe->metric_expr, NULL, &ids, &idnum) < 0) 497 + return -EINVAL; 498 + 499 + if (events->len > 0) 500 + strbuf_addf(events, ","); 501 + 502 + if (metricgroup__has_constraint(pe)) 503 + metricgroup__add_metric_non_group(events, ids, idnum); 504 + else 505 + metricgroup__add_metric_weak_group(events, ids, idnum); 506 + 507 + eg = malloc(sizeof(*eg)); 508 + if (!eg) 509 + return -ENOMEM; 510 + 511 + eg->ids = ids; 512 + eg->idnum = idnum; 513 + eg->metric_name = pe->metric_name; 514 + eg->metric_expr = pe->metric_expr; 515 + eg->metric_unit = pe->unit; 516 + list_add_tail(&eg->nd, group_list); 517 + 518 + return 0; 519 + } 520 + 488 521 static int metricgroup__add_metric(const char *metric, struct strbuf *events, 489 522 struct list_head *group_list) 490 523 { ··· 537 504 continue; 538 505 if (match_metric(pe->metric_group, metric) || 539 506 match_metric(pe->metric_name, metric)) { 540 - const char **ids; 541 - int idnum; 542 - struct egroup *eg; 543 507 544 508 pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); 545 509 546 - if (expr__find_other(pe->metric_expr, 547 - NULL, &ids, &idnum) < 0) 548 - continue; 549 - if (events->len > 0) 550 - strbuf_addf(events, ","); 551 - 552 - if (metricgroup__has_constraint(pe)) 553 - metricgroup__add_metric_non_group(events, ids, idnum); 554 - else 555 - metricgroup__add_metric_weak_group(events, ids, idnum); 556 - 557 - eg = malloc(sizeof(struct egroup)); 558 - if (!eg) { 559 - ret = -ENOMEM; 510 + ret = __metricgroup__add_metric(events, group_list, pe); 511 + if (ret == -ENOMEM) 560 512 break; 561 - } 562 - eg->ids = ids; 563 - eg->idnum = idnum; 564 - eg->metric_name = pe->metric_name; 565 - eg->metric_expr = pe->metric_expr; 566 - eg->metric_unit = pe->unit; 567 - list_add_tail(&eg->nd, group_list); 568 - ret = 0; 569 513 } 570 514 } 571 515 return ret;