Skip to content

Commit

Permalink
Add thread identifier to the elapsed time records.
Browse files Browse the repository at this point in the history
  • Loading branch information
EranGabber committed Jul 7, 2015
1 parent 612b401 commit d69df2c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions collector/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def return_elapsed(gs):
{'start_time': utilities.seconds_to_timestamp(
elapsed_record.start_time),
'what': elapsed_record.what,
'threadIdentifier': elapsed_record.thread_identifier,
'elapsed_seconds': duration})
elapsed_sum += duration
if (elapsed_min is None) or (elapsed_max is None):
Expand Down
5 changes: 4 additions & 1 deletion collector/global_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import Queue # "Queue" was renamed "queue" in Python 3.
import random
import sys
import thread
import threading
import types

Expand All @@ -30,7 +31,8 @@


ElapsedRecord = collections.namedtuple(
'ElapsedRecord', ['start_time', 'what', 'elapsed_seconds'])
'ElapsedRecord',
['start_time', 'what', 'thread_identifier', 'elapsed_seconds'])


class GlobalState(object):
Expand Down Expand Up @@ -245,6 +247,7 @@ def add_elapsed(self, start_time, url_or_fname, elapsed_seconds):

self._elapsed_queue.put(
ElapsedRecord(start_time=start_time, what=url_or_fname,
thread_identifier=thread.get_ident(),
elapsed_seconds=elapsed_seconds))

def get_elapsed(self):
Expand Down
2 changes: 2 additions & 0 deletions collector/global_state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""Tests for collector/global_state.py."""

# global imports
import thread
import time
import types
import unittest
Expand Down Expand Up @@ -46,6 +47,7 @@ def test_elapsed(self):
self.assertEqual(now, result[0].start_time)
self.assertEqual('abc', result[0].what)
self.assertEqual(13.4, result[0].elapsed_seconds)
self.assertEqual(thread.get_ident(), result[0].thread_identifier)

# Calling get_elapsed() should clear the list of elapsed times.
result = self._state.get_elapsed()
Expand Down

0 comments on commit d69df2c

Please sign in to comment.