bamlab / flashlight

πŸ“±βš‘οΈ Lighthouse for Mobile - audits your app and gives a performance score to your Android apps (native, React Native, Flutter..). Measure performance on CLI, E2E tests, CI...
https://docs.flashlight.dev
MIT License
1.2k stars 29 forks source link

Atrace not getting collected on Moto G40 Phone Device #78

Closed nitish24p closed 1 year ago

nitish24p commented 1 year ago

WHAT

I used the custom script to profile an android app. The app is in release build with the profileable tag enabled. On debugging and going a little deep into the source code i realised that the atrace was not getting collected. On debugging a little more i see the error log

Unable to open file5037 (.package.appname) S 1113 1113 0 0 -1 1077952832 2417899 0 63 0 45820 17497 0 0 20 0 117 0 119065447 25016229888 58295 18446744073709551615 1 1 0 0 0 0 4612 1 1073775864 0 0 0 17 3 0 0 0 0 0 0 0 0 0 0 0 0 0

The Unable to open file comes from line number https://github.com/bamlab/flashlight/blob/94c07a10f7811e83f8e7dcc01537e310e9957b87/packages/android-performance-profiler/cpp-profiler/src/atrace.cpp#L56

On checking the path of the systrace file the source code mentions

std::string traceOutputPath = "/sys/kernel/debug/tracing/trace_pipe";

However on my device i see the trace file being created at the path /sys/kernel/tracing/trace_pipe. To verify this on one terminal i ran the command adb shell atrace -c view -t 999 and in another terminal did a simple cat /sys/kernel/tracing/trace_pipe . And i was able to get the atrace..

What am i to do here? is it possible the trace file locations vary as per devices? Also how do i fix the current case?

Device Info

[media.recorder.show_manufacturer_and_model]: [true]
[ro.board.platform]: [sm6150]
[ro.boot.hardware]: [qcom]
[ro.boot.hardware.revision]: [pvt]
[ro.boot.hardware.sku]: [XT2147-1]
[ro.boot.product.hardware.sku]: [d]
[ro.boot.revision]: [pvt]
[ro.boot.secure_hardware]: [1]
[ro.boot.serialno]: [ZD2222GDQ8]
[ro.build.version.sdk]: [30]
[ro.hardware]: [qcom]
[ro.hardware.egl]: [adreno]
[ro.hardware.nfc_nci]: [pn54x]
[ro.hardware.sensors]: [hanoip]
[ro.hardware.soc.manufacturer]: [qcom]
[ro.hardware.vulkan]: [adreno]
[ro.mot.build.version.sdk_int]: [31]
[ro.opa.device_model_id]: [motorola-hanoip]
[ro.product.brand]: [motorola]
[ro.product.build.version.sdk]: [30]
[ro.product.manufacturer]: [motorola]
[ro.product.model]: [moto g(40) fusion]
[ro.product.name]: [hanoip_retail]
[ro.product.odm.brand]: [motorola]
[ro.product.odm.manufacturer]: [motorola]
[ro.product.odm.model]: [moto g(60)]
[ro.product.product.brand]: [motorola]
[ro.product.product.manufacturer]: [motorola]
[ro.product.product.model]: [moto g(60)]
[ro.product.product.name]: [hanoip_retail]
[ro.product.system.brand]: [motorola]
[ro.product.system.manufacturer]: [motorola]
[ro.product.system.model]: [moto g(60)]
[ro.product.system_ext.brand]: [motorola]
[ro.product.system_ext.manufacturer]: [motorola]
[ro.product.system_ext.model]: [moto g(60)]
[ro.product.vendor.brand]: [motorola]
[ro.product.vendor.manufacturer]: [motorola]
[ro.product.vendor.model]: [moto g(60)]
[ro.revision]: [pvt]
[ro.serialno]: [ZD2222GDQ8]
[ro.system.build.version.sdk]: [30]
[ro.system_ext.build.version.sdk]: [30]
[ro.vendor.boot.serialno]: [ZD2222GDQ8]
[ro.vendor.hw.revision]: [pvt]
[ro.vendor.product.hardware.sku.variant]: [d]
[ro.vendor.product.name]: [hanoip_retail]

Custom Script

const polling = pollPerformanceMeasures(pid, (measure) => {

  measures.push(measure);
  console.log(`JS Thread CPU Usage: ${measure.cpu.perName["(mqt_js)"]}%`);
  console.log(`Main Thread CPU Usage: ${measure.cpu.perName["UI Thread"]}%`);
  console.log(`RAM Usage: ${measure.ram}MB`);
});

setTimeout(() => {
  polling && polling.stop();
  fs.writeFileSync('results.json', JSON.stringify(measures));
}, 10000);

Just followed the documentation..

Almouro commented 1 year ago

HI @nitish24p, thanks for raising this issue, and apologies for the delay πŸ™

Nice debugging! Nice that you were able to find the proper file path! One thought: the app doesn't need to be profileable. That shouldn't matter but is it still /sys/kernel/tracing/trace_pipe if the app is not profileable?

Might be depending on the version of ftrace according to this. If we need to handle multiple paths depending on the device, we'll handle all of them. In case you'd like to contribute and test it out locally, there's a guide here on how to build/test the C++ executable, but let me know if you have any questions!

In any case, I'll run a script at some point on our AWS device farm to check those paths work for all devices

Also just adding Unable to open file in case of error is kind of horrendous on our side, so we'll need better error handling πŸ˜…

nitish24p commented 1 year ago

Hey @Almouro , Sure can help out if need be. Presently for my case, i made a fork and pushed a new tag with the path updated to the right one and built the binary files again and its working as expected.

Almouro commented 1 year ago

Hi @nitish24p, at last, this should be fixed, I was able to reproduce on other devices. Can you confirm on your end? πŸ™

nitish24p commented 1 year ago

Do i need to update the version to latest?

Almouro commented 1 year ago

Yep, you can upgrade the CLI by running curl https://get.flashlight.dev/ | bash

Almouro commented 1 year ago

Hi @nitish24p , doing a bit of cleanup on Github issues, so I'm closing this one for now for lack of activity ☺️

I think this is fixed now, but do feel free to reopen if the problem is still there! πŸ™