Closed Bug 1490821 Opened 6 years ago Closed 6 years ago

Use JSONPrinter for PCCount profiler

Categories

(Core :: JavaScript Engine, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
mozilla65
Tracking Status
firefox64 --- wontfix
firefox65 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(1 file, 2 obsolete files)

While working on bug 1482846 and bug 1485066, I saw that the PCCount profiler code could be updated to use the |JSONPrinter| class instead of doing its adhoc JSON processing.


(Note: I have no idea if the PCCount profiler is actually still used.)
Attached patch bug1490821.patch (obsolete) — Splinter Review
Updates the PCCount profiler to use JSONPrinter and adds some testing functions for the profiler. 

vm/BytecodeUtil.cpp
- Change the PCCount profiler functions to use JSONPrinter, which allows to remove quite a bit of code and makes it more readable, too. 

vm/JSONPrinter.{h,cpp}
- Add an option to omit indentation, because (1) this matches the previous PCCount profiler output and (2) it makes the JSON output smaller, which is probably necessary for the PCCount profiler output, because it can become quite large.
- Add JSONPrinter::beginList() to start a new JSON array.
- And improve the performance of the JSONPrinter by replacing printf() calls with putChar() resp. put() where applicable.

vm/Printer.{h,cpp}
- Add a helper to emit a correctly JSON quoted string.

vm/StringType.{h,cpp}
- Make js::StringToSource a static function, because it's no longer called outside of StringType.cpp.

builtin/TestingFunctions.cpp
- Add testing functions for the PCCounter profiler. These are not fuzzing safe, because the profiler uses PersistentRooted variables (see JSRuntime::scriptAndCountsVector), which makes it necessary to manually clean up the profiler data before destroying the runtime.

jit-test/tests/profiler/pc-count-profiler.js
- And add a simple smoke test for the PCCount profiler API.
Attachment #9008559 - Flags: review?(tcampbell)
(In reply to André Bargull [:anba] from comment #0)
> (Note: I have no idea if the PCCount profiler is actually still used.)

If not, we should remove it instead. I know Jan used it a few years ago with the -B option of the JS shell.
Flags: needinfo?(jdemooij)
(In reply to Nicolas B. Pierron [:nbp] from comment #2)
> If not, we should remove it instead. I know Jan used it a few years ago with
> the -B option of the JS shell.

I've used -D to see basic block counts for Ion but I don't think that uses the JSON printer?
Flags: needinfo?(jdemooij)
Comment on attachment 9008559 [details] [diff] [review]
bug1490821.patch

Review of attachment 9008559 [details] [diff] [review]:
-----------------------------------------------------------------

Excellent work as usual.

::: js/src/builtin/TestingFunctions.cpp
@@ +6319,5 @@
>              return false;
>          }
> +
> +        RootedObject pccount(cx, JS_NewPlainObject(cx));
> +        if (!pccount || !JS_DefineProperty(cx, obj, "pccount", pccount, 0)) {

Break into two ifs since JS_DefineProperty has side-effects.

::: js/src/vm/Printer.cpp
@@ +317,3 @@
>      using CharPtr = mozilla::RangedPtr<const CharT>;
>  
> +    const char* escapeMap = target == QuoteTarget::String ? js_EscapeMap : JSONEscapeMap;

Parens around the (target == QuoteTarget::String) for readability.
Attachment #9008559 - Flags: review?(tcampbell) → review+
Priority: -- → P2
Attached patch bug1490821.patch (obsolete) — Splinter Review
Updated per review comments, carrying r+.
Attachment #9008559 - Attachment is obsolete: true
Attachment #9020737 - Flags: review+
Attached patch bug1490821.patchSplinter Review
Updated to also JSON-quote the file name to ensure backslashes are correctly escaped on Windows.
Attachment #9020737 - Attachment is obsolete: true
Flags: needinfo?(andrebargull)
Attachment #9020831 - Flags: review+
https://hg.mozilla.org/mozilla-central/rev/719c199e6398
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla65
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: