# Trace files (\*.xml) parsing

**URL:** <https://forums.foundationdb.org/t/trace-files-xml-parsing/1325>\
**Category:** Development\
**Created:** [April 22, 2019, 9:22pm UTC](https://forums.foundationdb.org/t/trace-files-xml-parsing/1325 "2019-04-22T21:22:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gorrunyo](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@gorrunyo](https://forums.foundationdb.org/u/gorrunyo)\
**Post date:** [April 22, 2019, 9:22pm UTC](https://forums.foundationdb.org/t/trace-files-xml-parsing/1325/1 "2019-04-22T21:22:08Z")

</div>

Is there a tool to parse and present trace (\*.xml) files generated by fdbserver?

Thanks

---

<div class="post-metadata">

**Author:** ![jzhou](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/jzhou/32/445_2.png) [@jzhou](https://forums.foundationdb.org/u/jzhou)\
**Post date:** [April 25, 2019, 4:21am UTC](https://forums.foundationdb.org/t/trace-files-xml-parsing/1325/2 "2019-04-25T04:21:31Z")

</div>

[Splunk](https://www.splunk.com/) can handle these trace files. Either free version or commercial version of Splunk can be obtained.

If you use Python, I have some starter code that can convert a trace XML file into a Pandas dataframe:

```
import xml.dom.minidom
import pandas as pd

def filter_dict(input_dict, kept_keys, sep='\n'):
    # only keep keys in the "kept_keys", combine all others to "Details"
    # with a string concatenated with "sep"
    other = ''
    d = {}
    for key, value in input_dict.items():
        if key in kept_keys:
            d[key] = value
        else:
            if 'Details' in d:
                d['Details'] += sep + key + ": " + value
            else:
                d['Details'] = key + ": " + value
    return d

def load_trace_file(filename, columns):
    dom = xml.dom.minidom.parse(filename)
    events = dom.getElementsByTagName('Event')
    data = [filter_dict(dict(e.attributes.items()), columns) for e in events]
    return pd.DataFrame(data)

```

A usage example:

```
trace_file = "trace.000.000.000.000.0.1549822912.WhkJCk.1.xml"
columns = ['As', 'ID', 'Locality', 'Machine', 'Severity', 'Transition', 'Time', 'Type']

df = load_trace_file(trace_file, columns)
# Convert to number type for Severity & Time columns
df = df.astype({'Severity': int, 'Time': float})
df.head(5)

```

Get a list of unique machines and roles:

```
def get_roles(df):
    """df is a dataframe obtained from load_trace_file
    """
    return df['As'].dropna().unique().tolist()

def get_machines(df):
    return df['Machine'].dropna().unique().tolist()
```

---

<div class="post-metadata">

**Author:** ![alexmiller](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/alexmiller/32/326_2.png) [@alexmiller](https://forums.foundationdb.org/u/alexmiller)\
**Post date:** [April 25, 2019, 5:40pm UTC](https://forums.foundationdb.org/t/trace-files-xml-parsing/1325/3 "2019-04-25T17:40:33Z")

</div>

The only tool that I’ve seen to process trace files is [wavefrontHQ/wavefront-fdb-tailer](https://github.com/wavefrontHQ/wavefront-fdb-tailer).

Other folks have hooked up InfluxDB+Grafana to be able to do arbitrary graphs, or have an odd collection of bespoke python scripts (like Jingyu’s) laying around.

---

<div class="post-metadata">

**Author:** ![alloc](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/alloc/32/9_2.png) [@alloc](https://forums.foundationdb.org/u/alloc)\
**Post date:** [May 5, 2019, 6:34pm UTC](https://forums.foundationdb.org/t/trace-files-xml-parsing/1325/4 "2019-05-05T18:34:11Z")

</div>

Does the network option to emit JSON instead of XML work with fdbserver? I know it works with the clients, and that may be easier for some people to parse.

---

<div class="post-metadata">

**Author:** ![ajbeamon](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/ajbeamon/32/13_2.png) [@ajbeamon](https://forums.foundationdb.org/u/ajbeamon)\
**Post date:** [May 5, 2019, 11:02pm UTC](https://forums.foundationdb.org/t/trace-files-xml-parsing/1325/5 "2019-05-05T23:02:16Z")

</div>

Yeah, but it’s a command line parameter in that case.

EDIT: looks like it’s `--trace_format`, with `xml` and `json` being the supported choices.

---

<div class="post-metadata">

**Author:** ![osamarin](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/osamarin/32/905_2.png) [@osamarin](https://forums.foundationdb.org/u/osamarin)\
**Post date:** [October 21, 2020, 11:56am UTC](https://forums.foundationdb.org/t/trace-files-xml-parsing/1325/6 "2020-10-21T11:56:53Z")

</div>

Is there a tool that

1. merges multiple trace files from several fdbservers into the single text file in the chronological order
2. addes ip:port labels to the single file
3. converts Times from numbers to a human-readable date and time  
?

---

<div class="post-metadata">

**Author:** ![jzhou](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/jzhou/32/445_2.png) [@jzhou](https://forums.foundationdb.org/u/jzhou)\
**Post date:** [November 26, 2020, 1:37am UTC](https://forums.foundationdb.org/t/trace-files-xml-parsing/1325/7 "2020-11-26T01:37:43Z")

</div>

The third point is addressed by [https://github.com/apple/foundationdb/pull/4087/](https://github.com/apple/foundationdb/pull/4087/), which adds the field “DateTime”.
