From 2ced9416d3b87ffbe247974724420e357d667035 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cau=C3=AA=20Marcondes?=
<55978943+cauemarcondes@users.noreply.github.com>
Date: Tue, 23 Jul 2024 16:21:08 +0100
Subject: [PATCH] [Profiling] Fix TopN function total CPU value (#188848)
closes https://github.com/elastic/kibana/issues/188511
15
---
.../cypress/e2e/profiling_views/functions.cy.ts | 14 +++++++-------
.../public/components/topn_functions/utils.test.ts | 2 +-
.../public/components/topn_functions/utils.ts | 13 ++++++-------
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/x-pack/plugins/observability_solution/profiling/e2e/cypress/e2e/profiling_views/functions.cy.ts b/x-pack/plugins/observability_solution/profiling/e2e/cypress/e2e/profiling_views/functions.cy.ts
index 3fc0c535639ee..4c42069188b3a 100644
--- a/x-pack/plugins/observability_solution/profiling/e2e/cypress/e2e/profiling_views/functions.cy.ts
+++ b/x-pack/plugins/observability_solution/profiling/e2e/cypress/e2e/profiling_views/functions.cy.ts
@@ -36,8 +36,8 @@ describe('Functions page', () => {
const firstRowSelector = '[data-grid-row-index="0"] [data-test-subj="dataGridRowCell"]';
cy.get(firstRowSelector).eq(1).contains('1');
cy.get(firstRowSelector).eq(2).contains('vmlinux');
- cy.get(firstRowSelector).eq(3).contains('0.16%');
- cy.get(firstRowSelector).eq(4).contains('0.16%');
+ cy.get(firstRowSelector).eq(3).contains('5.46%');
+ cy.get(firstRowSelector).eq(4).contains('5.46%');
cy.get(firstRowSelector).eq(5).contains('3.97 lbs / 1.8 kg');
cy.get(firstRowSelector).eq(6).contains('$17.37');
cy.get(firstRowSelector).eq(7).contains('28');
@@ -56,8 +56,8 @@ describe('Functions page', () => {
{ parentKey: 'informationRows', key: 'executable', value: 'vmlinux' },
{ parentKey: 'informationRows', key: 'function', value: 'N/A' },
{ parentKey: 'informationRows', key: 'sourceFile', value: 'N/A' },
- { parentKey: 'impactEstimates', key: 'totalCPU', value: '0.16%' },
- { parentKey: 'impactEstimates', key: 'selfCPU', value: '0.16%' },
+ { parentKey: 'impactEstimates', key: 'totalCPU', value: '5.46%' },
+ { parentKey: 'impactEstimates', key: 'selfCPU', value: '5.46%' },
{ parentKey: 'impactEstimates', key: 'samples', value: '28' },
{ parentKey: 'impactEstimates', key: 'selfSamples', value: '28' },
{ parentKey: 'impactEstimates', key: 'coreSeconds', value: '1.4 seconds' },
@@ -118,7 +118,7 @@ describe('Functions page', () => {
columnIndex: 3,
highRank: 1,
lowRank: 389,
- highValue: '0.16%',
+ highValue: '5.46%',
lowValue: '0.00%',
},
{
@@ -126,8 +126,8 @@ describe('Functions page', () => {
columnIndex: 4,
highRank: 693,
lowRank: 44,
- highValue: '1.80%',
- lowValue: '0.01%',
+ highValue: '60.43%',
+ lowValue: '0.19%',
},
{
columnKey: 'annualizedCo2',
diff --git a/x-pack/plugins/observability_solution/profiling/public/components/topn_functions/utils.test.ts b/x-pack/plugins/observability_solution/profiling/public/components/topn_functions/utils.test.ts
index c7598f55acb0b..9142427790450 100644
--- a/x-pack/plugins/observability_solution/profiling/public/components/topn_functions/utils.test.ts
+++ b/x-pack/plugins/observability_solution/profiling/public/components/topn_functions/utils.test.ts
@@ -46,7 +46,7 @@ describe('Top N functions: Utils', () => {
expect(getTotalCount()).toEqual(0);
});
it('returns value from topNFunctions', () => {
- expect(getTotalCount({ TotalCount: 10 } as TopNFunctions)).toEqual(10);
+ expect(getTotalCount({ selfCPU: 10 } as TopNFunctions)).toEqual(10);
});
});
});
diff --git a/x-pack/plugins/observability_solution/profiling/public/components/topn_functions/utils.ts b/x-pack/plugins/observability_solution/profiling/public/components/topn_functions/utils.ts
index 74f63f1dd5689..6cb68bd54f153 100644
--- a/x-pack/plugins/observability_solution/profiling/public/components/topn_functions/utils.ts
+++ b/x-pack/plugins/observability_solution/profiling/public/components/topn_functions/utils.ts
@@ -32,7 +32,7 @@ export function scaleValue({ value, scaleFactor = 1 }: { value: number; scaleFac
return value * scaleFactor;
}
-export const getTotalCount = (topNFunctions?: TopNFunctions) => topNFunctions?.TotalCount ?? 0;
+export const getTotalCount = (topNFunctions?: TopNFunctions) => topNFunctions?.selfCPU ?? 0;
export interface IFunctionRow {
id: string;
@@ -95,15 +95,15 @@ export function getFunctionsRows({
scaleFactor: baselineScaleFactor,
});
- const totalCPUPerc = (topN.CountInclusive / topNFunctions.TotalCount) * 100;
- const selfCPUPerc = (topN.CountExclusive / topNFunctions.TotalCount) * 100;
+ const totalCPUPerc = (topN.CountInclusive / topNFunctions.selfCPU) * 100;
+ const selfCPUPerc = (topN.CountExclusive / topNFunctions.selfCPU) * 100;
const impactEstimates =
totalSeconds > 0
? calculateImpactEstimates({
countExclusive: topN.CountExclusive,
countInclusive: topN.CountInclusive,
- totalSamples: topNFunctions.TotalCount,
+ totalSamples: topNFunctions.selfCPU,
totalSeconds,
})
: undefined;
@@ -124,10 +124,9 @@ export function getFunctionsRows({
selfCPU: comparisonRow.CountExclusive,
totalCPU: comparisonRow.CountInclusive,
selfCPUPerc:
- selfCPUPerc - (comparisonRow.CountExclusive / comparisonTopNFunctions.TotalCount) * 100,
+ selfCPUPerc - (comparisonRow.CountExclusive / comparisonTopNFunctions.selfCPU) * 100,
totalCPUPerc:
- totalCPUPerc -
- (comparisonRow.CountInclusive / comparisonTopNFunctions.TotalCount) * 100,
+ totalCPUPerc - (comparisonRow.CountInclusive / comparisonTopNFunctions.selfCPU) * 100,
selfAnnualCO2kgs: comparisonRow.selfAnnualCO2kgs,
selfAnnualCostUSD: comparisonRow.selfAnnualCostUSD,
totalAnnualCO2kgs: comparisonRow.totalAnnualCO2kgs,