ARM-software/workload-automation

Adding a custom instrument - Could not find plugin or alias

hosunhc opened this issue · 5 comments

Hi, I've been trying to add an instrument called Perfetto to my WA by following the documentation, without much luck.
Here is the link for info on the instrument Perfetto. I am using their provided helper script.
I just want to start the instrument right before the workload and save the output file into the working directory of the host device. I checked the FAQ, but I think the solution is somewhat different for this case.

In my user directory, I added a directory called perfetto .workload_automation/perfetto/ with three files: perfetto.py, record_android_trace (the helper script), and config.pbtx (a configuration file necessary to run record_android_trace).

So far in perfetto.py, I have:

from wa import Instrument
import subprocess
from signal import SIGINT

class Perfetto(Instrument):
    name = 'perfetto'

    def __init__(self, context):
        super(Perfetto, self).__init__(context)
        self.proc = None

    def start(self, context):
        run_perf = ['./record_android_trace', '-c', 'config.pbtx', '-n', '-o', context.working_directory + 'perfetto.pftrace' ]
        self.proc = subprocess.Popen(run_perf)

    def stop(self, context):
        self.proc.send_signal(SIGINT)

    def finalize(self, context):
        self.proc.terminate()

In .workload_automation/config.yaml, I also added:

extra_plugin_paths: 
- '(home_path)/.workload_automation/perfetto'

And after restarting terminal and running wa create agenda perfetto just to see if wa can read perfetto, I get an error:
ERROR Could not find plugin or alias "perfetto".
I'm assuming I missed a step somewhere or placed the files in the wrong directory, but could not completely able to figure it out after looking through the documentation.
I just want to be able to run record_android_trace before the workload and quit it after and save it into the working directory of the host.
Anyways, any help/suggestions would be appreciated.

Hi,

The easiest way to let WA pick up your instrument should be to place your perfetto directory under (home_path)/.workload_automation/plugins/ and WA should automatically pick it up.

I realize in the "Adding an Instrument" how to we don't explicitly make this clear so we can add a clarification to fix this.

Oh I see, I also realized that in the config file, I made an error for extra_plugin_paths: .
Anyways thanks for the quick response.

I tried it and now it's being picked up by WA. However, after running it with wa run config.yaml -f:
ERROR TypeError(Perfetto.__init__() got an unexpected keyword argument 'cleanup_assets').

Ah thanks for finding that, it look like our example is missing the **kwargs argument for the __init__ method.

Could you try changing this to something like

def __init__(self, target, **kwargs):
        super(Perfetto, self).__init__(target, **kwargs)
        self.proc = None

Yep works now, thanks a lot!
There was another issue which occurred from context.working_directory, which got fixed with context.output_directory. I think there were some examples here that mistakenly used context.working_directory. Anyways, thanks for everything! Works like a charm.

Thanks for mentioning, I've created a PR (#1202) to address the issues raised.

Please let me know if you come across any other problems.