def dump_action_profile(pipe_name, action_profiles, p4_action_profile,
                        keep_pragmas=False):
    # check that the same action profile is not referenced across multiple
    # control flows. This is somewhat of an artifical restriction imposed by the
    # pipeline abstraction in the JSON
    if p4_action_profile in dump_action_profile.referenced:
        if dump_action_profile.referenced[p4_action_profile] != pipe_name:
            LOG_CRITICAL("action profile {} cannot be referenced in different "
                         "control flows".format(p4_action_profile.name))
    else:
        dump_action_profile.referenced[p4_action_profile] = pipe_name
        act_prof_dict = OrderedDict()
        act_prof_dict["name"] = p4_action_profile.name
        act_prof_dict["id"] = dump_action_profile.act_prof_id
        dump_action_profile.act_prof_id += 1
        act_prof_dict["max_size"] = p4_action_profile.size
        if p4_action_profile.selector is not None:
            p4_selector = p4_action_profile.selector
            selector = OrderedDict()
            if type(p4_selector.selection_key.algorithm) is list:
                # we already print a warning for this case in dump_calculations
                selector["algo"] = p4_selector.selection_key.algorithm[0]
            else:
                selector["algo"] = p4_selector.selection_key.algorithm
            elements = []
            assert(len(p4_selector.selection_key.input) == 1)
            for field in p4_selector.selection_key.input[0].fields:
                element_dict = OrderedDict()
                if type(field) is not p4.p4_field:  # pragma: no cover
                    LOG_CRITICAL("only fields supported in field lists")
                element_dict["type"] = "field"
                element_dict["value"] = format_field_ref(field)
                elements.append(element_dict)
            selector["input"] = elements
            act_prof_dict["selector"] = selector

        if keep_pragmas:
            add_pragmas(act_prof_dict, p4_action_profile)

        action_profiles.append(act_prof_dict)