<commit_before>// Copyright 2017 The Exonum Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Utilities for collecting metrics.

use std::time::SystemTime;
use std::fmt::Arguments;

/// Adds given metric with given value.
///
/// Metric name should be in the following format: `module_name.metric_name`, where `module_name`
/// is a high level name. For example `storage` or `node` (not `storage_proof_list_index`).
///
/// Value is a string and can be formatted similar to the `println!`. See `std::fmt` and example
/// for details.
///
/// Metrics output direction is determined by the corresponding `metrics-...` feature. If
///
/// # Examples
///
/// ```rust
/// # #[macro_use]
/// # extern crate exonum;
/// # fn main() {
/// let val = 10;
/// let other_val = "some value";
///
/// metric!("mod_name.metric_name", "{} and {}", val, other_val);
/// # }
/// ```
#[macro_export]
macro_rules! metric {
    ($name:expr, $($arg:tt)+) => ({
        $crate::helpers::metrics::add_metric($name, &format_args!($($arg)+));
    })
}

// Do not use directly, use `metric!` macro instead.
#[doc(hidden)]
pub fn add_metric(metric_name: &str, value: &Arguments) {
    // TODO: Convert time to some meaningful format.
    let time = format!("{:?}", SystemTime::now());

    if cfg!(feature = "metrics-hadoop") {
        write_to_hadoop(metric_name, value, &time);
    }

    if cfg!(feature = "metrics-log") {
        trace!("{} {} {}", metric_name, value, time);
    }
}

fn write_to_hadoop(_metric_name: &str, _value: &Arguments, _time: &str) {
    // TODO: Add implementation.
}
<commit_msg>Use cfg attribute instead of macro<commit_after>// Copyright 2017 The Exonum Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Utilities for collecting metrics.

use std::time::SystemTime;
use std::fmt::Arguments;

/// Adds given metric with given value.
///
/// Metric name should be in the following format: `module_name.metric_name`, where `module_name`
/// is a high level name. For example `storage` or `node` (not `storage_proof_list_index`).
///
/// Value is a string and can be formatted similar to the `println!`. See `std::fmt` and example
/// for details.
///
/// Metrics output direction is determined by the corresponding `metrics-...` feature. If
///
/// # Examples
///
/// ```rust
/// # #[macro_use]
/// # extern crate exonum;
/// # fn main() {
/// let val = 10;
/// let other_val = "some value";
///
/// metric!("mod_name.metric_name", "{} and {}", val, other_val);
/// # }
/// ```
#[macro_export]
macro_rules! metric {
    ($name:expr, $($arg:tt)+) => ({
        $crate::helpers::metrics::add_metric($name, &format_args!($($arg)+));
    })
}

// Do not use directly, use `metric!` macro instead.
#[doc(hidden)]
#[allow(unused_variables)]
pub fn add_metric(metric_name: &str, value: &Arguments) {
    // TODO: Convert time to some meaningful format.
    let time = format!("{:?}", SystemTime::now());

    #[cfg(feature = "metrics-hadoop")]
    {
        write_to_hadoop(metric_name, value, &time);
    }

    #[cfg(feature = "metrics-log")]
    {
        trace!("{} {} {}", metric_name, value, time);
    }
}

#[cfg(feature = "metrics-hadoop")]
fn write_to_hadoop(_metric_name: &str, _value: &Arguments, _time: &str) {
    // TODO: Add implementation.
}

{'fraction_non_alphanumeric': 0.16662777129521586, 'fraction_numerical': 0.004667444574095682, 'mean_word_length': 3.2817182817182817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6513383', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1287, 'n_words': 456}