Bug 1776694 - Return profile with additional info from GetProfileDataAsGzippedArrayBuffer r=mstange

Differential Revision: https://phabricator.services.mozilla.com/D172555
This commit is contained in:
Nazım Can Altınova 2023-03-15 18:19:31 +00:00
Родитель dc7e0f3c89
Коммит 5d4ab6bd13
6 изменённых файлов: 64 добавлений и 8 удалений

Просмотреть файл

@ -148,6 +148,15 @@ declare namespace MockedExports {
arch: string;
}
interface ProfileGenerationAdditionalInformation {
sharedLibraries: SharedLibrary[];
}
interface ProfileAndAdditionalInformation {
profile: ArrayBuffer;
additionalInformation?: ProfileGenerationAdditionalInformation;
}
type Services = {
env: {
set: (name: string, value: string) => void;
@ -176,7 +185,7 @@ declare namespace MockedExports {
getProfileDataAsArrayBuffer: (sinceTime?: number) => Promise<ArrayBuffer>;
getProfileDataAsGzippedArrayBuffer: (
sinceTime?: number
) => Promise<ArrayBuffer>;
) => Promise<ProfileAndAdditionalInformation>;
IsActive: () => boolean;
sharedLibraries: SharedLibrary[];
};

Просмотреть файл

@ -339,7 +339,7 @@ async function captureProfile(pageContext) {
const profileCaptureResult = await Services.profiler
.getProfileDataAsGzippedArrayBuffer()
.then(
profile => ({ type: "SUCCESS", profile }),
({ profile }) => ({ type: "SUCCESS", profile }),
error => {
console.error(error);
return { type: "ERROR", error };

Просмотреть файл

@ -861,8 +861,10 @@ Tester.prototype = {
let path = Services.env.get("MOZ_UPLOAD_DIR");
let profilePath = PathUtils.join(path, filename);
try {
let profileData = await Services.profiler.getProfileDataAsGzippedArrayBuffer();
await IOUtils.write(profilePath, new Uint8Array(profileData));
const {
profile,
} = await Services.profiler.getProfileDataAsGzippedArrayBuffer();
await IOUtils.write(profilePath, new Uint8Array(profile));
this.currentTest.addResult(
new testResult({
name:

Просмотреть файл

@ -6,7 +6,34 @@
#include "ProfileAdditionalInformation.h"
#include "jsapi.h"
#include "js/JSON.h"
#include "js/PropertyAndElement.h"
#include "js/Value.h"
#include "mozilla/JSONStringWriteFuncs.h"
#include "mozilla/ipc/IPDLParamTraits.h"
#include "platform.h"
void mozilla::ProfileGenerationAdditionalInformation::ToJSValue(
JSContext* aCx, JS::MutableHandle<JS::Value> aRetVal) const {
// Get the shared libraries array.
JS::Rooted<JS::Value> sharedLibrariesVal(aCx);
{
JSONStringWriteFunc<nsCString> buffer;
JSONWriter w(buffer, JSONWriter::SingleLineStyle);
w.StartArrayElement();
AppendSharedLibraries(w, mSharedLibraries);
w.EndArray();
NS_ConvertUTF8toUTF16 buffer16(buffer.StringCRef());
MOZ_ALWAYS_TRUE(JS_ParseJSON(aCx,
static_cast<const char16_t*>(buffer16.get()),
buffer16.Length(), &sharedLibrariesVal));
}
JS::Rooted<JSObject*> additionalInfoObj(aCx, JS_NewPlainObject(aCx));
JS_SetProperty(aCx, additionalInfoObj, "sharedLibraries", sharedLibrariesVal);
aRetVal.setObject(*additionalInfoObj);
}
namespace IPC {

Просмотреть файл

@ -585,14 +585,29 @@ nsProfiler::GetProfileDataAsGzippedArrayBuffer(double aSinceTime,
}
JSContext* cx = jsapi.cx();
// Get the profile typedArray.
JSObject* typedArray = dom::ArrayBuffer::Create(
cx, outBuff.Length(), outBuff.Elements());
if (typedArray) {
JS::Rooted<JS::Value> val(cx, JS::ObjectValue(*typedArray));
promise->MaybeResolve(val);
} else {
if (!typedArray) {
promise->MaybeReject(NS_ERROR_OUT_OF_MEMORY);
return;
}
JS::Rooted<JS::Value> typedArrayValue(cx,
JS::ObjectValue(*typedArray));
// Get the additional information object.
JS::Rooted<JS::Value> additionalInfoVal(cx);
if (aResult.mAdditionalInformation.isSome()) {
aResult.mAdditionalInformation->ToJSValue(cx, &additionalInfoVal);
} else {
additionalInfoVal.setUndefined();
}
// Create the return object.
JS::Rooted<JSObject*> resultObj(cx, JS_NewPlainObject(cx));
JS_SetProperty(cx, resultObj, "profile", typedArrayValue);
JS_SetProperty(cx, resultObj, "additionalInformation",
additionalInfoVal);
promise->MaybeResolve(resultObj);
},
[promise](nsresult aRv) { promise->MaybeReject(aRv); });

Просмотреть файл

@ -15,6 +15,7 @@
#define ProfileAdditionalInformation_h
#include "shared-libraries.h"
#include "js/Value.h"
namespace IPC {
class MessageReader;
@ -40,6 +41,8 @@ struct ProfileGenerationAdditionalInformation {
void FinishGathering() { mSharedLibraries.DeduplicateEntries(); }
void ToJSValue(JSContext* aCx, JS::MutableHandle<JS::Value> aRetVal) const;
SharedLibraryInfo mSharedLibraries;
};