def test_process_start_time(self):
     # Mostly just a smoke test.
     start_t_ms = timestamp.process_start_time_ms()
     age_ms = timestamp.process_age_ms()
     now = timestamp.now_ms()
     self.assertTrue(start_t_ms < now)
     self.assertTrue(((start_t_ms + age_ms) - now) < 10)
Exemple #2
0
 def test_process_start_time(self):
     # Mostly just a smoke test.
     start_t_ms = timestamp.process_start_time_ms()
     age_ms = timestamp.process_age_ms()
     now = timestamp.now_ms()
     self.assertTrue(start_t_ms < now)
     self.assertTrue(((start_t_ms + age_ms) - now) < 10)
    def html(self):
        now_ms = timestamp.now_ms()
        # Note my use of nested tables.  I suck at HTML.
        contents = ["<table border=1 cellpadding=4><tr><td><table>"]
        def add(key, val):
            contents.append(
                "<tr><td><i>%s</i></td><td>%s</td></tr>" % (key, val))
        def add_since_ms(key, ts_ms):
            add(key, "%s (%s ago)" % (
                    timestamp.get_pretty_ms(ts_ms),
                    timestamp.get_human_readable_duration_ms(now_ms-ts_ms)))

        add("start time", timestamp.get_pretty_ms(self.start_timestamp_ms))

        duration_ms = self.last_timestamp_ms - self.start_timestamp_ms
        add("duration", timestamp.get_human_readable_duration_ms(duration_ms))

        if self.num_frames:
            add("frames", "%d / %.2fM" % (self.num_frames,
                                          float(self.size_frames) / (1 << 20)))

            subtable = ["<table cellpadding=2>"]
            vbr = 0
            for key, num in sorted(self.freq_frame_kbps.items()):
                perc = 100.0 * num / self.num_frames
                vbr += float(key * num) / self.num_frames
                subtable.append(
                    "<tr><td>%d kbps</td><td>%.1f%%</td><td>%d</td></tr>" %
                    (key, perc, num))
            subtable.append("</table>")
            add("frame distribution", "".join(subtable))
            add("average bit rate", "%.2f kbps" % vbr)

            since_last_ms = now_ms - self.last_frame_timestamp_ms
            add_since_ms("last frame", self.last_frame_timestamp_ms)

            frame_span_ms = (self.last_frame_timestamp_ms -
                             self.first_frame_timestamp_ms)
            add("frame deficit",
                "%.1fms" % (frame_span_ms - self.duration_frames_ms))

        if self.num_blocks:
            add("junk blocks", "%d / %db" % (
                    self.num_blocks, self.size_blocks))
            add_since_ms("last junk", self.last_block_timestamp_ms)

        if self.errors:
            error_list = [
                "%s - %s / %s / %s" % (
                    timestamp.get_pretty_ms(err.start_timestamp_ms),
                    err.error_type, err.error_code, err.error_text)
                for err in reversed(self.errors)]
            add("errors", "<br>".join(error_list))


        contents.append("</table></td></tr></table>")
        return "\n".join(contents)
Exemple #4
0
 def _process_message(self, msg):
     info = [msg.message_type]
     if msg.message_type == message.FRAME:
         info.append(str(msg.mp3_header))
     output = "%s: %s\n" % (timestamp.get_human_readable_ms(
         timestamp.now_ms()), " / ".join(info))
     if msg.message_type == message.BLOCK:
         output += "length = %d\n%r\n" % (len(msg.payload), msg.payload)
     elif msg.message_type == message.RESPONSE:
         output += "".join(
             ["%s: %s\n" % x for x in msg.http_headers.items()])
     print output.strip()
     self._fh.write(output)
Exemple #5
0
 def _process_message(self, msg):
     info = [msg.message_type]
     if msg.message_type == message.FRAME:
         info.append(str(msg.mp3_header))
     output = "%s: %s\n" % (
         timestamp.get_human_readable_ms(timestamp.now_ms()),
         " / ".join(info))
     if msg.message_type == message.BLOCK:
         output += "length = %d\n%r\n" % (len(msg.payload), msg.payload)
     elif msg.message_type == message.RESPONSE:
         output += "".join(["%s: %s\n" % x for x in msg.http_headers.items()])
     print output.strip()
     self._fh.write(output)
    def __init__(self, prefix, start_ms=None):
        self._prefix = prefix
        self._start_ms = start_ms or timestamp.now_ms()
        self._end_ms = None
        self.duration_ms = 0
        self.frame_count = 0
        self.frame_size = 0
        self._sha1_calc = hashlib.sha1()

        self.path = "%s-%s.mp3" % (
            self._prefix, timestamp.get_human_readable_ms(self._start_ms))
        # The requested file should't already exist.  If so, delete it.
        try:
            os.unlink(self.path)
        except OSError, ex:
            if ex.errno != errno.ENOENT:
                raise ex
    def __init__(self, prefix, start_ms=None):
        self._prefix = prefix
        self._start_ms = start_ms or timestamp.now_ms()
        self._end_ms = None
        self.duration_ms = 0
        self.frame_count = 0
        self.frame_size = 0
        self._sha1_calc = hashlib.sha1()

        self.path = "%s-%s.mp3" % (
            self._prefix, timestamp.get_human_readable_ms(self._start_ms))
        # The requested file should't already exist.  If so, delete it.
        try:
            os.unlink(self.path)
        except OSError, ex:
            if ex.errno != errno.ENOENT:
                raise ex
    def html(self):
        now_ms = timestamp.now_ms()
        # Note my use of nested tables.  I suck at HTML.
        contents = ["<table border=1 cellpadding=4><tr><td><table>"]

        def add(key, val):
            contents.append("<tr><td><i>%s</i></td><td>%s</td></tr>" %
                            (key, val))

        def add_since_ms(key, ts_ms):
            add(
                key, "%s (%s ago)" %
                (timestamp.get_pretty_ms(ts_ms),
                 timestamp.get_human_readable_duration_ms(now_ms - ts_ms)))

        add("start time", timestamp.get_pretty_ms(self.start_timestamp_ms))

        duration_ms = self.last_timestamp_ms - self.start_timestamp_ms
        add("duration", timestamp.get_human_readable_duration_ms(duration_ms))

        if self.num_frames:
            add(
                "frames", "%d / %.2fM" %
                (self.num_frames, float(self.size_frames) / (1 << 20)))

            subtable = ["<table cellpadding=2>"]
            vbr = 0
            for key, num in sorted(self.freq_frame_kbps.items()):
                perc = 100.0 * num / self.num_frames
                vbr += float(key * num) / self.num_frames
                subtable.append(
                    "<tr><td>%d kbps</td><td>%.1f%%</td><td>%d</td></tr>" %
                    (key, perc, num))
            subtable.append("</table>")
            add("frame distribution", "".join(subtable))
            add("average bit rate", "%.2f kbps" % vbr)

            since_last_ms = now_ms - self.last_frame_timestamp_ms
            add_since_ms("last frame", self.last_frame_timestamp_ms)

            frame_span_ms = (self.last_frame_timestamp_ms -
                             self.first_frame_timestamp_ms)
            add("frame deficit",
                "%.1fms" % (frame_span_ms - self.duration_frames_ms))

        if self.num_blocks:
            add("junk blocks",
                "%d / %db" % (self.num_blocks, self.size_blocks))
            add_since_ms("last junk", self.last_block_timestamp_ms)

        if self.errors:
            error_list = [
                "%s - %s / %s / %s" %
                (timestamp.get_pretty_ms(err.start_timestamp_ms),
                 err.error_type, err.error_code, err.error_text)
                for err in reversed(self.errors)
            ]
            add("errors", "<br>".join(error_list))

        contents.append("</table></td></tr></table>")
        return "\n".join(contents)
 def _now_ms(self):
     """Returns the current time in integral milliseconds since the epoch.
     """
     return timestamp.now_ms()
Exemple #10
0
 def _now_ms(self):
     """Returns the current time in integral milliseconds since the epoch.
     """
     return timestamp.now_ms()