Running perf in bmv2

I would like to analyze the performance of a switch during a network flow attack. So I thought to use perf inside a xterm s1 s2 mininet application. Does that make sense?

If i run in the bmv2 switch s1 perf -pid(where the pid is mininet/simple_switch processes), will I be able to understand CPU and memory usage of a switch?

BMv2 / behavioral-model is a user space process that was developed primarily for the purposes of developing, testing, and debugging P4 programs on a development system. If you have not read this article yet, I recommend doing so:

If you want to learn how a software switch developed for the purposes of debugging primarily, and performance as a secondary concern, by all means measure the CPU and memory usage of the BMv2 user space process.

If you want to learn how some hardware switch performs and uses memory, then I recommend you do experiments with those hardware switches instead.

Running experiments on the BMv2 software switch will tell you almost nothing about other target devices.

The process i need to measure are both mininet and BMv2?

For exemple, we have these mininet process related to 2 switches:

root 24407 0.0 0.1 6972 3528 pts/6 Ss+ 17:02 0:00 bash --norc --noediting -is mininet:s1
root 24411 0.0 0.1 6972 3528 pts/7 Ss+ 17:02 0:00 bash --norc --noediting -is mininet:s2

But there are simple_switch process as well:

root@p4:/home/p4/tutorials/exercises/mri# ps aux | grep simple_switch_grpc
root 24391 0.0 0.2 9264 4556 pts/0 S+ 17:02 0:00 sudo python3 …/…/utils/ -t topology.json -j build/mri.json -b simple_switch_grpc
root 24392 0.0 2.0 635572 41544 pts/0 Sl+ 17:02 0:00 python3 …/…/utils/ -t topology.json -j build/mri.json -b simple_switch_grpc
root 24609 0.0 0.9 1209760 19648 pts/6 Sl+ 17:02 0:03 simple_switch_grpc -i 2@s1-eth2 -i 1@s1-eth1 -i 3@s1-eth3 -i 4@s1-eth4 --pcap /home/p4/tutorials/exercises/mri/pcaps --nanolog ipc://
root 24631 0.0 0.9 1209760 19456 pts/7 Sl+ 17:02 0:03 simple_switch_grpc -i 2@s2-eth2 -i 1@s2-eth1 -i 3@s2-eth3 -i 4@s2-eth4 --pcap /home/p4/tutorials/exercises/mri/pcaps --nanolog ipc://
root 24654 0.0 0.9 1205404 19592 pts/8 Sl+ 17:02 0:02 simple_switch_grpc -i 1@s3-eth1 -i 2@s3-eth2 -i 3@s3-eth3 --pcap /home/p4/tutorials/exercises/mri/pcaps --nanolog ipc:///tmp/bm-2-log
root 25862 0.0 0.0 6436 720 pts/11 S+ 18:01 0:00 grep --color=auto simple_switch_grpc

Which of these process would inidcate the CPU and memory usage of the BMv2 operating in a simulating network flow?

The BMv2 software switch program names are only simple_switch or simple_switch_grpc.

As far as I know, mininet is used to help you set up Linux network namespaces, veth or other kinds of virtual network interfaces, and connect these virtual network interfaces to each other in your desired topology. There is nothing in mininet itself that is involved in processing each individual packet once those things have been set up.

That said, I would recommend using top or some similar utility to show the CPU and memory usage of all processes, to see if anything unexpected is happening on your system. For example, what if you left a long-running process that consumed a lot of CPU on the system where you are running the BMv2 software switch(es), and it is slowing down your experiment and affecting your performance measurements. That seems like a useful thing to know about before using the performance results to make predictions.