{ "metadata": { "name": "", "signature": "sha256:4e50c9159c1a001f1a581f813b7e533f0ef5d8ec4220406180bad11eb9cdba5c" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Registering arbitrary trace events" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`trappy` knows about some trace events. You can add your own in the notebook without having to change any code in `trappy`. After the trace is registered, the next time you parse a trace file that information will be part of the trace object as a pandas `DataFrame` and can be analyzed like the other `DataFrame`s in the `FTrace` class.\n", "\n", "The trace event must follow the following format:\n", "\n", " title: key0=value0 key1=value1 key2=value2 ...\n", "\n", "The title should be something that's unique in the trace. For example, you can generate trace with the following `trace_printk()`:\n", "\n", " trace_printk(\"thermal_gpu_power_get: frequency=%u load=%d\\n\", freq, load);\n", "\n", "which will appear in the `trace.txt` as:\n", "\n", " kworker/6:1-457 [006] 144.439566: bprint: 0xc042f8a0f: thermal_gpu_power_get: frequency=177 load=0\n", "\n", "You can add this event to the trace instance using `register_dynamic_ftrace()`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First import trappy" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import sys\n", "sys.path.append(\"..\")\n", "%matplotlib inline\n", "import trappy" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Register it. The first argument is the name under which you will find it in the trace instance. It will be changed to lower_case_with_underscores_to_separate_words. The second argument is some unique text in the trace, usually the title:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "trappy.register_dynamic_ftrace(\"gpu_power_in\", \"thermal_gpu_power_get\")" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 2, "text": [ "trappy.dynamic.gpu_power_in" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can parse the trace" ] }, { "cell_type": "code", "collapsed": false, "input": [ "trace = trappy.FTrace(\"/path/to/trace\")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "`trace` now has a `gpu_power_in` member that contains the information. We can see the first few lines of the generated dataframe:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "trace.gpu_power_in.data_frame.head()" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", " | frequency | \n", "load | \n", "
---|---|---|
Time | \n", "\n", " | \n", " |
109.999957 | \n", "480 | \n", "96 | \n", "
110.099925 | \n", "480 | \n", "100 | \n", "
110.199930 | \n", "480 | \n", "100 | \n", "
110.299938 | \n", "480 | \n", "100 | \n", "
110.399924 | \n", "480 | \n", "100 | \n", "