有没有什么方法可以支持usdt探针(用户级静态定义的跟踪)而无需重新编译?

时间:2019-05-05 03:02:36

标签: trace perf

我想使用bcc,bpftrace和perf等ebpf工具跟踪mysql查询事件。而且我发现我们需要使用--with-dtrace标志自己编译应用程序以支持USDT事件。并且usdt如何运作。还有其他方法可以使用usdt而不重新编译应用程序吗?

1 个答案:

答案 0 :(得分:1)

您可以对perf probe使用 dynamic 跟踪点。可以在任何可执行文件或共享库以及内核中定义这些跟踪点。

例如:

    public class RecyclerviewAdapter extends RecyclerView.Adapter<RecyclerviewAdapter.MyHolder> {

        // ... constructor and member variables

        // Usually involves inflating a layout from XML and returning the holder
        Context mContext;
        List<Template> listdata;

        public RecyclerviewAdapter(Context context,List<Template> listdata) {
            this.mContext = context;
            this.listdata = listdata;
        }

        @Override
        public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {

            /*// Inflate the custom layout
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview,parent,false);

            // Return a new holder instance
            MyHolder myHolder = new MyHolder(view);
            return myHolder;*/
            View view = LayoutInflater.from(mContext).inflate(R.layout.cardview,parent,false);

            return new MyHolder(view);
        }

        public void onBindViewHolder(MyHolder holder, int position) {


    holder.pname.setText(listdata.get(position).getP_name());
    holder.pdesignation.setText(listdata.get(position).getP_designation());
    holder.pemail.setText(listdata.get(position).getP_email());
    holder.pphone.setText(listdata.get(position).getP_phone());
    holder.cname.setText(listdata.get(position).getC_name());
    holder.caddress.setText(listdata.get(position).getC_address());

    //holder.tempID.setText(listdata.get(position).getTempID());
    Glide.with(mContext).load(listdata.get(position).getC_logo()).into(holder.logo_image);

        }

        @Override
        public int getItemCount() {
            //return listdata.size();
            int arr = 0;

            try{
                if(listdata.size()==0) {
                    arr = 0;
                } else {
                    arr=listdata.size();
                }
            } catch (Exception e){
                e.printStackTrace();
            }
            return arr;
        }

        class MyHolder extends RecyclerView.ViewHolder{
            // Your holder should contain a member variable
            // for any view that will be set as you render a row
            TextView pname,caddress,pemail,pdesignation,pphone,cname,tempID;
            ImageView logo_image;

            // We also create a constructor that accepts the entire item row
            // and does the view lookups to find each subview

            public MyHolder(final View itemView) {
                // Stores the itemView in a public final member variable that can be used
                // to access the context from any ViewHolder instance.
                super(itemView);

                pname = (TextView) itemView.findViewById(R.id.txt_personName);
                caddress = (TextView) itemView.findViewById(R.id.txt_address);
                pemail = (TextView) itemView.findViewById(R.id.txt_email);
                pdesignation = (TextView) itemView.findViewById(R.id.txt_designation);
                pphone = (TextView) itemView.findViewById(R.id.txt_phone);
                cname = (TextView) itemView.findViewById(R.id.txt_companyName);
                logo_image = itemView.findViewById(R.id.imageView);
                tempID = itemView.findViewById(R.id.tempID);

                caddress.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //Toast.makeText(mContext,"Clicked on Address",Toast.LENGTH_SHORT).show();
                        DialogCompanyAddress address = new DialogCompanyAddress();
                        //address.show(getSupportFragmentManager);--->This line give me error

                    }
                });

        }
    }

然后它们可用作df <- df %>% mutate(value = lag(new_var,1) 和朋友的跟踪点。如果优化级别允许,您还可以添加函数参数或局部变量。