aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/sort.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/sort.c')
-rw-r--r--tools/perf/util/sort.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index b4a805e5e440..1958637cf136 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1453,7 +1453,7 @@ static int __setup_sorting(void)
1453 int ret = 0; 1453 int ret = 0;
1454 1454
1455 if (sort_keys == NULL) { 1455 if (sort_keys == NULL) {
1456 if (field_order) { 1456 if (is_strict_order(field_order)) {
1457 /* 1457 /*
1458 * If user specified field order but no sort order, 1458 * If user specified field order but no sort order,
1459 * we'll honor it and not add default sort orders. 1459 * we'll honor it and not add default sort orders.
@@ -1639,23 +1639,36 @@ static void reset_dimensions(void)
1639 memory_sort_dimensions[i].taken = 0; 1639 memory_sort_dimensions[i].taken = 0;
1640} 1640}
1641 1641
1642bool is_strict_order(const char *order)
1643{
1644 return order && (*order != '+');
1645}
1646
1642static int __setup_output_field(void) 1647static int __setup_output_field(void)
1643{ 1648{
1644 char *tmp, *tok, *str; 1649 char *tmp, *tok, *str, *strp;
1645 int ret = 0; 1650 int ret = -EINVAL;
1646 1651
1647 if (field_order == NULL) 1652 if (field_order == NULL)
1648 return 0; 1653 return 0;
1649 1654
1650 reset_dimensions(); 1655 reset_dimensions();
1651 1656
1652 str = strdup(field_order); 1657 strp = str = strdup(field_order);
1653 if (str == NULL) { 1658 if (str == NULL) {
1654 error("Not enough memory to setup output fields"); 1659 error("Not enough memory to setup output fields");
1655 return -ENOMEM; 1660 return -ENOMEM;
1656 } 1661 }
1657 1662
1658 for (tok = strtok_r(str, ", ", &tmp); 1663 if (!is_strict_order(field_order))
1664 strp++;
1665
1666 if (!strlen(strp)) {
1667 error("Invalid --fields key: `+'");
1668 goto out;
1669 }
1670
1671 for (tok = strtok_r(strp, ", ", &tmp);
1659 tok; tok = strtok_r(NULL, ", ", &tmp)) { 1672 tok; tok = strtok_r(NULL, ", ", &tmp)) {
1660 ret = output_field_add(tok); 1673 ret = output_field_add(tok);
1661 if (ret == -EINVAL) { 1674 if (ret == -EINVAL) {
@@ -1667,6 +1680,7 @@ static int __setup_output_field(void)
1667 } 1680 }
1668 } 1681 }
1669 1682
1683out:
1670 free(str); 1684 free(str);
1671 return ret; 1685 return ret;
1672} 1686}