Skip to content

Commit

Permalink
[Profiling] Scale diff functions summary (#160708)
Browse files Browse the repository at this point in the history
This PR fixes a problem where the Total sample summary value wasn't
being scaled when a scale factor is selected.

<img width="1794" alt="Screenshot 2023-06-28 at 10 34 14 AM"
src="https://github.com/elastic/kibana/assets/55978943/8a77d01c-ab10-4b53-b9fa-855a2710c78b">
  • Loading branch information
cauemarcondes authored Jun 28, 2023
1 parent fdd709b commit d0358f5
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions x-pack/plugins/profiling/public/components/topn_functions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,28 @@ interface Row {
}

function TotalSamplesStat({
totalSamples,
newSamples,
baselineTotalSamples,
baselineScaleFactor,
comparisonTotalSamples,
comparisonScaleFactor,
}: {
totalSamples: number;
newSamples: number | undefined;
baselineTotalSamples: number;
baselineScaleFactor?: number;
comparisonTotalSamples?: number;
comparisonScaleFactor?: number;
}) {
const value = totalSamples.toLocaleString();
const scaledBaselineTotalSamples = scaleValue({
value: baselineTotalSamples,
scaleFactor: baselineScaleFactor,
});

const value = scaledBaselineTotalSamples.toLocaleString();

const sampleHeader = i18n.translate('xpack.profiling.functionsView.totalSampleCountLabel', {
defaultMessage: ' Total sample estimate: ',
});

if (newSamples === undefined || newSamples === 0) {
if (comparisonTotalSamples === undefined || comparisonTotalSamples === 0) {
return (
<EuiStat
title={<EuiText style={{ fontWeight: 'bold' }}>{value}</EuiText>}
Expand All @@ -67,8 +76,13 @@ function TotalSamplesStat({
);
}

const diffSamples = totalSamples - newSamples;
const percentDelta = (diffSamples / (totalSamples - diffSamples)) * 100;
const scaledComparisonTotalSamples = scaleValue({
value: comparisonTotalSamples,
scaleFactor: comparisonScaleFactor,
});

const diffSamples = scaledBaselineTotalSamples - scaledComparisonTotalSamples;
const percentDelta = (diffSamples / (scaledBaselineTotalSamples - diffSamples)) * 100;

return (
<EuiStat
Expand Down Expand Up @@ -408,8 +422,10 @@ export function TopNFunctionsTable({
return (
<>
<TotalSamplesStat
totalSamples={totalCount}
newSamples={comparisonTopNFunctions?.TotalCount}
baselineTotalSamples={totalCount}
baselineScaleFactor={baselineScaleFactor}
comparisonTotalSamples={comparisonTopNFunctions?.TotalCount}
comparisonScaleFactor={comparisonScaleFactor}
/>
<EuiSpacer size="s" />
<EuiHorizontalRule margin="none" style={{ height: 2 }} />
Expand Down

0 comments on commit d0358f5

Please sign in to comment.