Skip to content

Commit

Permalink
HW6 (#212)
Browse files Browse the repository at this point in the history
* add dao

* fix dependencies

* simple server

* create all routes

* fix cringe

* tests

* update dao to last version :)

* add scripts

* partly stage1

* vivods

* мега вывод

* code climate

* new ideas

* hw2

* fix codeclimate

* code refactor

* gg wp

* refactor reports

* hw2

* hw3 code base

* hw3 add validation
+fix codeclimate

* hw3 move files

* hw3 fix codeclimate x2

* hw3 change to consistent hashing

* stage3

* stage3 full

* remove main

* add timestamp entry

* fix cringe

* hw4

* fix codeclimate

* umom

* md

* remove cringe

* codeclimate

* вывод

* fix build gradle

* fix gradle x2

* fix bug

* hw4 on java.net.HttpClient

* hw5 add async to httpclint

* hw5

* update bash

* fix codeclimate

* oh, lol

* prettify

* fix codeclimate x2

* stage5

* stage5 vivods

* hw6

* hw6 cool

* for pr check

* codeclimate fix

* better code

* omg, remove cringe

* codeclimate ;)

* add hw6

* files ;)

* reuse one chunk

* add additional vivod

* fix codeclimate

* ggwp

---------

Co-authored-by: Vadim Tsesko <[email protected]>
Co-authored-by: Daniil Ushkov <[email protected]>
  • Loading branch information
3 people authored May 25, 2024
1 parent bdfd74f commit a88dd7d
Show file tree
Hide file tree
Showing 31 changed files with 2,321 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public E next() {
}
return result;
}

public E getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,379 @@
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<style>
body {margin: 0; padding: 10px 10px 22px 10px; background-color: #ffffff}
h1 {margin: 5px 0 0 0; font-size: 18px; font-weight: normal; text-align: center}
header {margin: -24px 0 5px 0; line-height: 24px}
button {font: 12px sans-serif; cursor: pointer}
p {position: fixed; bottom: 0; margin: 0; padding: 2px 3px 2px 3px; outline: 1px solid #ffc000; display: none; overflow: hidden; white-space: nowrap; background-color: #ffffe0}
a {color: #0366d6}
#hl {position: absolute; display: none; overflow: hidden; white-space: nowrap; pointer-events: none; background-color: #ffffe0; outline: 1px solid #ffc000; height: 15px}
#hl span {padding: 0 3px 0 3px}
#status {left: 0}
#match {right: 0}
#reset {cursor: pointer}
#canvas {width: 100%; height: 528px}
</style>
</head>
<body style='font: 12px Verdana, sans-serif'>
<h1>Flame Graph</h1>
<header style='text-align: left'><button id='reverse' title='Reverse'>&#x1f53b;</button>&nbsp;&nbsp;<button id='search' title='Search'>&#x1f50d;</button></header>
<header style='text-align: right'>Produced by <a href='https://github.com/async-profiler/async-profiler'>async-profiler</a></header>
<canvas id='canvas'></canvas>
<div id='hl'><span></span></div>
<p id='status'></p>
<p id='match'>Matched: <span id='matchval'></span> <span id='reset' title='Clear'>&#x274c;</span></p>
<script>
// Copyright The async-profiler authors
// SPDX-License-Identifier: Apache-2.0
'use strict';
let root, rootLevel, px, pattern;
let level0 = 0, left0 = 0, width0 = 0;
let reverse = false;
const levels = Array(33);
for (let h = 0; h < levels.length; h++) {
levels[h] = [];
}

const canvas = document.getElementById('canvas');
const c = canvas.getContext('2d');
const hl = document.getElementById('hl');
const status = document.getElementById('status');

const canvasWidth = canvas.offsetWidth;
const canvasHeight = canvas.offsetHeight;
canvas.style.width = canvasWidth + 'px';
canvas.width = canvasWidth * (devicePixelRatio || 1);
canvas.height = canvasHeight * (devicePixelRatio || 1);
if (devicePixelRatio) c.scale(devicePixelRatio, devicePixelRatio);
c.font = document.body.style.font;

const palette = [
[0xb2e1b2, 20, 20, 20],
[0x50e150, 30, 30, 30],
[0x50cccc, 30, 30, 30],
[0xe15a5a, 30, 40, 40],
[0xc8c83c, 30, 30, 10],
[0xe17d00, 30, 30, 0],
[0xcce880, 20, 20, 20],
];

function getColor(p) {
const v = Math.random();
return '#' + (p[0] + ((p[1] * v) << 16 | (p[2] * v) << 8 | (p[3] * v))).toString(16);
}

function f(key, level, left, width, inln, c1, int) {
levels[level0 = level].push({left: left0 += left, width: width0 = width || width0,
color: getColor(palette[key & 7]), title: cpool[key >>> 3],
details: (int ? ', int=' + int : '') + (c1 ? ', c1=' + c1 : '') + (inln ? ', inln=' + inln : '')
});
}

function u(key, width, inln, c1, int) {
f(key, level0 + 1, 0, width, inln, c1, int)
}

function n(key, width, inln, c1, int) {
f(key, level0, width0, width, inln, c1, int)
}

function samples(n) {
return n === 1 ? '1 sample' : n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' samples';
}

function pct(a, b) {
return a >= b ? '100' : (100 * a / b).toFixed(2);
}

function findFrame(frames, x) {
let left = 0;
let right = frames.length - 1;

while (left <= right) {
const mid = (left + right) >>> 1;
const f = frames[mid];

if (f.left > x) {
right = mid - 1;
} else if (f.left + f.width <= x) {
left = mid + 1;
} else {
return f;
}
}

if (frames[left] && (frames[left].left - x) * px < 0.5) return frames[left];
if (frames[right] && (x - (frames[right].left + frames[right].width)) * px < 0.5) return frames[right];

return null;
}

function search(r) {
if (r === true && (r = prompt('Enter regexp to search:', '')) === null) {
return;
}

pattern = r ? RegExp(r) : undefined;
const matched = render(root, rootLevel);
document.getElementById('matchval').textContent = pct(matched, root.width) + '%';
document.getElementById('match').style.display = r ? 'inline-block' : 'none';
}

function render(newRoot, newLevel) {
if (root) {
c.fillStyle = '#ffffff';
c.fillRect(0, 0, canvasWidth, canvasHeight);
}

root = newRoot || levels[0][0];
rootLevel = newLevel || 0;
px = canvasWidth / root.width;

const x0 = root.left;
const x1 = x0 + root.width;
const marked = [];

function mark(f) {
return marked[f.left] >= f.width || (marked[f.left] = f.width);
}

function totalMarked() {
let total = 0;
let left = 0;
Object.keys(marked).sort(function(a, b) { return a - b; }).forEach(function(x) {
if (+x >= left) {
total += marked[x];
left = +x + marked[x];
}
});
return total;
}

function drawFrame(f, y, alpha) {
if (f.left < x1 && f.left + f.width > x0) {
c.fillStyle = pattern && f.title.match(pattern) && mark(f) ? '#ee00ee' : f.color;
c.fillRect((f.left - x0) * px, y, f.width * px, 15);

if (f.width * px >= 21) {
const chars = Math.floor(f.width * px / 7);
const title = f.title.length <= chars ? f.title : f.title.substring(0, chars - 2) + '..';
c.fillStyle = '#000000';
c.fillText(title, Math.max(f.left - x0, 0) * px + 3, y + 12, f.width * px - 6);
}

if (alpha) {
c.fillStyle = 'rgba(255, 255, 255, 0.5)';
c.fillRect((f.left - x0) * px, y, f.width * px, 15);
}
}
}

for (let h = 0; h < levels.length; h++) {
const y = reverse ? h * 16 : canvasHeight - (h + 1) * 16;
const frames = levels[h];
for (let i = 0; i < frames.length; i++) {
drawFrame(frames[i], y, h < rootLevel);
}
}

return totalMarked();
}

function unpack(cpool) {
for (let i = 1; i < cpool.length; i++) {
cpool[i] = cpool[i - 1].substring(0, cpool[i].charCodeAt(0) - 32) + cpool[i].substring(1);
}
}

canvas.onmousemove = function() {
const h = Math.floor((reverse ? event.offsetY : (canvasHeight - event.offsetY)) / 16);
if (h >= 0 && h < levels.length) {
const f = findFrame(levels[h], event.offsetX / px + root.left);
if (f) {
if (f !== root) getSelection().removeAllRanges();
hl.style.left = (Math.max(f.left - root.left, 0) * px + canvas.offsetLeft) + 'px';
hl.style.width = (Math.min(f.width, root.width) * px) + 'px';
hl.style.top = ((reverse ? h * 16 : canvasHeight - (h + 1) * 16) + canvas.offsetTop) + 'px';
hl.firstChild.textContent = f.title;
hl.style.display = 'block';
canvas.title = f.title + '\n(' + samples(f.width) + f.details + ', ' + pct(f.width, levels[0][0].width) + '%)';
canvas.style.cursor = 'pointer';
canvas.onclick = function() {
if (f !== root) {
render(f, h);
canvas.onmousemove();
}
};
status.textContent = 'Function: ' + canvas.title;
status.style.display = 'inline-block';
return;
}
}
canvas.onmouseout();
}

canvas.onmouseout = function() {
hl.style.display = 'none';
status.style.display = 'none';
canvas.title = '';
canvas.style.cursor = '';
canvas.onclick = null;
}

canvas.ondblclick = function() {
getSelection().selectAllChildren(hl);
}

document.getElementById('reverse').onclick = function() {
reverse = !reverse;
render();
}

document.getElementById('search').onclick = function() {
search(true);
}

document.getElementById('reset').onclick = function() {
search(false);
}

window.onkeydown = function() {
if (event.ctrlKey && event.keyCode === 70) {
event.preventDefault();
search(true);
} else if (event.keyCode === 27) {
search(false);
}
}

const cpool = [
'all',
' [pool-4-thread-2 tid=36611]',
' byte[]',
' java.lang.Long',
'%util.ArrayList$Itr',
'$/lang/Long.toHexString',
'1UnsignedString0',
'/valueOf',
'*String.encode',
'7UTF8',
'1getBytes',
'*Thread.run',
'4With',
'*foreign/MemorySegment.ofArray',
'%util/AbstractList$Itr.next',
'7SubList$1.next',
'+rrayList.iterator',
'*concurrent/CompletableFuture$AsyncSupply.run',
'5ThreadPoolExecutor$Worker.run',
'G.runWorker',
'!dk.internal.foreign.GlobalSession',
'5HeapMemorySegmentImpl$OfByte',
'5MappedMemorySegmentImpl',
'#/internal/foreign/AbstractMemorySegmentImpl.asSlice',
'VNoCheck',
'5HeapMemorySegmentImpl$OfByte.fromArray',
'5MappedMemorySegmentImpl.asSlice',
'Mdup',
'6emorySessionImpl.heapSession',
' one/nio/net/Session.write',
' ru.vk.itmo.test.kovalevigor.dao.IndexList$LazyEntry',
'@entry.MSegmentTimeEntry',
'"/vk/itmo/test/kovalevigor/dao/IndexList$LazyEntry.value',
'I.get',
'MValue',
'@SSTimeTableManager$$Lambda.0x0000007001147d10.apply',
'R.keyValueEntryTo',
'@iterators/ApplyIterator.next',
'JMergeIterator.next',
'XshiftAdd',
'JShiftedIterator.next',
'<server/strategy/ServerDaoStrategy$$Lambda.0x0000007001148998.apply',
'].handleRequest',
'^lambda$mapEntry$0',
'RStrategy$$Lambda.0x0000007001146888.get',
'Z.lambda$handleRequestAsync$0',
'Lutil/ChainedQueueItem.write',
'SunkQueueItem.mapToHex',
'`setChunk'
];
unpack(cpool);

n(3,1361)
u(11)
u(89)
u(97)
u(145)
u(153)
u(137)
u(353)
u(361)
u(337)
u(233)
u(369)
u(369)
u(297)
u(305,977)
u(313)
u(321)
u(305)
u(313)
u(321)
u(297)
u(121,341)
u(113)
u(265)
u(265)
u(209,192)
u(209)
u(185)
u(193)
u(217)
u(217)
u(178)
f(242,25,192,149)
f(281,21,149,636)
u(289)
u(57,119)
u(26)
f(185,23,119,186)
u(185)
u(193)
u(217)
u(217)
u(178)
f(250,23,186,141)
n(257,190)
u(257)
u(273)
u(209)
u(209)
u(185)
u(193)
u(217)
u(217)
u(178)
f(329,14,190,384)
u(345)
u(385)
u(129,86)
u(34)
f(377,17,86,298)
u(41,58)
u(49)
u(18)
f(81,18,58,66)
u(65)
u(73)
u(18)
f(105,18,66,174)
u(201)
u(170,93)
n(225,81)
u(162)

search();
</script></body></html>
Loading

0 comments on commit a88dd7d

Please sign in to comment.