diff options
-rw-r--r-- | tools/perf/util/sort.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 1958637cf136..289df9d1e65a 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
@@ -1446,12 +1446,47 @@ static const char *get_default_sort_order(void) | |||
1446 | return default_sort_orders[sort__mode]; | 1446 | return default_sort_orders[sort__mode]; |
1447 | } | 1447 | } |
1448 | 1448 | ||
1449 | static int setup_sort_order(void) | ||
1450 | { | ||
1451 | char *new_sort_order; | ||
1452 | |||
1453 | /* | ||
1454 | * Append '+'-prefixed sort order to the default sort | ||
1455 | * order string. | ||
1456 | */ | ||
1457 | if (!sort_order || is_strict_order(sort_order)) | ||
1458 | return 0; | ||
1459 | |||
1460 | if (sort_order[1] == '\0') { | ||
1461 | error("Invalid --sort key: `+'"); | ||
1462 | return -EINVAL; | ||
1463 | } | ||
1464 | |||
1465 | /* | ||
1466 | * We allocate new sort_order string, but we never free it, | ||
1467 | * because it's checked over the rest of the code. | ||
1468 | */ | ||
1469 | if (asprintf(&new_sort_order, "%s,%s", | ||
1470 | get_default_sort_order(), sort_order + 1) < 0) { | ||
1471 | error("Not enough memory to set up --sort"); | ||
1472 | return -ENOMEM; | ||
1473 | } | ||
1474 | |||
1475 | sort_order = new_sort_order; | ||
1476 | return 0; | ||
1477 | } | ||
1478 | |||
1449 | static int __setup_sorting(void) | 1479 | static int __setup_sorting(void) |
1450 | { | 1480 | { |
1451 | char *tmp, *tok, *str; | 1481 | char *tmp, *tok, *str; |
1452 | const char *sort_keys = sort_order; | 1482 | const char *sort_keys; |
1453 | int ret = 0; | 1483 | int ret = 0; |
1454 | 1484 | ||
1485 | ret = setup_sort_order(); | ||
1486 | if (ret) | ||
1487 | return ret; | ||
1488 | |||
1489 | sort_keys = sort_order; | ||
1455 | if (sort_keys == NULL) { | 1490 | if (sort_keys == NULL) { |
1456 | if (is_strict_order(field_order)) { | 1491 | if (is_strict_order(field_order)) { |
1457 | /* | 1492 | /* |