merge.py 2.35 KB
Newer Older
1
2
from darshan.report import *

Jakob Luettgau's avatar
PEP8.    
Jakob Luettgau committed
3
import datetime
4
5
import copy

Jakob Luettgau's avatar
PEP8.    
Jakob Luettgau committed
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def merge(self, other, reduce_first=False):
    """
    Merge two darshan reports and return a new combined report.

    Args:
        mods:           Name(s) of modules to preserve (reduced)
        name_records:   Id(s)/Name(s) of name_records to preserve (reduced)

    Return:
        None
    """

    # new report
    nr = DarshanReport()

    # keep provenance?
    if self.provenance_enabled or other.provenance_enabled:
        # Currently, assume logs remain in memomry to create prov. tree on demand
        # Alternative: maintain a tree with simpler refs? (modified reports would not work then)

        #nr.provenance_reports[self.filename] = copy.copy(self)
        #nr.provenance_reports[other.filename] = copy.copy(other)

        nr.provenance_reports[self.filename] = None
        nr.provenance_reports[other.filename] = None

33
        nr.provenance_graph.append(("add", self, other, datetime.datetime.now()))
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60


    # update metadata helper
    def update_metadata(report, force=False):
        if force:
            nr.start_time = report.start_time
            nr.end_time = report.end_time
            return

        if report.start_time < nr.start_time:
            nr.start_time = report.start_time

        if report.end_time > nr.end_time:
            nr.end_time = report.end_time


    update_metadata(self, force=True)
    update_metadata(other)


    # copy over records (references, under assumption single records are not altered)
    for report in [self, other]:
        for key, records in report.data['records'].items():
            #print(report, key)
            if key not in nr.records:
                nr.records[key] = copy.copy(records)
            else:
Jakob Luettgau's avatar
Jakob Luettgau committed
61
                nr.records[key]._records = nr.records[key]._records + copy.copy(records._records)
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

        for key, mod in report.modules.items():
            if key not in nr.modules:
                nr.modules[key] = copy.copy(mod)
                # TODO: invalidate len/counters

        for key, counter in report.counters.items():
            if key not in nr.counters:
                nr.counters[key] = copy.copy(counter)

        for key, nrec in report.name_records.items():
            if key not in nr.counters:
                nr.name_records[key] = copy.copy(nrec)
                # TODO: verify colliding name_records?

    return nr