Skip to content
space2 edited this page Feb 4, 2013 · 3 revisions

Extending chkbugreport

XML Plugin

It's possible to extend/change the functionality with plugins using the xml file format.

The structure of the plugin must be the following:

<plugin name="ExamplePlugin">
    <hook into="FooBarPlugin">
        ...
    </hook>
    <load>
        ...
    </load>
    <generate>
        <chapter name="Chapter/Subchapter">
            ...
        </chapter>
    </generate>
</plugin>

Note that all of the "hook", "load" and "generate" tags are optional. The "hook" tag is used to modify the behavior of other plugins. The "load" tag is used to collect data. The "generate" tag is used to insert new chapters.

Hook

When present, it is used to modify the behavior of other plugins. That's why the "into" attribute is mandatory, and must contain the name of an internal plugin. The syntax of the hook is then dependent on the target plugin. Currently the following plugins have support for hooks:

BatteryInfoPlugin

This plugin supports adding extra info into the battery chart. For example:

<hook into="BatteryInfoPlugin">
    <logchart>
        <dataset id="batt" name="Battery" type="state" colors="#fc8,#00f,#0f0,#f00" />
        <filter log="event" matchTag="battery_status" matchMsg="..*,.*,.*,(.*),.*\]" dataset="batt" />
    </logchart>
</hook>

The syntax of the logchart is exactly the same as below (under "Generate")

SystemLogPlugin, MainLogPlugin and EventLogPlugin

It's possible to hide log lines matching a regular expression, add notes to log lines or to mark bugs in the log. Example:

<hook into="SystemLogPlugin">
    <filter matchTag="WindowManager" matchMsg="Lock screen displayed!">
        <!-- Add a red side-note to the log -->
        <note text="Lockscreen" error="true" />
    </filter>
    <filter matchMsg="Start proc com.google.android.youtube">
        <!-- Add a yellow side-note to the log -->
        <note text="YouTube" />
    </filter>
    <filter matchTag="ConnectivityService" matchMsg="Attempting to switch to BLUETOOTH_TETHER">
        <!-- Create a link from the "Errors" chapter -->
        <bug title="Something's fishy" text="Lok at the log. Can you believe it?!" prio="100" type="phone err" />
    </filter>
    <filter matchTag="BackupManagerService">
        <!-- Delete log lines -->
        <hide />
    </filter>
</hook>

Load

The "load" tag is used only to collect data. Currently it's not used. In the future it will be used to create tables in the databases and populate it from the log or from other data source.

Generate

The "generate" tag can contain any number of "chapter" tags. The chapter names can contain the unix style path separator ('/') which can be used to create sub-chapters. The "chapter" nodes contain the actual report contents.

Currently the following tags can be used inside the "chapter" tags:

Text

The "text" tag will simply add the defined text to the generated output.

Logchart

The "logchart" tag can create simple charts (like the example above) based on the log files. It requires one or more "dataset" and one or more "filter" tag.

The "dataset" tag specifies a set of data to be plotted. It can be plotted in three different ways:

  • If type="plot", then it will be plotted normally on a 2D plot, where the time is on the X axis and the extract value on the Y axis. This can be used to plot used memory or the battery level.
  • If type="state", then it will be plotted below the main plot as a horizontal strip, who's background is filled according to the state value extracted. This can be used to plot the state of the screen (on or off) or the state of the data connection.
  • If type="event", then it will be plotted also below the main plot, and for each data in the dataset a small vertical line will be drawn, to mark the position of an event on the timeline.

The "filter" tag is used to fill the datasets with data extracted from the log. It should contain at least one regexp pattern to match either the whole log line, the logtag or the message. If the log line matches, and one of the regexp patterns contain a group, then the value from the group is extracted, converted to integer and stored as data in the specified data set. If no groups are present, then the "filter" tag must define the values to insert at the given timestamp using the "value" attribute.

Example:

    <chapter name="Example/Test 1">
        <text>This is just some example test</text>
        <logchart name="Battery level" file="ex_battery_level">
            <dataset id="level" name="Battery level" type="plot" min="0" max="100" />
            <dataset id="screen" name="Screen on" type="state" colors="#0f0,#ff0,#f00" />
            <dataset id="am" name="ActivityManager" type="event" colors="#080,#f00" />
            <filter log="event" matchTag="battery_level" matchMsg=".(.*),.*,.*\]" dataset="level" />
            <filter log="event" matchTag="screen_toggled" matchMsg="(.)" dataset="screen" />
            <filter log="event" matchTag="am_proc_start" dataset="am" value="0" />
            <filter log="event" matchTag="am_proc_died" dataset="am" value="1" />
        </logchart>
    </chapter>

Log

The "log" tag simply creates a filtered log. The syntax is a simplified version of the "logchart" filter: "filter" tags specify which log lines should be included. Example:

    <chapter name="My stuff/Log">
        <log>
            <filter log="event" matchTag="battery_level" matchMsg=".(.*),.*,.*\]" />
            <filter log="event" matchTag="screen_toggled" matchMsg="(.)" />
        </log>
    </chapter>