{"id":404071,"date":"2024-06-29T17:29:52","date_gmt":"2024-06-29T17:29:52","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=404071"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=404071","title":{"rendered":"<span>\u041e\u0446\u0435\u043d\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 JDK Flight Recorder\u00a0\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e JfrUnit<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/twitter.com\/gunnarmorling\" rel=\"noopener noreferrer nofollow\"><u>\u0413\u0443\u043d\u043d\u0430\u0440 \u041c\u043e\u0440\u043b\u0438\u043d\u0433<\/u><\/a>, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0432 Red Hat,\u00a0<a href=\"https:\/\/www.morling.dev\/blog\/introducing-jfrunit-1-0-0-alpha1\/\" rel=\"noopener noreferrer nofollow\"><u>\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b<\/u><\/a>\u00a0JfrUnit, \u043d\u043e\u0432\u0443\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u0443 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441 <a href=\"https:\/\/junit.org\/\" rel=\"noopener noreferrer nofollow\"><u>JUnit<\/u><\/a>\u00a0\u0438\u043b\u0438\u00a0<a href=\"https:\/\/spockframework.org\/\" rel=\"noopener noreferrer nofollow\"><u>Spock Framework<\/u><\/a>.\u00a0\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043a\u043b\u0438\u043a\u0430, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438, \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0444\u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0438\u043b\u0438 \u0441\u0435\u0442\u044c, \u0430 \u043d\u0435 \u0441\u0430\u043c\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c.\u00a0<a href=\"https:\/\/github.com\/moditect\/jfrunit\/blob\/main\/README.md\" rel=\"noopener noreferrer nofollow\"><u>JfrUnit<\/u><\/a>\u00a0\u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0443\u0442\u0435\u043c \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430, \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0445 \u043e\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/JDK_Flight_Recorder\" rel=\"noopener noreferrer nofollow\"><u>JDK Flight Recorder<\/u><\/a>\u00a0(JFR) \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0437 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u043a\u0438 \u0438\u043b\u0438 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.\u00a0\u042d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043b\u044e\u0431\u044b\u043c\u0438, \u043e\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043e \u0441\u0431\u043e\u0440\u043a\u0438 \u043c\u0443\u0441\u043e\u0440\u0430.\u00a0<\/p>\n<p>\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u043e \u043e\u043d \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/JDK_Mission_Control\" rel=\"noopener noreferrer nofollow\"><u>JDK Mission Control,<\/u><\/a>\u00a0\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043b\u0430\u0433\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 JFR.\u00a0JfrUnit \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f JFR \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>JfrUnit \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u00a0<a href=\"https:\/\/openjdk.java.net\/projects\/jdk\/16\/\" rel=\"noopener noreferrer nofollow\"><u>OpenJDK 16,<\/u><\/a>\u00a0\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432 Maven Central:<\/p>\n<pre><code class=\"xml\">&lt;dependency>   &lt;groupId>org.moditect.jfrunit&lt;\/groupId>   &lt;artifactId>jfrunit&lt;\/artifactId>   &lt;version>1.0.0.Alpha1&lt;\/version>   &lt;scope>test&lt;\/scope> &lt;\/dependency><\/code><\/pre>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0435\u0441\u0442\u0430 JUnit \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u00a0\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@JfrEventTest<\/code> \u043a \u043a\u043b\u0430\u0441\u0441\u0443 unit \u0442\u0435\u0441\u0442\u0430, \u0435\u0441\u043b\u0438 \u0442\u0435\u0441\u0442 \u043d\u0435 \u043e\u0442\u043c\u0435\u0447\u0435\u043d \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439\u00a0<code>@QuarkusTest<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0440\u0435\u0434\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Quarkus \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0441 \u0437\u0430\u043f\u0438\u0441\u044c\u044e JFR.\u00a0\u0422\u0435\u0441\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u00a0\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@EnableEvent<\/code> \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441\u0431\u043e\u0440\u043a\u0438 \u043c\u0443\u0441\u043e\u0440\u0430.\u00a0\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u0435\u0442\u043e\u0434 <code>jfrEvents.awaitEvents() <\/code>\u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043b\u044e\u0431\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 JFR \u043e\u0442 JVM \u0438\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e:<\/p>\n<pre><code class=\"java\">@JfrEventTest public class GarbageCollectionTest {     public JfrEvents jfrEvents = new JfrEvents();      @Test     @EnableEvent(\"jdk.GarbageCollection\")     public void testGarbageCollectionEvent() throws Exception {         System.gc();          jfrEvents.awaitEvents();          assertThat(jfrEvents).contains(event(\"jdk.GarbageCollection\"));     } }<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a Spock \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u043e\u0433\u043e \u0436\u0435 \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"java\">class GarbageCollectionSpec extends Specification { JfrEvents jfrEvents &lt;span style=\"margin: 0px; box-sizing: border-box; display: inline; -webkit-box-orient: horizontal; -webkit-box-direction: normal; flex-flow: row wrap; vertical-align: top; color: rgb(166, 127, 89); background: rgba(255, 255, 255, 0.5);\" class=\"token operator\">=&lt;\/span> &lt;span style=\"margin: 0px; box-sizing: border-box; display: inline; -webkit-box-orient: horizontal; -webkit-box-direction: normal; flex-flow: row wrap; vertical-align: top; color: rgb(0, 119, 170);\" class=\"token keyword\">new&lt;\/span> &lt;span style=\"margin: 0px; box-sizing: border-box; display: inline; -webkit-box-orient: horizontal; -webkit-box-direction: normal; flex-flow: row wrap; vertical-align: top;\" class=\"token class-name\">JfrEvents&lt;\/span>&lt;span style=\"margin: 0px; box-sizing: border-box; display: inline; -webkit-box-orient: horizontal; -webkit-box-direction: normal; flex-flow: row wrap; vertical-align: top; color: rgb(153, 153, 153);\" class=\"token punctuation\">(&lt;\/span>&lt;span style=\"margin: 0px; box-sizing: border-box; display: inline; -webkit-box-orient: horizontal; -webkit-box-direction: normal; flex-flow: row wrap; vertical-align: top; color: rgb(153, 153, 153);\" class=\"token punctuation\">)&lt;\/span>&lt;font style=\"margin: 0px; box-sizing: border-box;\">&lt;\/font>       @EnableEvent('jdk.GarbageCollection')     def 'Contains a garbage collection Jfr event'() {         when:         System.gc()          then:         jfrEvents['jdk.GarbageCollection']     } }<\/code><\/pre>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u043e\u0433\u043e, \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0434\u0435\u0442\u0430\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u00a0<code>Thread.sleep()<\/code>:<\/p>\n<pre><code class=\"java\">@Test @EnableEvent(\"jdk.ThreadSleep\") public void testThreadSleepEvent() throws Exception {     Thread.sleep(42);      jfrEvents.awaitEvents();      assertThat(jfrEvents)             .contains(event(\"jdk.ThreadSleep\")             .with(\"time\", Duration.ofMillis(42))); }<\/code><\/pre>\n<p>JfrUnit \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438.\u00a0\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u0442 \u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0435, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"java\">@Test @EnableEvent(\"jdk.ObjectAllocationInNewTLAB\") @EnableEvent(\"jdk.ObjectAllocationOutsideTLAB\") public void testAllocationEvent() throws Exception {     String threadName = Thread.currentThread().getName();      \/\/ Application logic which creates objects      jfrEvents.awaitEvents();     long sum = jfrEvents.filter(this::isObjectAllocationEvent)             .filter(event -> event.getThread().getJavaName().equals(threadName))             .mapToLong(this::getAllocationSize)             .sum();      assertThat(sum).isLessThan(43_000_000);     assertThat(sum).isGreaterThan(42_000_000); }  private boolean isObjectAllocationEvent(RecordedEvent re) {     String name = re.getEventType().getName();     return name.equals(\"jdk.ObjectAllocationInNewTLAB\") ||             name.equals(\"jdk.ObjectAllocationOutsideTLAB\"); }  private long getAllocationSize(RecordedEvent recordedEvent) {     return recordedEvent.getEventType().getName()             .equals(\"jdk.ObjectAllocationInNewTLAB\") ?             recordedEvent.getLong(\"tlabSize\") :             recordedEvent.getLong(\"allocationSize\"); }<\/code><\/pre>\n<p>\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u00ab<em>\u00bb, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440,\u00a0<\/em><code>@EnableEvent(\"jdk.ObjectAllocation\") <\/code>\u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 ObjectAllocation.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f,\u00a0\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>jfrEvents.reset()<\/code>, \u0447\u0442\u043e\u0431\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u00a0\u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f\u00a0\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <code>reset()<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java\">for (int i = 0; i &lt; ITERATIONS; i++) {     \/\/ Application logic      jfrEvents.awaitEvents();       \/\/ Assertions      jfrEvents.reset(); }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438, \u043a\u0430\u043a Hibernate, \u0441\u0430\u043c\u0438 \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043d\u043e \u0432 \u044d\u0442\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445\u00a0<a href=\"https:\/\/developers.redhat.com\/blog\/2020\/10\/29\/collect-jdk-flight-recorder-events-at-runtime-with-jmc-agent#overview_of_the_jdk_flight_recorder_toolchain\" rel=\"noopener noreferrer nofollow\"><u>\u0430\u0433\u0435\u043d\u0442 JMC<\/u><\/a>\u00a0\u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439.\u00a0\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0433\u0435\u043d\u0442\u0430 JMC \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0441\u043e\u0431\u044b\u0442\u0438\u044f SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430) SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0438\u0445 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.\u00a0\u042d\u0442\u043e \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043d\u0430 \u0441\u0435\u0441\u0441\u0438\u0438 DevNation Tech Talk\u00a0<a href=\"https:\/\/developers.redhat.com\/devnation\/tech-talks\/jfrunit\" rel=\"noopener noreferrer nofollow\"><u>Continuous performance regression testing with JfrUnit,<\/u><\/a>\u00a0\u0430 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 GitHub:\u00a0<a href=\"https:\/\/github.com\/moditect\/jfrunit-examples\" rel=\"noopener noreferrer nofollow\"><u>Examples for JfrUnit<\/u><\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/582632\/\"> https:\/\/habr.com\/ru\/articles\/582632\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/twitter.com\/gunnarmorling\" rel=\"noopener noreferrer nofollow\"><u>\u0413\u0443\u043d\u043d\u0430\u0440 \u041c\u043e\u0440\u043b\u0438\u043d\u0433<\/u><\/a>, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0432 Red Hat,\u00a0<a href=\"https:\/\/www.morling.dev\/blog\/introducing-jfrunit-1-0-0-alpha1\/\" rel=\"noopener noreferrer nofollow\"><u>\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b<\/u><\/a>\u00a0JfrUnit, \u043d\u043e\u0432\u0443\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u0443 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441 <a href=\"https:\/\/junit.org\/\" rel=\"noopener noreferrer nofollow\"><u>JUnit<\/u><\/a>\u00a0\u0438\u043b\u0438\u00a0<a href=\"https:\/\/spockframework.org\/\" rel=\"noopener noreferrer nofollow\"><u>Spock Framework<\/u><\/a>.\u00a0\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043a\u043b\u0438\u043a\u0430, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438, \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0444\u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0438\u043b\u0438 \u0441\u0435\u0442\u044c, \u0430 \u043d\u0435 \u0441\u0430\u043c\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c.\u00a0<a href=\"https:\/\/github.com\/moditect\/jfrunit\/blob\/main\/README.md\" rel=\"noopener noreferrer nofollow\"><u>JfrUnit<\/u><\/a>\u00a0\u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0443\u0442\u0435\u043c \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430, \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0445 \u043e\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/JDK_Flight_Recorder\" rel=\"noopener noreferrer nofollow\"><u>JDK Flight Recorder<\/u><\/a>\u00a0(JFR) \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0437 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u043a\u0438 \u0438\u043b\u0438 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.\u00a0\u042d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043b\u044e\u0431\u044b\u043c\u0438, \u043e\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043e \u0441\u0431\u043e\u0440\u043a\u0438 \u043c\u0443\u0441\u043e\u0440\u0430.\u00a0<\/p>\n<p>\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u043e \u043e\u043d \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/JDK_Mission_Control\" rel=\"noopener noreferrer nofollow\"><u>JDK Mission Control,<\/u><\/a>\u00a0\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043b\u0430\u0433\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 JFR.\u00a0JfrUnit \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f JFR \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>JfrUnit \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u00a0<a href=\"https:\/\/openjdk.java.net\/projects\/jdk\/16\/\" rel=\"noopener noreferrer nofollow\"><u>OpenJDK 16,<\/u><\/a>\u00a0\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432 Maven Central:<\/p>\n<pre><code class=\"xml\">&lt;dependency>   &lt;groupId>org.moditect.jfrunit&lt;\/groupId>   &lt;artifactId>jfrunit&lt;\/artifactId>   &lt;version>1.0.0.Alpha1&lt;\/version>   &lt;scope>test&lt;\/scope> &lt;\/dependency><\/code><\/pre>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0435\u0441\u0442\u0430 JUnit \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u00a0\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@JfrEventTest<\/code> \u043a \u043a\u043b\u0430\u0441\u0441\u0443 unit \u0442\u0435\u0441\u0442\u0430, \u0435\u0441\u043b\u0438 \u0442\u0435\u0441\u0442 \u043d\u0435 \u043e\u0442\u043c\u0435\u0447\u0435\u043d \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439\u00a0<code>@QuarkusTest<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0440\u0435\u0434\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Quarkus \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0441 \u0437\u0430\u043f\u0438\u0441\u044c\u044e JFR.\u00a0\u0422\u0435\u0441\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u00a0\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@EnableEvent<\/code> \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441\u0431\u043e\u0440\u043a\u0438 \u043c\u0443\u0441\u043e\u0440\u0430.\u00a0\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u0435\u0442\u043e\u0434 <code>jfrEvents.awaitEvents() <\/code>\u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043b\u044e\u0431\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 JFR \u043e\u0442 JVM \u0438\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e:<\/p>\n<pre><code class=\"java\">@JfrEventTest public class GarbageCollectionTest {     public JfrEvents jfrEvents = new JfrEvents();      @Test     @EnableEvent(\"jdk.GarbageCollection\")     public void testGarbageCollectionEvent() throws Exception {         System.gc();          jfrEvents.awaitEvents();          assertThat(jfrEvents).contains(event(\"jdk.GarbageCollection\"));     } }<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a Spock \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u043e\u0433\u043e \u0436\u0435 \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"java\">class GarbageCollectionSpec extends Specification { JfrEvents jfrEvents &lt;span style=\"margin: 0px; box-sizing: border-box; display: inline; -webkit-box-orient: horizontal; -webkit-box-direction: normal; flex-flow: row wrap; vertical-align: top; color: rgb(166, 127, 89); background: rgba(255, 255, 255, 0.5);\" class=\"token operator\">=&lt;\/span> &lt;span style=\"margin: 0px; box-sizing: border-box; display: inline; -webkit-box-orient: horizontal; -webkit-box-direction: normal; flex-flow: row wrap; vertical-align: top; color: rgb(0, 119, 170);\" class=\"token keyword\">new&lt;\/span> &lt;span style=\"margin: 0px; box-sizing: border-box; display: inline; -webkit-box-orient: horizontal; -webkit-box-direction: normal; flex-flow: row wrap; vertical-align: top;\" class=\"token class-name\">JfrEvents&lt;\/span>&lt;span style=\"margin: 0px; box-sizing: border-box; display: inline; -webkit-box-orient: horizontal; -webkit-box-direction: normal; flex-flow: row wrap; vertical-align: top; color: rgb(153, 153, 153);\" class=\"token punctuation\">(&lt;\/span>&lt;span style=\"margin: 0px; box-sizing: border-box; display: inline; -webkit-box-orient: horizontal; -webkit-box-direction: normal; flex-flow: row wrap; vertical-align: top; color: rgb(153, 153, 153);\" class=\"token punctuation\">)&lt;\/span>&lt;font style=\"margin: 0px; box-sizing: border-box;\">&lt;\/font>       @EnableEvent('jdk.GarbageCollection')     def 'Contains a garbage collection Jfr event'() {         when:         System.gc()          then:         jfrEvents['jdk.GarbageCollection']     } }<\/code><\/pre>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u043e\u0433\u043e, \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0434\u0435\u0442\u0430\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u00a0<code>Thread.sleep()<\/code>:<\/p>\n<pre><code class=\"java\">@Test @EnableEvent(\"jdk.ThreadSleep\") public void testThreadSleepEvent() throws Exception {     Thread.sleep(42);      jfrEvents.awaitEvents();      assertThat(jfrEvents)             .contains(event(\"jdk.ThreadSleep\")             .with(\"time\", Duration.ofMillis(42))); }<\/code><\/pre>\n<p>JfrUnit \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438.\u00a0\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u0442 \u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0435, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"java\">@Test @EnableEvent(\"jdk.ObjectAllocationInNewTLAB\") @EnableEvent(\"jdk.ObjectAllocationOutsideTLAB\") public void testAllocationEvent() throws Exception {     String threadName = Thread.currentThread().getName();      \/\/ Application logic which creates objects      jfrEvents.awaitEvents();     long sum = jfrEvents.filter(this::isObjectAllocationEvent)             .filter(event -> event.getThread().getJavaName().equals(threadName))             .mapToLong(this::getAllocationSize)             .sum();      assertThat(sum).isLessThan(43_000_000);     assertThat(sum).isGreaterThan(42_000_000); }  private boolean isObjectAllocationEvent(RecordedEvent re) {     String name = re.getEventType().getName();     return name.equals(\"jdk.ObjectAllocationInNewTLAB\") ||             name.equals(\"jdk.ObjectAllocationOutsideTLAB\"); }  private long getAllocationSize(RecordedEvent recordedEvent) {     return recordedEvent.getEventType().getName()             .equals(\"jdk.ObjectAllocationInNewTLAB\") ?             recordedEvent.getLong(\"tlabSize\") :             recordedEvent.getLong(\"allocationSize\"); }<\/code><\/pre>\n<p>\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u00ab<em>\u00bb, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440,\u00a0<\/em><code>@EnableEvent(\"jdk.ObjectAllocation\") <\/code>\u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 ObjectAllocation.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f,\u00a0\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>jfrEvents.reset()<\/code>, \u0447\u0442\u043e\u0431\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u00a0\u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f\u00a0\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <code>reset()<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java\">for (int i = 0; i &lt; ITERATIONS; i++) {     \/\/ Application logic      jfrEvents.awaitEvents();       \/\/ Assertions      jfrEvents.reset(); }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438, \u043a\u0430\u043a Hibernate, \u0441\u0430\u043c\u0438 \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043d\u043e \u0432 \u044d\u0442\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445\u00a0<a href=\"https:\/\/developers.redhat.com\/blog\/2020\/10\/29\/collect-jdk-flight-recorder-events-at-runtime-with-jmc-agent#overview_of_the_jdk_flight_recorder_toolchain\" rel=\"noopener noreferrer nofollow\"><u>\u0430\u0433\u0435\u043d\u0442 JMC<\/u><\/a>\u00a0\u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439.\u00a0\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0433\u0435\u043d\u0442\u0430 JMC \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0441\u043e\u0431\u044b\u0442\u0438\u044f SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430) SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0438\u0445 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.\u00a0\u042d\u0442\u043e \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043d\u0430 \u0441\u0435\u0441\u0441\u0438\u0438 DevNation Tech Talk\u00a0<a href=\"https:\/\/developers.redhat.com\/devnation\/tech-talks\/jfrunit\" rel=\"noopener noreferrer nofollow\"><u>Continuous performance regression testing with JfrUnit,<\/u><\/a>\u00a0\u0430 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 GitHub:\u00a0<a href=\"https:\/\/github.com\/moditect\/jfrunit-examples\" rel=\"noopener noreferrer nofollow\"><u>Examples for JfrUnit<\/u><\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/582632\/\"> https:\/\/habr.com\/ru\/articles\/582632\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-404071","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/404071","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=404071"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/404071\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=404071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=404071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=404071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}