コード例 #1
0
    def _create_trace(self):
        trace = btw.Writer(self._trace_path)
        clock = btw.Clock('test_clock')
        trace.add_clock(clock)

        integer_field_type = btw.IntegerFieldDeclaration(32)

        event_class = btw.EventClass('simple_event')
        event_class.add_field(integer_field_type, 'int_field')

        stream_class = btw.StreamClass('empty_packet_stream')
        stream_class.add_event_class(event_class)
        stream_class.clock = clock

        stream = trace.create_stream(stream_class)

        for i in range(self._expected_event_count):
            event = btw.Event(event_class)
            event.payload('int_field').value = i
            stream.append_event(event)
        stream.flush()

        # The CTF writer will not be able to populate the packet context's
        # timestamp_begin and timestamp_end fields if it is asked to flush
        # without any queued events.
        with self.assertRaises(ValueError):
            stream.flush()

        packet_context = stream.packet_context
        packet_context.field('timestamp_begin').value = 1
        packet_context.field('timestamp_end').value = 123456

        stream.flush()
コード例 #2
0
    def _create_trace(self, stream_descriptions):
        trace_path = tempfile.mkdtemp()
        trace = btw.Writer(trace_path)
        clock = btw.Clock('test_clock')
        clock.uuid = self._clock_uuid
        trace.add_clock(clock)

        integer_field_type = btw.IntegerFieldDeclaration(32)

        event_class = btw.EventClass('simple_event')
        event_class.add_field(integer_field_type, 'int_field')

        stream_class = btw.StreamClass('test_stream')
        stream_class.add_event_class(event_class)
        stream_class.clock = clock

        streams = []
        stream_entries = []
        for stream_id, stream_packets in enumerate(stream_descriptions):
            stream = trace.create_stream(stream_class)
            streams.append(stream)

            for packet in stream_packets:
                for timestamp in packet.timestamps:
                    stream_entries.append(Entry(stream_id, timestamp))
                # Mark the last inserted entry as the end of packet
                stream_entries[len(stream_entries) - 1].end_of_packet = True

        # Sort stream entries which will provide us with a time-ordered list of
        # events to insert in the streams.
        for entry in sorted(stream_entries, key=lambda entry: entry.timestamp):
            clock.time = entry.timestamp
            event = btw.Event(event_class)
            event.payload('int_field').value = entry.stream_id
            streams[entry.stream_id].append_event(event)
            if entry.end_of_packet is True:
                streams[entry.stream_id].flush()

        return trace_path
コード例 #3
0
    def _write_trace(self):
        trace = btw.Writer(self._trace_path)
        clock = btw.Clock('test_clock')
        trace.add_clock(clock)

        integer_field_type = btw.IntegerFieldDeclaration(32)

        event_class = btw.EventClass('simple_event')
        event_class.add_field(integer_field_type, 'int_field')

        stream_class = btw.StreamClass('test_stream')
        stream_class.add_event_class(event_class)
        stream_class.clock = clock

        stream_class.packet_context_type = None
        stream = trace.create_stream(stream_class)

        for i in range(self._expected_event_count):
            event = btw.Event(event_class)
            event.payload('int_field').value = i
            stream.append_event(event)
        stream.flush()

        # It is not valid for a stream to contain more than one packet
        # if it does not have content_size/packet_size info in its packet
        # context
        event = btw.Event(event_class)
        event.payload('int_field').value = 42
        stream.append_event(event)

        flush_raises = False
        try:
            stream.flush()
        except ValueError:
            flush_raises = True
        self.assertTrue(flush_raises)
        trace.flush_metadata()
コード例 #4
0
    path = max([os.path.join(directory, d) for d in os.listdir(directory)],
               key=os.path.getmtime)
else:
    path = args.input_trace
if path[-1] == "/":
    path = path[:-1]
collection.add_trace(path + "/ust/uid/1000/64-bit", 'ctf')

# Set the output trace
if args.output_trace == None:
    out_path = "/tmp/tensorflow-profiler"
else:
    out_path = args.output_trace
if not os.path.isdir(out_path):
    os.system("mkdir " + out_path)
writer = btw.Writer(out_path)

# Clock
clock_offset = 0
metadata_file = path + "/ust/uid/1000/64-bit/metadata"
with open(metadata_file, "r", errors='ignore') as f:
    lines = f.readlines()
    for l in lines:
        if "offset = " in l:
            clock_offset = int(l.split()[-1][:-1])

clock = btw.Clock('monotonic')
clock.description = 'Monotonic clock from AMD RCP'
writer.add_clock(clock)

# Environment
コード例 #5
0
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import sys
import tempfile
import babeltrace.writer as btw


trace_path = tempfile.mkdtemp()

print("Writing trace at {}".format(trace_path))
writer = btw.Writer(trace_path)

clock = btw.Clock("A_clock")
print("Clock name is \"{}\"".format(clock.name))
clock.description = "Simple clock"
print("Clock description is \"{}\"".format(clock.description))
print("Clock frequency is {}".format(clock.frequency))
print("Clock precision is {}".format(clock.precision))
print("Clock offset_seconds is {}".format(clock.offset_seconds))
print("Clock offset is {}".format(clock.offset))
print("Clock is absolute: {}".format(clock.absolute))
print("Clock time is {}".format(clock.time))
print("Clock UUID is {}".format(clock.uuid))

writer.add_clock(clock)
writer.add_environment_field("Python_version", str(sys.version_info))
コード例 #6
0
 def __init__(self, trace_path):
     if not WriterManager.instance:
         WriterManager.instance = btw.Writer(trace_path)
         WriterManager.instance.add_clock(ClockManager().get_clock())
         WriterManager.instance.add_environment_field(
             "Python_version", str(sys.version_info))
コード例 #7
0
def create_ctf(trace):
    # temporary directory holding the CTF trace
    trace_path = tempfile.mkdtemp()

    # our writer
    writer = btw.Writer(trace_path)

    # create one default clock and register it to the writer
    clock = btw.Clock('my_clock')
    clock.description = 'this is my clock'
    #clock.frequency = 3570000000
    writer.add_clock(clock)

    # create our single stream
    streams = []
    event_types = []
    for i in range(8):
        event_types.append({})
        print("iter ", i)

        # create one default stream class and assign our clock to it
        stream_class = btw.StreamClass('stream{}'.format(i))
        stream_class.clock = clock

        # create one default event class
        event_class_cont = btw.EventClass('switch_infcont')
        event_class_prev = btw.EventClass('switch_infprev')
        event_class_next = btw.EventClass('switch_infnext')
        event_class_hypercall = btw.EventClass('hypercall')
        event_class_hypercall2 = btw.EventClass('hypercall2')
        event_class_hypercall_version = btw.EventClass('hypercall_version')
        event_class_hypercall_version_return = btw.EventClass('hypercall_version_return')
        event_class_running_runnable = btw.EventClass('running_to_runnable')
        event_class_runnable_running = btw.EventClass('runnable_to_running')
        event_class_running_block = btw.EventClass('running_to_blocked')
        event_class_blocked_runnable = btw.EventClass('blocked_to_runnable')

        # create one 32-bit signed integer field
        int32_field_decl = btw.IntegerFieldDeclaration(32)
        int32_field_decl.signed = True

        # create one 32-bit signed integer field
        int64_field_decl = btw.IntegerFieldDeclaration(64)
        int64_field_decl.signed = True

        # add this field declaration to our event class
        event_class_blocked_runnable.add_field(int32_field_decl, 'dom') 
        event_class_blocked_runnable.add_field(int32_field_decl, 'vcpu') 

        event_class_running_block.add_field(int32_field_decl, 'dom') 
        event_class_running_block.add_field(int32_field_decl, 'vcpu') 

        event_class_runnable_running.add_field(int32_field_decl, 'dom') 
        event_class_runnable_running.add_field(int32_field_decl, 'vcpu') 

        event_class_running_runnable.add_field(int32_field_decl, 'dom') 
        event_class_running_runnable.add_field(int32_field_decl, 'vcpu') 

        event_class_cont.add_field(int32_field_decl, 'dom')
        event_class_cont.add_field(int32_field_decl, 'vcpu')

        event_class_prev.add_field(int32_field_decl, 'dom')
        event_class_prev.add_field(int32_field_decl, 'vcpu')

        event_class_next.add_field(int32_field_decl, 'dom')
        event_class_next.add_field(int32_field_decl, 'vcpu')

        event_class_hypercall.add_field(int32_field_decl, 'op')
        event_class_hypercall2.add_field(int32_field_decl, 'op')

        event_class_hypercall_version.add_field(int32_field_decl, 'id')
        event_class_hypercall_version_return.add_field(int32_field_decl, 'id')

        event_types[i]['switch_infcont'] = event_class_cont
        event_types[i]['switch_infprev'] = event_class_prev
        event_types[i]['switch_infnext'] = event_class_next
        event_types[i]['hypercall'] = event_class_hypercall
        event_types[i]['hypercall2'] = event_class_hypercall2
        event_types[i]['hypercall_version'] = event_class_hypercall_version
        event_types[i]['hypercall_version_return'] = event_class_hypercall_version_return
        event_types[i]['blocked_to_runnable'] = event_class_blocked_runnable
        event_types[i]['running_to_blocked'] = event_class_running_block
        event_types[i]['runnable_to_running'] = event_class_runnable_running
        event_types[i]['running_to_runnable'] = event_class_running_runnable

        # register our event class to our stream class
        stream_class.add_event_class(event_class_cont)
        stream_class.add_event_class(event_class_prev)
        stream_class.add_event_class(event_class_next)
        stream_class.add_event_class(event_class_hypercall)
        stream_class.add_event_class(event_class_hypercall2)
        stream_class.add_event_class(event_class_hypercall_version)
        stream_class.add_event_class(event_class_hypercall_version_return)
        stream_class.add_event_class(event_class_running_block)
        stream_class.add_event_class(event_class_blocked_runnable)
        stream_class.add_event_class(event_class_running_runnable)
        stream_class.add_event_class(event_class_runnable_running)

        stream_class.packet_context_type.add_field(int32_field_decl, 'cpu_id')

        streams.append(writer.create_stream(stream_class))
        streams[-1].packet_context.field('cpu_id').value = i

    used_streams = set()

    done = False
    while not done:
        time = 2 ** 64
        e = None
        selected_s = None
        for s in trace:
            if len(s) > 0:
                temp = s[0]
                if temp["timestamp"] < time:
                    e = temp
                    time = e["timestamp"]
                    selected_s = s
        if e is None:
            done = True
            break
        else:
            e = selected_s.pop(0)
            
        event = None
        cpu = e["cpu"]
        if e["name"] == "switch_infcont":
            event = btw.Event(event_types[cpu]["switch_infcont"])
            event.payload('dom').value = e["dom"]
            event.payload('vcpu').value = e["vcpu"]
        elif e["name"] == "switch_infnext":
            event = btw.Event(event_types[cpu]["switch_infnext"])
            event.payload('dom').value = e["dom"]
            event.payload('vcpu').value = e["vcpu"]
        elif e["name"] == "switch_infprev":
            event = btw.Event(event_types[cpu]["switch_infprev"])
            event.payload('dom').value = e["dom"]
            event.payload('vcpu').value = e["vcpu"]

        elif e["name"] == "blocked_to_runnable":
            event = btw.Event(event_types[cpu]["blocked_to_runnable"])
            event.payload('dom').value = e["dom"]
            event.payload('vcpu').value = e["vcpu"]
        elif e["name"] == "running_to_blocked":
            event = btw.Event(event_types[cpu]["running_to_blocked"])
            event.payload('dom').value = e["dom"]
            event.payload('vcpu').value = e["vcpu"]
        elif e["name"] == "runnable_to_running":
            event = btw.Event(event_types[cpu]["runnable_to_running"])
            event.payload('dom').value = e["dom"]
            event.payload('vcpu').value = e["vcpu"]
        elif e["name"] == "running_to_runnable":
            event = btw.Event(event_types[cpu]["running_to_runnable"])
            event.payload('dom').value = e["dom"]
            event.payload('vcpu').value = e["vcpu"]

        elif e["name"] == "hypercall_op":
            class_ = event_types[cpu]["hypercall"]
            event = btw.Event(event_types[cpu]["hypercall"])
            #print("cpu={}' class={} ev={}".format(cpu, class_, event))
            event.payload('op').value = e["op"]
        elif e["name"] == "hypercall_op2":
            event = btw.Event(event_types[cpu]["hypercall2"])
            event.payload('op').value = e["op"]
        elif e["name"] == "hypercall_version":
            event = btw.Event(event_types[cpu]["hypercall_version"])
            event.payload('id').value = e["id"]

        used_streams.add(cpu)
        stream = streams[cpu]
        if event != None:
            clock.time = to_ns(e["timestamp"])
            stream.append_event(event)
            if e["name"] == "hypercall_version":
                event = btw.Event(event_types[cpu]["hypercall_version_return"])
                event.payload('id').value = e["id"]
                stream.append_event(event)

    # flush the stream
    print('trace path: {}'.format(trace_path))
    for s in used_streams:
        streams[s].flush()