You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: lib.rs
    path of file: ./repos/nearcore/utils/near-performance-metrics-macros/src
    
    the code of the file until where you have to start completion: extern crate proc_macro;
extern crate syn;

use proc_macro::TokenStream;
use quote::quote;

/// Wrap the method call with near_performance_metrics::stats::measure_performance function.
///
/// This derive can be used to provide performance metrics to method calls with Actors. Currently
/// we print performance stats per thread every minute, and we print a warning whenever a function
/// call exceeds took more than given time limit. It should have no performance impact unless
/// `performance_stats` fe
    
fn perf_internal(_attr: TokenStream, item: TokenStream, debug: bool) -> TokenStream {
    let item: syn::Item = syn::parse(item).expect("failed to parse input");

    if let syn::Item::Fn(mut func) = item {
        let function_body = func.block;

        let new_body: TokenStream = if debug {
            quote! (
                {
                    near_performance_metrics::stats::measure_performance_with_debug(std::any::type_name::<Self>(), msg, move |msg| {
                        #function_body
                    })
                }
            ).into()
        } else {
            quote! (
                {
                    near_performance_metrics::stats::measure_performance(std::any::type_name::<Self>(), (), move |_| {
                        #function_body
                    })
                }
             ).into()
        };
        func.block = syn::parse::<syn::Block>(new_body).expect("failed to parse input").into();

        quote! ( #func ).into()
    } else {
        panic!("not a function");
    }
}