import collections


def profile_light_trace(trace_data, indicator, frequency):
    """Profile trace data for light.

    Parameters
    ----------
    trace_data : dict
        Original trace data in light.

    indicator : list
        Indicator type to profile.

    frequency : int
        NPU frequency

    Returns
    -------
    result : list[OrderedDict]
        The results of profiler.
    """
    result = list()
    for layer in trace_data["layers"]:
        l_data = collections.OrderedDict()
        # op
        l_data["op"] = collections.OrderedDict()
        l_data["op"]["type"] = layer["ops"]
        l_data["op"]["name"] = layer["names"]
        # ddr
        if "mem" in indicator or "all" in indicator:
            l_data["memory"] = collections.OrderedDict()
            l_data["memory"]["accum_ddr"] = layer["accum_ddr"]
            l_data["memory"]["coeff_ddr"] = layer["coeff_ddr"]
            l_data["memory"]["input_ddr"] = layer["input_ddr"]
            l_data["memory"]["output_ddr"] = layer["output_ddr"]
        # cycle
        if "cycle" in indicator or "all" in indicator:
            l_data["cycle"] = layer["cycles"]
            l_data["time_ms"] = layer["cycles"] / frequency * 1000  # ms

        result.append(l_data)
    return result