Skip to content

Commit 98a6407

Browse files
authored
Added memory consumption to dataset report (#1670)
1 parent 0819a2a commit 98a6407

16 files changed

Lines changed: 51 additions & 22 deletions

File tree

src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Flow\ETL\{Cache, Config, NativePHPRandomValueGenerator, RandomValueGenerator};
1010
use Flow\ETL\Config\Cache\CacheConfigBuilder;
1111
use Flow\ETL\Config\Sort\SortConfigBuilder;
12+
use Flow\ETL\Dataset\Memory\Unit;
1213
use Flow\ETL\Filesystem\FilesystemStreams;
13-
use Flow\ETL\Monitoring\Memory\Unit;
1414
use Flow\ETL\Pipeline\Optimizer;
1515
use Flow\ETL\Pipeline\Optimizer\{BatchSizeOptimization, LimitOptimization};
1616
use Flow\ETL\Row\EntryFactory;

src/core/etl/src/Flow/ETL/Config/Sort/SortConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Flow\ETL\Config\Sort;
66

7-
use Flow\ETL\Monitoring\Memory\Unit;
7+
use Flow\ETL\Dataset\Memory\Unit;
88
use Flow\ETL\Sort\SortAlgorithms;
99

1010
final readonly class SortConfig

src/core/etl/src/Flow/ETL/Config/Sort/SortConfigBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Flow\ETL\Config\Sort;
66

7-
use Flow\ETL\Monitoring\Memory\Unit;
7+
use Flow\ETL\Dataset\Memory\Unit;
88
use Flow\ETL\Sort\SortAlgorithms;
99

1010
final class SortConfigBuilder

src/core/etl/src/Flow/ETL/DataFrame.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use function Flow\ETL\DSL\{analyze, refs, to_output};
88
use Flow\ETL\DataFrame\GroupedDataFrame;
9-
use Flow\ETL\Dataset\{Report, Statistics};
9+
use Flow\ETL\Dataset\{Memory\Consumption, Report, Statistics};
1010
use Flow\ETL\Dataset\Statistics\{Columns, ExecutionTime, HighResolutionTime};
1111
use Flow\ETL\Exception\{InvalidArgumentException, RuntimeException};
1212
use Flow\ETL\Extractor\FileExtractor;
@@ -757,6 +757,7 @@ public function run(?callable $callback = null, bool|Analyze $analyze = false) :
757757
$analyze = $analyze === true ? analyze() : $analyze;
758758

759759
if ($analyze) {
760+
$memory = new Consumption();
760761
$startedAt = $this->context->config->clock()->now();
761762
$startTime = HighResolutionTime::now();
762763
$columnStatistics = $analyze->collectColumnStatistics() ? new Columns() : null;
@@ -770,6 +771,7 @@ public function run(?callable $callback = null, bool|Analyze $analyze = false) :
770771

771772
if ($analyze) {
772773
$totalRows += $rows->count();
774+
$memory->capture();
773775

774776
if ($schema !== null) {
775777
$schema = $schema->merge($rows->schema());
@@ -794,6 +796,7 @@ public function run(?callable $callback = null, bool|Analyze $analyze = false) :
794796
new Statistics(
795797
$totalRows,
796798
new ExecutionTime($startedAt, $endedAt, $startTime->diff($endTime)),
799+
$memory,
797800
$columnStatistics
798801
)
799802
);

src/core/etl/src/Flow/ETL/Monitoring/Memory/Configuration.php renamed to src/core/etl/src/Flow/ETL/Dataset/Memory/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Flow\ETL\Monitoring\Memory;
5+
namespace Flow\ETL\Dataset\Memory;
66

77
use Flow\ETL\Exception\InvalidArgumentException;
88

src/core/etl/src/Flow/ETL/Monitoring/Memory/Consumption.php renamed to src/core/etl/src/Flow/ETL/Dataset/Memory/Consumption.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Flow\ETL\Monitoring\Memory;
5+
namespace Flow\ETL\Dataset\Memory;
66

77
final class Consumption
88
{
@@ -14,14 +14,14 @@ final class Consumption
1414

1515
public function __construct()
1616
{
17-
$this->initial = Unit::fromBytes(\memory_get_usage());
17+
$this->initial = Unit::fromBytes(\memory_get_usage(true));
1818
$this->min = $this->initial;
1919
$this->max = $this->initial;
2020
}
2121

22-
public function current() : Unit
22+
public function capture() : Unit
2323
{
24-
$current = Unit::fromBytes(\memory_get_usage());
24+
$current = Unit::fromBytes(\memory_get_usage(true));
2525

2626
if ($current->isGreaterThan($this->max)) {
2727
$this->max = $current;
@@ -36,7 +36,7 @@ public function current() : Unit
3636

3737
public function currentDiff() : Unit
3838
{
39-
return $this->current()->diff($this->initial);
39+
return $this->capture()->diff($this->initial);
4040
}
4141

4242
public function initial() : Unit

src/core/etl/src/Flow/ETL/Monitoring/Memory/Unit.php renamed to src/core/etl/src/Flow/ETL/Dataset/Memory/Unit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Flow\ETL\Monitoring\Memory;
5+
namespace Flow\ETL\Dataset\Memory;
66

77
use Flow\ETL\Exception\InvalidArgumentException;
88

src/core/etl/src/Flow/ETL/Dataset/Statistics.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
namespace Flow\ETL\Dataset;
66

7+
use Flow\ETL\Dataset\Memory\Consumption;
78
use Flow\ETL\Dataset\Statistics\{Columns, ExecutionTime};
89

910
final readonly class Statistics
1011
{
1112
public function __construct(
1213
private int $totalRows,
1314
public ExecutionTime $executionTime,
15+
public Consumption $memory,
1416
public ?Columns $columns,
1517
) {
1618
}

src/core/etl/src/Flow/ETL/Pipeline/SortingPipeline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Flow\ETL\Pipeline;
66

77
use function Flow\Filesystem\DSL\protocol;
8+
use Flow\ETL\Dataset\Memory\Unit;
89
use Flow\ETL\Exception\OutOfMemoryException;
910
use Flow\ETL\{Extractor, FlowContext, Loader, Pipeline, Transformer};
10-
use Flow\ETL\Monitoring\Memory\Unit;
1111
use Flow\ETL\Row\References;
1212
use Flow\ETL\Sort\ExternalSort\BucketsCache\FilesystemBucketsCache;
1313
use Flow\ETL\Sort\{ExternalSort, MemorySort};

src/core/etl/src/Flow/ETL/Sort/MemorySort.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
namespace Flow\ETL\Sort;
66

7-
use Flow\ETL\{Exception\OutOfMemoryException,
7+
use Flow\ETL\{
8+
Dataset\Memory\Configuration,
9+
Dataset\Memory\Consumption,
10+
Dataset\Memory\Unit,
11+
Exception\OutOfMemoryException,
812
Extractor,
913
FlowContext,
10-
Monitoring\Memory\Configuration,
11-
Monitoring\Memory\Consumption,
12-
Monitoring\Memory\Unit,
1314
Pipeline,
1415
Row\References,
15-
Rows};
16+
Rows
17+
};
1618
use Flow\ETL\Extractor\GeneratorExtractor;
1719

1820
final class MemorySort implements SortingAlgorithm

0 commit comments

Comments
 (0)