blob: 098d22548762a1673f51b3c871efdb9ea71fd06d [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/core/selection.html">
<script>
'use strict';
tr.exportTo('tr.c.analysis', function() {
var FLOW_IN = 0x1;
var FLOW_OUT = 0x2;
var FLOW_IN_OUT = FLOW_IN | FLOW_OUT;
function FlowClassifier() {
this.numEvents_ = 0;
this.eventsByGUID_ = {};
}
FlowClassifier.prototype = {
getFS_: function(event) {
var fs = this.eventsByGUID_[event.guid];
if (fs === undefined) {
this.numEvents_++;
fs = {
state: 0,
event: event
};
this.eventsByGUID_[event.guid] = fs;
}
return fs;
},
addInFlow: function(event) {
var fs = this.getFS_(event);
fs.state |= FLOW_IN;
return event;
},
addOutFlow: function(event) {
var fs = this.getFS_(event);
fs.state |= FLOW_OUT;
return event;
},
hasEvents: function() {
return this.numEvents_ > 0;
},
get inFlowEvents() {
var selection = new tr.c.Selection();
for (var guid in this.eventsByGUID_) {
var fs = this.eventsByGUID_[guid];
if (fs.state === FLOW_IN)
selection.push(fs.event);
}
return selection;
},
get outFlowEvents() {
var selection = new tr.c.Selection();
for (var guid in this.eventsByGUID_) {
var fs = this.eventsByGUID_[guid];
if (fs.state === FLOW_OUT)
selection.push(fs.event);
}
return selection;
},
get internalFlowEvents() {
var selection = new tr.c.Selection();
for (var guid in this.eventsByGUID_) {
var fs = this.eventsByGUID_[guid];
if (fs.state === FLOW_IN_OUT)
selection.push(fs.event);
}
return selection;
}
};
return {
FlowClassifier: FlowClassifier
};
});
</script>