Visualize adb shell dumpsys activity activities
result with D3's tree layout. Based on activitykit. You can see preview here
Last active
August 29, 2015 14:03
-
-
Save chitacan/8f1a4d3829442b2e69fc to your computer and use it in GitHub Desktop.
activity stack visualizer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.nodebox { | |
fill: #fff; | |
stroke: steelblue; | |
stroke-width: 3.5px; | |
} | |
.nodeTitle { | |
font: 10px sans-serif; | |
font-weight: bold; | |
} | |
.component { | |
font: 8px sans-serif; | |
} | |
.nodeText { | |
font: 8px sans-serif; | |
} | |
.package { | |
font: 8px sans-serif; | |
} | |
.link { | |
fill: none; | |
stroke: #ccc; | |
stroke-width: 3.5px; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.js"></script> | |
<script src="tree.js"> | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var WIDTH = 960 | |
, HEIGHT = 2000 | |
, BOX_WIDTH = 150 | |
, BOX_HEIGHT = 60 | |
function COMPARATOR(a, b) { | |
return a.name < b.name ? -1 : (a.name > b.name ? 1 : 0); | |
} | |
function SEPARATION(a, b) { | |
return (a.parent == b.parent ? 1 : 2); | |
} | |
var tree = d3.layout.tree() | |
.size([HEIGHT, WIDTH - 400]) | |
.sort(COMPARATOR) | |
.separation(SEPARATION); | |
var diagonal = d3.svg.diagonal().projection(function(d) { return [d.y, d.x]; }); | |
var svg = d3.select('body').append('svg') | |
.attr('width', WIDTH) | |
.attr('height', HEIGHT) | |
// group SVG shapes together. | |
.append('g') | |
.attr('transform', 'translate(80,0)'); | |
d3.json('https://googledrive.com/host/0ByxPwij8v_deaV9BeVIwSGg2M3c', function(data) { | |
var focused = data.focused; | |
var nodes = tree.nodes(data.stack) | |
, links = tree.links(nodes); | |
var eLinks = svg.selectAll('.link').data(links) | |
, eNodes = svg.selectAll('.node').data(nodes); | |
eLinks.enter().append('path') | |
.attr('class', 'link') | |
.attr('d', diagonal); | |
var newNodes = eNodes.enter().append('g'); | |
newNodes | |
.attr('class', function(d) { | |
return !!d.type ? 'node ' + d.type : 'node'; | |
}) | |
.attr('id', function(d) { return d.name }) | |
.attr('transform', function(d) { return 'translate(' + d.y + ',' + d.x +')'; }) | |
.append('rect') | |
.attr('class', 'nodebox') | |
.attr('x', -BOX_WIDTH/2) | |
.attr('y', -BOX_HEIGHT/2) | |
.attr('width', BOX_WIDTH) | |
.attr('height', BOX_HEIGHT) | |
// fill focused activity | |
newNodes | |
.select('rect').filter(function(d) { return d.depth === 3; }) | |
.style('fill', function(d) { | |
if (d.taskId === focused.taskId && d.component === focused.component) | |
return 'rgb(210, 228, 242)'; | |
}); | |
newNodes.append('text') | |
.attr('id', 'nodeTitle') | |
.attr('class', 'nodeTitle') | |
.attr('y', -10) | |
.attr('text-anchor', 'middle') | |
newNodes.select('#nodeTitle') | |
.text(function(d) { return d.name; }); | |
svg.selectAll('.history').append('text') | |
.attr('id', 'package') | |
.attr('class', 'package') | |
.attr('y', 10) | |
.attr('text-anchor', 'middle') | |
.attr('fill', 'gray') | |
newNodes.select('#package') | |
.text(function(d) { return d.component.split('/')[0]; }); | |
svg.selectAll('.history').append('text') | |
.attr('id', 'component') | |
.attr('class', 'component') | |
.attr('y', 25) | |
.attr('text-anchor', 'middle') | |
.attr('fill', 'gray') | |
newNodes.select('#component') | |
.text(function(d) { return d.component.split('/')[1]; }); | |
var link = svg.selectAll(".link") | |
.data(links) | |
.enter().append("g") | |
.attr("class", "link"); | |
link.append("line") | |
.style("stroke-width", function(d) { return "20px"; }); | |
eLinks | |
.transition() | |
.duration(1000) | |
.style('stroke-width', function(d) { | |
if (d.source.depth == 2 && d.target.depth == 3) { | |
var id = +d.target.name.replace('Hist #', ''); | |
return id == 0 ? 10 : 0; | |
} | |
else | |
return 15; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment