forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssembliesTotalSize.cs
More file actions
46 lines (39 loc) · 1.29 KB
/
AssembliesTotalSize.cs
File metadata and controls
46 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
// estimate the total memory needed for the assemblies
public class WasmCalculateInitialHeapSize : Task
{
[Required]
[NotNull]
public string[]? Assemblies { get; set; }
[Output]
public long? TotalSize { get; private set; }
public override bool Execute ()
{
long totalDllSize=0;
foreach (var asm in Assemblies)
{
var info = new FileInfo(asm);
if (!info.Exists)
{
Log.LogError($"Could not find assembly '{asm}'");
return false;
}
totalDllSize += info.Length;
}
// this is arbitrary guess about memory overhead of the runtime, after the assemblies are loaded
const double extraMemoryRatio = 1.2;
long memorySize = (long) (totalDllSize * extraMemoryRatio);
// round it up to 64KB page size for wasm
TotalSize = (memorySize + 0x10000) & 0xFFFF0000;
return true;
}
}