1<!DOCTYPE html>
2<!--
3Copyright (c) 2012 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/tracing/extras/importer/linux_perf/parser.html">
9
10<script>
11'use strict';
12
13/**
14 * @fileoverview Parses drm driver events in the Linux event trace format.
15 */
16tr.exportTo('tr.e.importer.linux_perf', function() {
17  var Parser = tr.e.importer.linux_perf.Parser;
18
19  /**
20   * Parses linux vmscan trace events.
21   * @constructor
22   */
23  function MemReclaimParser(importer) {
24    Parser.call(this, importer);
25
26    importer.registerEventHandler('mm_vmscan_kswapd_wake',
27        MemReclaimParser.prototype.kswapdWake.bind(this));
28    importer.registerEventHandler('mm_vmscan_kswapd_sleep',
29        MemReclaimParser.prototype.kswapdSleep.bind(this));
30    importer.registerEventHandler('mm_vmscan_direct_reclaim_begin',
31        MemReclaimParser.prototype.reclaimBegin.bind(this));
32    importer.registerEventHandler('mm_vmscan_direct_reclaim_end',
33        MemReclaimParser.prototype.reclaimEnd.bind(this));
34  }
35
36  // Matches the mm_vmscan_kswapd_wake record
37  //  mm_vmscan_kswapd_wake: nid=%d order=%d
38  var kswapdWakeRE = /nid=(\d+) order=(\d+)/;
39
40  // Matches the mm_vmscan_kswapd_sleep record
41  //  mm_vmscan_kswapd_sleep: order=%d
42  var kswapdSleepRE = /nid=(\d+)/;
43
44  // Matches the mm_vmscan_direct_reclaim_begin record
45  //  mm_vmscan_direct_reclaim_begin: order=%d may_writepage=%d gfp_flags=%s
46  var reclaimBeginRE = /order=(\d+) may_writepage=\d+ gfp_flags=(.+)/;
47
48  // Matches the mm_vmscan_direct_reclaim_end record
49  //  mm_vmscan_direct_reclaim_end: nr_reclaimed=%lu
50  var reclaimEndRE = /nr_reclaimed=(\d+)/;
51
52  MemReclaimParser.prototype = {
53    __proto__: Parser.prototype,
54
55    /**
56     * Parses memreclaim events and sets up state in the importer.
57     */
58    kswapdWake: function(eventName, cpuNumber, pid, ts, eventBase) {
59      var event = kswapdWakeRE.exec(eventBase.details);
60      if (!event)
61        return false;
62
63      var tgid = parseInt(eventBase.tgid);
64
65      var nid = parseInt(event[1]);
66      var order = parseInt(event[2]);
67
68      var kthread = this.importer.getOrCreateKernelThread(
69          eventBase.threadName, tgid, pid);
70
71      if (kthread.openSliceTS) {
72        if (order > kthread.order) {
73          kthread.order = order;
74        }
75      } else {
76        kthread.openSliceTS = ts;
77        kthread.order = order;
78      }
79      return true;
80    },
81
82    kswapdSleep: function(eventName, cpuNumber, pid, ts, eventBase) {
83      var tgid = parseInt(eventBase.tgid);
84
85      var kthread = this.importer.getOrCreateKernelThread(
86          eventBase.threadName, tgid, pid);
87
88      if (kthread.openSliceTS) {
89
90        kthread.thread.sliceGroup.pushCompleteSlice(
91            'memreclaim', eventBase.threadName, kthread.openSliceTS,
92            ts - kthread.openSliceTS, 0, 0,
93            {
94              order: kthread.order
95            });
96      }
97      kthread.openSliceTS = undefined;
98      kthread.order = undefined;
99      return true;
100    },
101
102    reclaimBegin: function(eventName, cpuNumber, pid, ts, eventBase) {
103      var event = reclaimBeginRE.exec(eventBase.details);
104      if (!event)
105        return false;
106
107      var order = parseInt(event[1]);
108      var gfp = event[2];
109      var tgid = parseInt(eventBase.tgid);
110
111      var kthread = this.importer.getOrCreateKernelThread(
112          eventBase.threadName, tgid, pid);
113
114      kthread.openSliceTS = ts;
115      kthread.order = order;
116      kthread.gfp = gfp;
117      return true;
118    },
119
120    reclaimEnd: function(eventName, cpuNumber, pid, ts, eventBase) {
121      var event = reclaimEndRE.exec(eventBase.details);
122      if (!event)
123        return false;
124
125      var nr_reclaimed = parseInt(event[1]);
126      var tgid = parseInt(eventBase.tgid);
127
128      var kthread = this.importer.getOrCreateKernelThread(
129          eventBase.threadName, tgid, pid);
130
131      if (kthread.openSliceTS !== undefined) {
132        kthread.thread.sliceGroup.pushCompleteSlice('memreclaim',
133            'direct reclaim', kthread.openSliceTS, ts - kthread.openSliceTS,
134            0, 0,
135            {
136              order: kthread.order,
137              gfp: kthread.gfp,
138              nr_reclaimed: nr_reclaimed
139            });
140      }
141      kthread.openSliceTS = undefined;
142      kthread.order = undefined;
143      kthread.gfp = undefined;
144      return true;
145    }
146
147  };
148
149  Parser.register(MemReclaimParser);
150
151  return {
152    MemReclaimParser: MemReclaimParser
153  };
154});
155</script>
156