{"id":327666,"date":"2022-01-10T08:59:00","date_gmt":"2022-01-10T08:59:00","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=327666"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=327666","title":{"rendered":"<span>profile-guided \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u043a\u043e\u0434\u0443<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\" class=\"article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u043a\u043e\u0434\u0443 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/github.com\/quasilyte\/gogrep\" rel=\"nofollow noopener noreferrer\">gogrep<\/a> \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/github.com\/quasilyte\/perf-heatmap\" rel=\"nofollow noopener noreferrer\">perf-heatmap<\/a>, \u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c profile-guided \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u043a\u043e\u0434\u0443.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443 \u043f\u043e\u0438\u0441\u043a\u0430, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u0447\u0442\u043e \u043b\u0435\u0436\u0430\u0442 \u043d\u0430 &#171;\u0433\u043e\u0440\u044f\u0447\u0435\u043c&#187; \u043f\u0443\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0427\u0435\u0440\u0435\u0437 perf-heatmap \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0442\u043e\u0433\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 &#171;\u0433\u043e\u0440\u044f\u0447\u0430\u044f&#187;.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/a9\/xv\/tb\/a9xvtbb0_gzuvebzlobcw9wyjb4.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/a9\/xv\/tb\/a9xvtbb0_gzuvebzlobcw9wyjb4.jpeg\" data-blurred=\"true\"\/><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"vvedenie\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0417\u0430\u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0438\u0441\u043a \u043a\u043e\u0434\u0430 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0442\u0438\u043f\u0430 <a href=\"https:\/\/github.com\/google\/pprof\" rel=\"nofollow noopener noreferrer\">pprof<\/a> (\u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u043e\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0447\u0435\u0440\u0435\u0437 <code>go tool pprof<\/code>)?<\/p>\n<p>  <\/p>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0443\u0437\u043a\u0438\u0435 \u043c\u0435\u0441\u0442\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u043e\u043f \u043f\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c. \u041d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0435\u0449\u0438 \u0442\u0440\u0443\u0434\u043d\u043e \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0431\u044b \u0432\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u0438 <code>append()<\/code> \u0432\u044b\u0437\u043e\u0432\u044b \u0432 \u043f\u0440\u043e\u0444\u0438\u043b\u0435, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0432 \u0440\u0430\u0437\u043d\u044b\u0439 \u043a\u043e\u0434 (\u043f\u0440\u0438\u0447\u0451\u043c \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430)? \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0447\u0430\u0441\u0442\u044c \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u043e <code>append()<\/code>, \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u044d\u043a\u0441\u043a\u043b\u044e\u0437\u0438\u0432\u043d\u044b\u043c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>growslice()<\/code> \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041c\u043e\u0436\u043d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0434\u0435\u0440\u0435\u0432\u0443 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u043d\u043e \u0432\u044b \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u0443\u043f\u0440\u0451\u0442\u0435\u0441\u044c \u0432 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u043b\u044e\u0431\u043e\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0432\u0430\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u044e\u0442 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"https:\/\/pkg.go.dev\/fmt#Errorf\" rel=\"nofollow noopener noreferrer\">fmt.Errorf<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442. \u0422\u043e \u0435\u0441\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 <code>fmt.Errorf(\"error occured\")<\/code>. \u041a\u0430\u043a \u0440\u0430\u0437, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0441\u043c\u044b\u0441\u043b \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c \u044d\u0442\u0438 \u0432\u044b\u0437\u043e\u0432\u044b \u043d\u0430 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c <a href=\"https:\/\/pkg.go.dev\/errors#New\" rel=\"nofollow noopener noreferrer\">errors.New()<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f gogrep+heatmap \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a \u0440\u0430\u0437 \u044d\u0442\u043e: \u043d\u0430\u0439\u0442\u0438 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u0432 \u043a\u043e\u0434\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0433\u043e\u0440\u044f\u0447\u0438\u0445 \u043f\u0443\u0442\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c CPU \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>  <\/p>\n<h2 id=\"podgotavlivaem-cpu-profil\">\u041f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c CPU \u043f\u0440\u043e\u0444\u0438\u043b\u044c<\/h2>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <code>-cpuprofile<\/code><\/li>\n<li>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u043a\u0443 \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/li>\n<li>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u043b\u0435\u0442\u0443 \u0447\u0435\u0440\u0435\u0437 \u0440\u0443\u0447\u043a\u0443<\/li>\n<li>\u041d\u0430 \u0447\u0430\u0441\u0442\u0438 \u043c\u0430\u0448\u0438\u043d (\u0438\u043b\u0438 \u043d\u0430 \u0441\u0442\u0435\u0439\u0434\u0436\u0435) \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u043c<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0438\u043b\u0438 \u0434\u043e\u043b\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 3 \u0438 4. \u041e\u043d\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0414\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 CLI \u0443\u0442\u0438\u043b\u0438\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 2-\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0442\u044c CPU-\u043f\u0440\u043e\u0444\u0438\u043b\u0438 \u043d\u0430 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430\u0445 \u043c\u043e\u0436\u043d\u043e, \u043d\u043e \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0447\u0435\u043d\u044c \u0441\u0432\u043e\u0435\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 &#171;\u043f\u0435\u0440\u0435\u0433\u0440\u0435\u0432\u0430\u0442\u044c\u0441\u044f&#187; \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u043e\u043c, \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a-\u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0410 \u0435\u0449\u0451 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0441\u043e\u0431\u043e \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u044b\u043c \u043f\u0440\u0438 \u0438\u0445 \u0441\u0431\u043e\u0440\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u044d\u0442\u043e \u043d\u0430 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u043e\u0432 \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Go.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\"># \u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u0444\u0430\u0439\u043b cpu.out, # \u043d\u0430\u0434 \u043d\u0438\u043c \u043c\u044b \u0438 \u0431\u0443\u0434\u0435\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. # \u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u042d\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0437\u0430\u0439\u043c\u0451\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0443\u0442. go test -cpuprofile cpu.out -bench . -timeout 20m -count 2 bytes<\/code><\/pre>\n<p>  <\/p>\n<p>Go \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u043e\u0444\u0438\u043b\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <a href=\"https:\/\/github.com\/google\/pprof\/blob\/6f57359322fd9ce2d6dabde5b733714463416b6f\/proto\/profile.proto\" rel=\"nofollow noopener noreferrer\">profile.proto<\/a>. \u041f\u0430\u0440\u0441\u0438\u0442\u044c \u044d\u0442\u0438 \u0444\u0430\u0439\u043b\u044b \u0438\u0437 Go \u043c\u043e\u0436\u043d\u043e \u043f\u0430\u043a\u0435\u0442\u043e\u043c <a href=\"https:\/\/pkg.go.dev\/github.com\/google\/pprof\/profile\" rel=\"nofollow noopener noreferrer\">github.com\/google\/pprof\/profile<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"perf-heatmap\">perf-heatmap<\/h2>\n<p>  <\/p>\n<p>\u041f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/github.com\/quasilyte\/perf-heatmap.git\" rel=\"nofollow noopener noreferrer\">perf-heatmap<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0441\u043e\u0431\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 CPU-\u043f\u0440\u043e\u0444\u0438\u043b\u044f \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <code>profile.proto<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412\u043c\u0435\u0441\u0442\u0435 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0432 \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0442\u0435 \u0438\u0434\u0451\u0442 \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>perf-heatmap json cpu.out<\/code> \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c heatmap \u0438\u043d\u0434\u0435\u043a\u0441 \u0432 JSON \u0444\u043e\u0440\u043c\u0430\u0442\u0435<\/li>\n<li><code>perf-heatmap stat cpu.out<\/code> \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c heatmap \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d Go, \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u0443\u0442\u0438\u043b\u0438\u0442\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">go install github.com\/quasilyte\/perf-heatmap\/cmd\/perf-heatmap@latest<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0441\u0435\u043c\u043f\u043b\u044b, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0432 <code>cpu.out<\/code>, \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u043b\u0438\u0441\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u0440\u0430\u0437, \u0442\u0430\u043a \u0447\u0442\u043e \u043c\u0451\u0440\u0442\u0432\u044b\u0439 \u043a\u043e\u0434 \u0442\u0443\u0434\u0430 \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>-threshold<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u0441\u0435\u043c\u043f\u043b\u043e\u0432 \u0438\u0437 \u0442\u043e\u043f\u0430 \u043c\u044b \u0431\u0435\u0440\u0451\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>-threshold=0.5<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0431\u0435\u0440\u0451\u043c top50% \u0432\u0441\u0435\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, <code>-threshold=1.0<\/code> \u0440\u0430\u0437\u043c\u0435\u0442\u0438\u0442 \u0432\u0441\u0435 \u0441\u0435\u043c\u043f\u043b\u044b, \u0430 <code>-threshold=0.1<\/code> \u0432\u043e\u0437\u044c\u043c\u0451\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u044b\u0435 \u0433\u043e\u0440\u044f\u0447\u0438\u0435 10%.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043f\u043e\u043f\u0430\u0432\u0448\u0438\u0435 \u0432 topN% \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043d\u0430 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0435 5 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439: \u043e\u0442 \u043c\u0435\u043d\u0435\u0435 \u0433\u043e\u0440\u044f\u0447\u0435\u0439 \u043a \u0441\u0430\u043c\u043e\u0439 \u043f\u044b\u043b\u0430\u044e\u0449\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0441\u0435\u043c\u043f\u043b\u044b (topN%) \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0433\u043e\u0440\u044f\u0447\u0438\u043c\u0438, \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043b\u0438\u0448\u044c \u0432 \u0438\u0445 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0435 (heat level \u043e\u0442 1 \u0434\u043e 5 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e). \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0430 \u0443\u0440\u043e\u0432\u043d\u044f: \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 (\u043f\u043e \u0444\u0430\u0439\u043b\u0443) \u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 (\u043f\u043e \u0432\u0441\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435). \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c. \u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043f\u0440\u0438 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435 \u0444\u0430\u0439\u043b\u0430 \u0432 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u043a\u0443\u0441\u043a\u0438 \u043a\u043e\u0434\u0430 \u0431\u043e\u043b\u0435\u0435 \u0433\u043e\u0440\u044f\u0447\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0432 \u044d\u0442\u043e\u043c \u0436\u0435 \u0444\u0430\u0439\u043b\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">$ perf-heatmap stat -filename buffer.go cpu.out   func bytes.(Buffer).Write ($GOROOT\/src\/bytes\/buffer.go):     line  168:   0.34s L=0 G=3     line  170:   0.56s L=4 G=3     line  172:   0.44s L=0 G=3     line  174:   3.97s L=5 G=5   func bytes.(Buffer).Grow ($GOROOT\/src\/bytes\/buffer.go):     line  161:   0.11s L=5 G=1   func bytes.(Buffer).Read ($GOROOT\/src\/bytes\/buffer.go):     line  298:   0.05s L=0 G=0     line  299:   0.25s L=4 G=2     line  307:   3.34s L=5 G=5     line  308:   0.06s L=0 G=1     line  309:   0.18s L=3 G=2     line  310:   0.14s L=0 G=2   func bytes.(Buffer).grow ($GOROOT\/src\/bytes\/buffer.go):     line  117:   0.04s L=0 G=0     line  118:   0.01s L=0 G=0     line  120:   0.04s L=2 G=0     line  128:   0.01s L=0 G=0     line  132:   0.01s L=0 G=0     line  137:   0.19s L=5 G=2     line  142:   0.16s L=4 G=2     line  143:   0.05s L=3 G=0     line  148:   0.01s L=0 G=0   func bytes.(Buffer).tryGrowByReslice ($GOROOT\/src\/bytes\/buffer.go):     line  107:   1.26s L=5 G=4     line  108:   0.27s L=0 G=2   func bytes.makeSlice ($GOROOT\/src\/bytes\/buffer.go):     line  229:   0.16s L=5 G=2   func bytes.(Buffer).empty ($GOROOT\/src\/bytes\/buffer.go):     line   69:   0.25s L=5 G=2   func bytes.(Buffer).WriteByte ($GOROOT\/src\/bytes\/buffer.go):     line  263:   0.66s L=0 G=4     line  265:   0.88s L=4 G=4     line  269:   1.11s L=5 G=4     line  270:   0.86s L=0 G=4   func bytes.(Buffer).readSlice ($GOROOT\/src\/bytes\/buffer.go):     line  418:   0.05s L=0 G=0     line  419:   0.97s L=5 G=4     line  420:   0.01s L=0 G=0   func bytes.(Buffer).Len ($GOROOT\/src\/bytes\/buffer.go):     line   73:   0.01s L=5 G=0   func bytes.(Buffer).ReadString ($GOROOT\/src\/bytes\/buffer.go):     line  438:   1.03s L=0 G=4     line  439:   3.30s L=5 G=5   func bytes.(Buffer).WriteRune ($GOROOT\/src\/bytes\/buffer.go):     line  277:   0.25s L=0 G=2     line  283:   0.22s L=0 G=2     line  284:   0.36s L=3 G=3     line  288:   2.51s L=5 G=4     line  289:   0.54s L=4 G=3     line  290:   0.17s L=0 G=2   func bytes.(Buffer).String ($GOROOT\/src\/bytes\/buffer.go):     line   65:   0.04s L=5 G=0<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>L<\/code> \u2014 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c<\/li>\n<li><code>G<\/code> \u2014 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"heat-levels-na-primere\">heat levels \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435<\/h2>\n<p>  <\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u0441\u0435\u043c\u043f\u043b\u043e\u0432:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>file<\/th>\n<th>line<\/th>\n<th>value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>a.go<\/code><\/td>\n<td><code>10<\/code><\/td>\n<td><code>100<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>a.go<\/code><\/td>\n<td><code>10<\/code><\/td>\n<td><code>200<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>a.go<\/code><\/td>\n<td><code>13<\/code><\/td>\n<td><code>200<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>40<\/code><\/td>\n<td><code>100<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>40<\/code><\/td>\n<td><code>300<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>40<\/code><\/td>\n<td><code>400<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>49<\/code><\/td>\n<td><code>100<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>49<\/code><\/td>\n<td><code>100<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>50<\/code><\/td>\n<td><code>500<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>51<\/code><\/td>\n<td><code>100<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 \u2014 \u043f\u0440\u043e\u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 value \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 CPU \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u0445 value \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0432 \u043d\u0430\u043d\u043e\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u0442\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0435 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b.<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>file<\/th>\n<th>line<\/th>\n<th>total value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>a.go<\/code><\/td>\n<td><code>10<\/code><\/td>\n<td><code>300<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>a.go<\/code><\/td>\n<td><code>13<\/code><\/td>\n<td><code>200<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>40<\/code><\/td>\n<td><code>800<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>49<\/code><\/td>\n<td><code>200<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>50<\/code><\/td>\n<td><code>500<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>51<\/code><\/td>\n<td><code>100<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0441\u0441\u0442\u0430\u0432\u0438\u0442\u044c global heat level, \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044e \u0438 \u0432\u0437\u044f\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 N, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u043f\u043e\u0434 threshold. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, threshold=0.5, \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u0431\u0435\u0440\u0451\u043c \u043f\u0435\u0440\u0432\u044b\u0435 3 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>file<\/th>\n<th>line<\/th>\n<th>total value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>+<code>b.go<\/code>+<\/td>\n<td>+<code>40<\/code>+<\/td>\n<td>+<code>800<\/code>+<\/td>\n<\/tr>\n<tr>\n<td>+<code>b.go<\/code>+<\/td>\n<td>+<code>50<\/code>+<\/td>\n<td>+<code>500<\/code>+<\/td>\n<\/tr>\n<tr>\n<td>+<code>a.go<\/code>+<\/td>\n<td>+<code>10<\/code>+<\/td>\n<td>+<code>300<\/code>+<\/td>\n<\/tr>\n<tr>\n<td><code>a.go<\/code><\/td>\n<td><code>13<\/code><\/td>\n<td><code>200<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>49<\/code><\/td>\n<td><code>200<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>51<\/code><\/td>\n<td><code>100<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0432\u043e\u0437\u044c\u043c\u0451\u043c threshold=0.9, \u0442\u043e \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u043f\u0430\u0434\u0443\u0442 \u0443\u0436\u0435 5 \u0437\u0430\u043f\u0438\u0441\u0435\u0439: 800, 500, 300, 200, 200.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 global \u0443\u0440\u043e\u0432\u043d\u044f, \u0442\u043e \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>file<\/th>\n<th>line<\/th>\n<th>total value<\/th>\n<th>global heat level<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>40<\/code><\/td>\n<td><code>800<\/code><\/td>\n<td>5<\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>50<\/code><\/td>\n<td><code>500<\/code><\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td><code>a.go<\/code><\/td>\n<td><code>10<\/code><\/td>\n<td><code>300<\/code><\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td><code>a.go<\/code><\/td>\n<td><code>13<\/code><\/td>\n<td><code>200<\/code><\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>49<\/code><\/td>\n<td><code>200<\/code><\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td><code>b.go<\/code><\/td>\n<td><code>51<\/code><\/td>\n<td><code>100<\/code><\/td>\n<td>0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u043c\u044b \u0431\u0435\u0440\u0451\u043c \u0441\u0440\u0435\u0437\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0430\u0439\u043b\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u0432\u0441\u0435\u0445 \u0441\u0435\u043c\u043f\u043b\u043e\u0432 \u0441\u0440\u0430\u0437\u0443.<\/p>\n<p>  <\/p>\n<h2 id=\"gogrep--heatmap\">gogrep + heatmap<\/h2>\n<p>  <\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c gogrep:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">go install github.com\/quasilyte\/gogrep\/cmd\/gogrep@latest<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u043f\u0430\u043a\u0435\u0442\u0443 bytes:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\"># \u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e, \u0433\u0434\u0435 \u043b\u0435\u0436\u0430\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u043a\u043e\u0434\u044b \u043f\u0430\u043a\u0435\u0442\u0430 bytes cd $(go env GOROOT)\/src\/bytes  # \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u043e\u0438\u0441\u043a append() \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u0435\u0436\u0430\u0442 \u0432 \u0433\u043e\u0440\u044f\u0447\u0438\u0445 \u043f\u0443\u0442\u044f\u0445 # \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u0444\u0438\u043b\u044c\u0442\u0440\u0443\u044f \u043f\u043e \u043d\u0430\u0448\u0435\u043c\u0443 \u043f\u0440\u043e\u0444\u0438\u043b\u044e, \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u043c\u0443 \u043d\u0430 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430\u0445) gogrep -heatmap cpu.out . 'append($*_)' '$$.IsHot()' bytes.go:487:               spans = append(spans, span{start, i}) bytes.go:500:       spans = append(spans, span{start, len(s)}) bytes.go:626:           return append([]byte(\"\"), s...) bytes.go:656:           return append([]byte(\"\"), s...) bytes.go:702:           b = append(b, byte(c)) bytes.go:710:               b = append(b, replacement...) bytes.go:715:       b = append(b, s[i:i+wid]...) found 7 matches<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0438\u0434\u0438\u043e\u043c\u0430\u043c\u0438 gogrep \u0438 <a href=\"https:\/\/github.com\/quasilyte\/go-ruleguard\" rel=\"nofollow noopener noreferrer\">ruleguard<\/a>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u0442 \u0440\u0430\u0437\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>$*_<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043e\u0442 0 \u0434\u043e N \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439<\/li>\n<li><code>$$<\/code> \u2014 \u044d\u0442\u043e \u043e\u0441\u043e\u0431\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 &#171;\u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043c\u0430\u0442\u0447&#187;, \u043a\u0430\u043a <code>$0<\/code> \u0432 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043a\u0430\u0445<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e gogrep \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>threshold=0.5<\/code>. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>heatmap-threshold<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">gogrep -heatmap cpu.out -heatmap-threshold 0.1 . 'append($*_)' '$$.IsHot()' bytes.go:487:               spans = append(spans, span{start, i}) bytes.go:500:       spans = append(spans, span{start, len(s)}) bytes.go:626:           return append([]byte(\"\"), s...) bytes.go:656:           return append([]byte(\"\"), s...) found 4 matches<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0438\u0441\u043a \u0432\u0441\u0435\u0445 <code>fmt.Errorf()<\/code> \u043e\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">gogrep -heatmap cpu.out . 'fmt.Errorf($format)' '$format.IsHot()'<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u044f \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u0443\u044e gogrep \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>$format<\/code>, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b \u0444\u0438\u043b\u044c\u0442\u0440 <code>IsHot()<\/code> \u0438\u043c\u0435\u043d\u043d\u043e \u043a \u043d\u0435\u0439. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043f\u043e\u0447\u0442\u0438 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435, \u043a\u0430\u043a \u0438 <code>$$.IsHot()<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u044f\u0437\u044b\u043a \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 gogrep \u043e\u043f\u0438\u0441\u0430\u043d \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/505652\/\">gogrep: \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0438 \u0437\u0430\u043c\u0435\u043d\u0430 Go \u043a\u043e\u0434\u0430<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0421\u043a\u0440\u0438\u043d\u043a\u0430\u0441\u0442 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>gogrep<\/code> \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <a href=\"https:\/\/asciinema.org\/a\/j8JM8prOFscPPCXJJPXpYwjil\" rel=\"nofollow noopener noreferrer\">asciinema<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"kak-heatmap-integrirovan-v-gogrep\">\u041a\u0430\u043a heatmap \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0432 gogrep<\/h2>\n<p>  <\/p>\n<p>\u0411\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e <code>&lt;var>.IsHot()<\/code> \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u0442\u0438\u043f\u0430 <code>func isHot(var gogrepVar) bool<\/code>.<\/p>\n<p>  <\/p>\n<p><code>gogrepVar<\/code> \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 AST \u0434\u0435\u0440\u0435\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0432\u043f\u0430\u043b\u043e \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 <code>$$<\/code> \u044d\u0442\u043e \u0434\u0435\u0440\u0435\u0432\u043e \u0446\u0435\u043b\u0438\u043a\u043e\u043c, \u0434\u043b\u044f \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u0430 <code>$x<\/code> \u044d\u0442\u043e \u043f\u043e\u0434\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c statement. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 <code>gogrepVar<\/code> \u2014 \u044d\u0442\u043e \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u044b\u0439 <code>ast.Node<\/code> \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043b\u044e\u0441 \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0448\u0430\u0431\u043b\u043e\u043d\u0430.<\/p>\n<p>  <\/p>\n<p><code>isHot(v)<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0441\u0442\u0440\u043e\u043a <code>[fromLine, toLine]<\/code> \u0447\u0435\u0440\u0435\u0437 <code>ast.Node<\/code>. \u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/pkg.go.dev\/github.com\/quasilyte\/perf-heatmap\/heatmap#Index.QueryLineRange\" rel=\"nofollow noopener noreferrer\">Index.QueryLineRange(&#8230;, fromLine, toLine)<\/a>. \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043d\u0430\u0439\u0434\u0451\u0442\u0441\u044f \u0441\u0435\u043c\u043f\u043b, \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0439 threshold, <code>isHot(v)<\/code> \u0432\u0435\u0440\u043d\u0451\u0442 true.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u0439\u0442\u0438 \u0433\u043e\u0440\u044f\u0447\u0438\u0439 \u043a\u043e\u0434 \u043f\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0448\u0438\u0440\u0435 \u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0417\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f (\u0430\u043d\u043e\u043d\u0438\u043c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438) \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438.<\/p>\n<p>  <\/p>\n<h2 id=\"plagin-vs-code\">\u041f\u043b\u0430\u0433\u0438\u043d VS Code<\/h2>\n<p>  <\/p>\n<p><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=quasilyte.perf-heatmap\" rel=\"nofollow noopener noreferrer\">perf-heatmap on marketplace.visualstudio.com<\/a><\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0443\u0442\u0438\u043b\u0438\u0442\u044b perf-heatmap, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <a href=\"https:\/\/github.com\/gopherjs\/gopherjs\" rel=\"nofollow noopener noreferrer\">gopherjs<\/a> \u0434\u043b\u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 Go-\u043a\u043e\u0434\u0430 \u0432 JS, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 VS Code \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<ol>\n<li>CPU \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 heatmap \u0438\u043d\u0434\u0435\u043a\u0441 \u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>perf-heatmap.loadProfile<\/code><\/li>\n<li>\u041a\u043e\u0433\u0434\u0430 \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d, \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043c\u0435\u0442\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u043b\u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u043e\u043c heat level&#8217;\u043e\u0432. \u0414\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438 <code>perf-heatmap.annotateLocalLevels<\/code> \u0438 <code>perf-heatmap.annotateGlobalLevels<\/code><\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041d\u0430\u0439\u0442\u0438 \u044d\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437 <code>ctrl+shift+p<\/code> (<code>workbench.action.showCommands<\/code>).<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/ad\/w-\/bc\/adw-bc8dt_sej_rqm5hvshmzsw4.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/ad\/w-\/bc\/adw-bc8dt_sej_rqm5hvshmzsw4.jpeg\" data-blurred=\"true\"\/><\/p>\n<p>  <\/p>\n<blockquote><p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u043d\u0435 \u0431\u044b\u043b\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439. \u042d\u0442\u043e \u043b\u0438\u0448\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0439 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043a\u0430\u043a \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c perf-heatmap. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u0438\u0434\u0435\u044f, \u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043c\u043e\u0447\u044c \u0441 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/github.com\/quasilyte\/vscode-perf-heatmap\" rel=\"nofollow noopener noreferrer\">\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f<\/a>.<\/p><\/blockquote>\n<p>  <\/p>\n<h2 id=\"mapping-simvolov-iz-profilya\">\u041c\u0430\u043f\u043f\u0438\u043d\u0433 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u044f<\/h2>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e heatmap \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 CPU \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0431\u044b\u043b \u0441\u043e\u0431\u0440\u0430\u043d \u043d\u0430 \u0432\u0430\u0448\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435, \u043a\u0430\u043a \u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u0438\u043a, \u0442\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435\u0442. \u041c\u043e\u0436\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0444\u0430\u0439\u043b\u0430 \u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u0434\u0430 \u0445\u043e\u0442\u044c \u043f\u043e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u043c \u043f\u0443\u0442\u044f\u043c.<\/p>\n<p>  <\/p>\n<p>\u0421\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u0431\u0438\u043d\u0430\u0440\u043d\u0438\u043a \u043c\u043e\u0433 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c build \u0430\u0433\u0435\u043d\u0442\u0435, \u0430 \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0441\u044f \u0432 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438. \u0423 \u0432\u0430\u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043f\u0443\u0442\u044c \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0441\u0442\u0438 \u043a \u043c\u043e\u0434\u0443\u043b\u044e (go modules), \u0430 \u043d\u0430 build \u0430\u0433\u0435\u043d\u0442\u0435 \u0441\u0431\u043e\u0440\u043a\u0430 \u043c\u043e\u0433\u043b\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u0435\u043d\u0434\u043e\u0440\u0438\u043d\u0433\u0430.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c\u0441\u044f \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041e\u0442\u0440\u0435\u0437\u0430\u044f \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u043e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 (\u0432\u044b\u0447\u0438\u0442\u0430\u044f \u0442\u0430\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u043e\u0442 \u043a\u043e\u0440\u043d\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430), \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043c\u0430\u0442\u0447\u0438\u043d\u0433.<\/p>\n<p>  <\/p>\n<p>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044d\u0442\u043e\u0442 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e. \u0410 \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0441\u0435\u043c\u043f\u043b, \u0442\u043e \u044d\u0442\u043e \u0432\u043e\u0432\u0441\u0435 \u043d\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0435\u0434\u044c \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u044f. \u0411\u044b\u043b\u043e \u0431\u044b \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u043f\u043e \u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u041d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (\u0432\u0435\u0434\u044c \u043e\u043d\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0430 \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438).<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u044d\u0442\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c, heatmap \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u043a\u043b\u044e\u0447\/\u043e\u0442\u043f\u0435\u0447\u0430\u0442\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0441\u0442\u043e \u0432 \u043a\u043e\u0434\u0435, \u043d\u043e \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"go\">type Key struct {     \/\/ TypeName is a receiver type name for methods.     \/\/ For functions it should be empty.     TypeName string      \/\/ FuncName is a Go function name.     \/\/ For methods, TypeName+FuncName compose a full method name.     FuncName string      \/\/ Filename is a base part of the full file path.     Filename string      \/\/ PkgName is the name of the package that defines this symbol.     PkgName string }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043d\u0430\u0448 \u043a\u043b\u044e\u0447 \u0440\u0430\u0432\u0435\u043d <code>Key{\"Buffer\", \"Write\", \"buffer.go\", \"bytes\"}<\/code>, \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0438\u043d\u0434\u0435\u043a\u0441\u0443:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>QueryLine(key, 10) => HeatLevel<\/code><\/li>\n<li><code>QueryLineRange(key, 20, 40) => []HeatLevel<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>HeatLevel \u2014 \u044d\u0442\u043e \u043f\u0430\u0440\u0430 <code>{LocalHeatLevel, GlobalHeatLevel}<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u043d\u0435\u0442 \u0441\u0435\u043c\u043f\u043b\u043e\u0432 \u0438\u043b\u0438 \u043e\u043d\u0438 \u043d\u0438\u0436\u0435 \u043f\u043e\u0440\u043e\u0433\u0430 threshold, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0432\u043d\u044b 0.<\/p>\n<p>  <\/p>\n<h2 id=\"zaklyuchitelnye-slova\">\u0417\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430<\/h2>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"\/img\/image-loader.svg\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/8b4\/40b\/572\/8b440b5720e2a1bb8e28e438c73d65f2.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0423 \u043c\u0435\u043d\u044f \u043d\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0440\u043f\u0443\u0441\u0430 \u043b\u0443\u0447\u0448\u0438\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432. \u0427\u0430\u0441\u0442\u044c \u0438\u0437 performance \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432 <a href=\"https:\/\/github.com\/go-critic\/go-critic\" rel=\"nofollow noopener noreferrer\">go-critic<\/a> (\u0445\u043e\u0442\u044f \u043e\u043d \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 CPU \u043f\u0440\u043e\u0444\u0438\u043b\u0438). gogrep+heatmap \u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u0430\u043a \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u0430\u0448\u0438\u0445 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432. <\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0442\u0430\u043a \u0436\u0435 \u043d\u0435 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0442\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439 \u0438\u0437 pprof \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>gogrep+heatmap \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0432\u0430\u0448 \u0430\u0440\u0441\u0435\u043d\u0430\u043b. \u042d\u0442\u0430 \u0441\u0432\u044f\u0437\u043a\u0430 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0430\u043c \u043a\u043e\u0433\u0434\u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0443 \u043c\u0435\u043d\u044f \u043d\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u0438\u0445 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043e\u043a, \u044f \u043f\u044b\u0442\u0430\u044e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u0442 \u0432\u0430\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">$ gogrep --heatmap cpu.out . \\   'var $b bytes.Buffer; $*_; return $b.$m()' \\   '$m.Text() == \"String\" &amp;&amp; $m.IsHot()'<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>bytes.Buffer<\/code>, \u0433\u0434\u0435 \u043c\u044b \u0432 \u043a\u043e\u043d\u0446\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0443. \u0412 \u044d\u0442\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0431\u0443\u0444\u0435\u0440 \u043d\u0430 <code>strings.Builder<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e <code>$b.String()<\/code> \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>$m<\/code> \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u0442\u043e\u043c \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432 \u0444\u0438\u043b\u044c\u0442\u0440\u0435, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u0441\u043e <code>String<\/code>. \u0421\u0434\u0435\u043b\u0430\u043d\u043e \u044d\u0442\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 <code>IsHot()<\/code>. <\/p>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>$$.IsHot()<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u043b\u043e \u0431\u044b, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0439 \u0441\u0435\u043c\u043f\u043b \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u043d\u0430 \u043f\u0443\u0442\u0438 \u043e\u0442 <code>var $b bytes.Buffer<\/code> \u0434\u043e <code>return $b.String()<\/code> \u0441\u0434\u0435\u043b\u0430\u043b \u0431\u044b \u043c\u0430\u0442\u0447 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0439. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>$b.IsHot()<\/code> \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043e \u043a \u043f\u0435\u0440\u0432\u043e\u0439 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u043c\u0430\u0442\u0447 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0435\u0440\u0432\u044b\u043c \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u043f\u0440\u043e\u0444\u0438\u043b\u044c, \u0442\u043e \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0442\u0430\u043c <code>bytes.(*Buffer).String()<\/code> \u0438 \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0433\u043e\u0440\u044f\u0447\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0442\u0435\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u043d\u0430\u0439\u0442\u0438 \u043f\u0443\u0442\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (pprof \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0436\u0435 \u0433\u0440\u0430\u0444\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435). \u041d\u043e \u0447\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e \u2014 \u044d\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u0441 \u043a\u0430\u043a\u0438\u043c\u0438-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u043a\u0435\u0439\u0441\u0430\u043c\u0438. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0448\u0435 \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443 \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u0435\u0441\u0442\u044c \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u2014 \u0432\u0437\u044f\u0442\u044c <code>strings.Builder<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u043f\u043e\u0440\u0430 \u0431\u044b \u0443\u0436\u0435 \u0437\u0430\u043a\u0440\u0443\u0433\u043b\u044f\u0442\u044c\u0441\u044f, \u043d\u043e \u043d\u0435\u0442. \u0412\u043e\u0442 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">$ gogrep --heatmap cpu.out . \\   'return $*_, errors.New($x)' \\   '$$.IsHot() &amp;&amp; $x.IsStringLit()'<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043a\u0440\u0443\u043f\u043d\u043e\u0439 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u0442\u043d\u0438 \u043c\u0435\u0441\u0442, \u0433\u0434\u0435 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f <code>errors.New<\/code> \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0433\u043e\u0440\u044f\u0447\u0435\u0435 \u043c\u0435\u0441\u0442\u043e. \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u0430\u0435\u0442\u0435\u0441\u044c \u0430\u0442\u0430\u043a\u0435 \u0438\u043b\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0435\u0441\u043e\u0432\u0441\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0442\u043e \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e. \u041a\u0430\u043a \u0436\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 <code>errors.New()<\/code> \u0432\u043e\u043e\u0431\u0449\u0435 \u0435\u0441\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c? \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u044c! \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u044b \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u0442\u0430\u043a \u0436\u0435 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0442 \u0441\u043b\u0443\u0447\u0430\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438, \u0442\u0438\u043f\u0430 <code>errors.New(\"foo: \" + msg)<\/code>, \u0433\u0434\u0435 \u043c\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u0442\u0430\u043a \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0435\u0434\u0438\u043d\u043e\u0436\u0434\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u043e\u0442 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u0418\u0437 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <code>errors.New()<\/code> \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0442\u043e\u043b\u044c\u043a\u043e 2-3 \u0442\u0435\u0445, \u0447\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0442\u043e\u0438\u0442 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c.<\/p>\n<\/div>\n<\/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\/post\/596755\/\"> https:\/\/habr.com\/ru\/post\/596755\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\" class=\"article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u043a\u043e\u0434\u0443 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/github.com\/quasilyte\/gogrep\" rel=\"nofollow noopener noreferrer\">gogrep<\/a> \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/github.com\/quasilyte\/perf-heatmap\" rel=\"nofollow noopener noreferrer\">perf-heatmap<\/a>, \u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c profile-guided \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u043a\u043e\u0434\u0443.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443 \u043f\u043e\u0438\u0441\u043a\u0430, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u0447\u0442\u043e \u043b\u0435\u0436\u0430\u0442 \u043d\u0430 &#171;\u0433\u043e\u0440\u044f\u0447\u0435\u043c&#187; \u043f\u0443\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0427\u0435\u0440\u0435\u0437 perf-heatmap \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0442\u043e\u0433\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 &#171;\u0433\u043e\u0440\u044f\u0447\u0430\u044f&#187;.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/a9\/xv\/tb\/a9xvtbb0_gzuvebzlobcw9wyjb4.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/a9\/xv\/tb\/a9xvtbb0_gzuvebzlobcw9wyjb4.jpeg\" data-blurred=\"true\"\/><\/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-327666","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327666","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=327666"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327666\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}