def _line_format(name, tags, fields, timestamp=None):
    """
    Format a report as InfluxDB line format

    :param name: name of the report
    :type name: str
    :param tags: tags identifying the specific report
    :type tags: dict[str]
    :param fields: measurements of the report
    :type fields: dict[str]
    :param timestamp: when the measurement was taken, in **seconds** since the epoch
    :type timestamp: float, int or None
    """
    output_str = name
    if tags:
        output_str += ',' + ','.join('%s=%s' % (key, value) for key, value in sorted(tags.items()))
    output_str += ' '
    output_str += ','.join(('%s=%r' % (key, value)).replace("'", '"') for key, value in sorted(fields.items()))
    if timestamp is not None:
        # line protocol requires nanosecond precision, python uses seconds
        output_str += ' %d' % (timestamp * 1E9)
    return output_str + '\n'