Skip to content

Commit 3752e37

Browse files
authored
🤖 Merge PR DefinitelyTyped#72240 Improve the frida-gum Profiler typings by @oleavr
1 parent ec9e7c0 commit 3752e37

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

types/frida-gum/frida-gum-tests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,10 @@ const moduleObserver = Process.attachModuleObserver({
454454
},
455455
});
456456
moduleObserver.detach();
457+
458+
// $ExpectType Profiler
459+
const profiler = new Profiler();
460+
const sampler = new BusyCycleSampler();
461+
for (const e of Process.getModuleByName("libc.so").enumerateExports().filter(e => e.type === "function")) {
462+
profiler.instrument(e.address, sampler);
463+
}

types/frida-gum/index.d.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4640,11 +4640,36 @@ declare namespace Cloak {
46404640
function hasFileDescriptor(fd: number): boolean;
46414641
}
46424642

4643+
/**
4644+
* Simple worst-case profiler built on top of Interceptor.
4645+
*
4646+
* Unlike a conventional profiler, which samples call stacks at a certain
4647+
* frequency, you decide the exact functions that you're interested in
4648+
* profiling.
4649+
*
4650+
* When any of those functions gets called, the profiler grabs a sample on
4651+
* entry, and another one upon return. It then subtracts the two, to compute how
4652+
* expensive the call was. If the resulting value is greater than what it's seen
4653+
* previously for the specific function, that value becomes its new worst-case.
4654+
*
4655+
* Whenever a new worst-case has been discovered, it isn't necessarily enough to
4656+
* know that most of the time/cycles/etc. was spent by a specific function. That
4657+
* function may only be slow with certain input arguments, for example.
4658+
*
4659+
* This is a situation where you can pass in `ProfilerInstrumentCallbacks` to
4660+
* implement a `describe()` callback for the specific function. Your callback
4661+
* should capture relevant context from the argument list and/or other state,
4662+
* and return a string that describes the new worst-case that was just
4663+
* discovered.
4664+
*
4665+
* When you later decide to call `generateReport()`, you'll find your computed
4666+
* descriptions embedded in each worst-case entry.
4667+
*/
46434668
declare class Profiler {
46444669
/**
46454670
* Starts instrumenting the specified function using the specified sampler.
46464671
*/
4647-
instrument(functionAddress: NativePointerValue, sampler: Sampler, callbacks: ProfilerInstrumentCallbacks): void;
4672+
instrument(functionAddress: NativePointerValue, sampler: Sampler, callbacks?: ProfilerInstrumentCallbacks): void;
46484673

46494674
/**
46504675
* Generates an XML report from the live profiler state. May be called at

0 commit comments

Comments
 (0)