def get_task_name(ftrace, pid, cls=None):
    """Returns the execname for pid

    :param ftrace: A ftrace object with a sched_switch
        event
    :type ftrace: :mod:`trappy.ftrace.FTrace`

    :param pid: The PID of the process
    :type pid: int

    :param cls: The SchedSwitch event class (required if
        a different event is to be used)
    :type cls: :mod:`trappy.base.Base`

    :return: The execname for the PID
    """

    if not cls:
        try:
            df = ftrace.sched_switch.data_frame
        except AttributeError:
           raise ValueError("SchedSwitch event not found in ftrace")
    else:
        event = getattr(ftrace, cls.name)
        df = event.data_frame

    df = df[df["next_pid"] == pid]
    if not len(df):
        return ""
    else:
        return df["next_comm"].values[0]