Skip to content

Commit

Permalink
Shift the responsibility of checking profile's size to the browser.
Browse files Browse the repository at this point in the history
  • Loading branch information
ilonatommy committed Sep 11, 2024
1 parent 760689b commit 8e4bc94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/MemoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Xunit.Abstractions;
using Xunit;

Expand Down Expand Up @@ -47,7 +48,15 @@ public async Task RunSimpleAppWithProfiler()
BuildProject(config, assertAppBundle: false, extraArgs: extraArgs);

var result = await RunSdkStyleAppForBuild(new (Configuration: config, TestScenario: "ProfilerTest"));
Console.WriteLine($"Test output: {result}");
// ToDo: check if the file is created AND its size it bigger than 10MB - where do we look for it?
Regex regex = new Regex(@"Profile data of size (\d+) bytes");
var match = result.TestOutput
.Select(line => regex.Match(line))
.FirstOrDefault(m => m.Success);
Assert.True(match != null, $"TestOuptup did not contain log matching {regex}");
if (!int.TryParse(match.Groups[1].Value, out int fileSize))
{
Assert.Fail($"Failed to parse profile size from {match.Groups[1].Value} to int");
}
Assert.True(fileSize >= 10 * 1024, $"Profile file size is less than 10KB. Actual size: {fileSize} bytes.");
}
}
21 changes: 14 additions & 7 deletions src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/profiler.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
export function saveProfile(Module) {
let profileData = readProfileFile(Module);
const fileName = "output.mlpd";
let profileData = readProfileFile(Module, fileName);

if (!profileData) {
console.error("Profile data is empty or could not be read.");
return;
}

const a = document.createElement('a');
const blob = new Blob([profileData]);
a.href = URL.createObjectURL(blob);
a.download = "output.mlpd";
a.download = fileName;
// Append anchor to body.
document.body.appendChild(a);
a.click();

console.log(`TestOutput -> Profile data of size ${profileData.length} bytes started downloading.`);

// Remove anchor from body
document.body.removeChild(a);
}

function readProfileFile(Module) {
let profileFilePath="output.mlpd";
function readProfileFile(Module, fileName) {

var stat = Module.FS.stat(profileFilePath);
var stat = Module.FS.stat(fileName);

if (stat && stat.size > 0) {
return Module.FS.readFile(profileFilePath);
return Module.FS.readFile(fileName);
}
else {
console.debug(`Unable to fetch the profile file ${profileFilePath} as it is empty`);
console.debug(`Unable to fetch the profile file ${fileName} as it is empty`);
return null;
}
}

0 comments on commit 8e4bc94

Please sign in to comment.