code: def test_aggregate_stats_sorting():
      sort_by_options = {
          "total": "Total",
          "avg": "Avg",
          "min": "Min",
          "max": "Max",
          "count": "Count",
      }
      ascending_options = [False, True]
  
      def check_ascending(lst, asc):
          assert lst == sorted(lst, reverse=not asc)
  
      def check_sorting(debug_str, sort_by, ascending):
          target_dict = json.loads(
              debug_str, object_pairs_hook=OrderedDict
          )
          lst = []
          for _, domain in target_dict["Time"].items():
              lst = [
                  item[sort_by_options[sort_by]]
                  for item_name, item in domain.items()
              ]
              check_ascending(lst, ascending)
          # Memory items do not have stat 'Total'
          if sort_by != "total":
              for _, domain in target_dict["Memory"].items():
                  lst = [
                      item[sort_by_options[sort_by]]
                      for item_name, item in domain.items()
                  ]
                  check_ascending(lst, ascending)
  
      file_name = "test_aggregate_stats_sorting.json"
      enable_profiler(file_name, True, True, True)
      test_profile_event(False)
      for sb in sort_by_options:
          for asc in ascending_options:
              debug_str = profiler.dumps(
                  format="json", sort_by=sb, ascending=asc
              )
              check_sorting(debug_str, sb, asc)
      profiler.set_state("stop")
  
imports: from __future__ import print_function
  import time
  import os
  import csv
  import json
  import numpy
  from collections import OrderedDict
  import mxnet
  from mxnet import profiler
  from mxnet.gluon import nn
  from mxnet.test_utils import is_cd_run
  from common import run_in_spawned_process
  import pytest
label_desc: Use image node_id 12 for calling a global function with example usage: test_aggregate_stats_sorting() without return types