Skip to content

Commit

Permalink
chore(Android): Migrate Hermes Instruments to Kotlin (#48378)
Browse files Browse the repository at this point in the history
Summary:
Time to migrate some of Hermes's instruments. I see that HermesMemoryDumper(`react/hermes/instrumentation/HermesMemoryDumper.h`) implements the interface on C++, ~but not sure if i need to update the `getId` call to just `id` (same with `getInternalStorage`) or if the interop between Kotlin and Java applies to these things as well. cortinico Any thoughts on your side would be appreciated.
HermesSamplingProfiler just became an object, since it was a singleton and a static anyway.
Here is what HermesMemoryDumper.h looks like:
<img width="1840" alt="Screenshot 2024-12-24 at 10 03 00" src="https://github.com/user-attachments/assets/d18e378a-9b23-47a9-83c9-402d29aeaa5f" />~
*Updated*: I ended up making them match the function signature on Cxx, because even if it does have that implicit behavior, doesn't feel right to tap into it like this.

## Changelog:

[INTERNAL] [FIXED] - Migrate HermesMemoryDumper and HermesSamplingProfiler to Kotlin

Pull Request resolved: #48378

Test Plan:
`/gradlew test`:
<img width="1840" alt="Screenshot 2024-12-24 at 09 54 29" src="https://github.com/user-attachments/assets/1b23fb6f-9da8-42e4-a348-7da868df77c1" />

Reviewed By: cortinico

Differential Revision: D67657481

Pulled By: philIip

fbshipit-source-id: 4fb5e003789d51d464d0cca5800704ea51324b69
  • Loading branch information
TheRogue76 authored and facebook-github-bot committed Jan 7, 2025
1 parent cd40e4e commit d22dbb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.hermes.instrumentation;
package com.facebook.hermes.instrumentation

public interface HermesMemoryDumper {
boolean shouldSaveSnapshot();
public fun shouldSaveSnapshot(): Boolean

String getInternalStorage();
public fun getInternalStorage(): String

String getId();
public fun getId(): String

void setMetaData(String crashId);
public fun setMetaData(crashId: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.hermes.instrumentation;
package com.facebook.hermes.instrumentation

import com.facebook.soloader.SoLoader;
import com.facebook.soloader.SoLoader

/** Hermes sampling profiler static JSI API. */
public class HermesSamplingProfiler {
static {
SoLoader.loadLibrary("jsijniprofiler");
public object HermesSamplingProfiler {
init {
SoLoader.loadLibrary("jsijniprofiler")
}

/** Start sample profiling. */
public static native void enable();
@JvmStatic public external fun enable()

/** Stop sample profiling. */
public static native void disable();
@JvmStatic public external fun disable()

/**
* Dump sampled stack traces to file.
*
* @param filename the file to dump sampling trace to.
*/
public static native void dumpSampledTraceToFile(String filename);

private HermesSamplingProfiler() {}
@JvmStatic public external fun dumpSampledTraceToFile(filename: String)
}

0 comments on commit d22dbb5

Please sign in to comment.