init the component by protobuf object.
36 {
37 if (!config.has_name() || !config.has_interval()) {
38 AERROR <<
"Missing required field in config file.";
39 return false;
40 }
44 return false;
45 }
46 interval_ = config.interval();
47
48 auto role_attr = std::make_shared<proto::RoleAttributes>();
49 role_attr->set_node_name(config.name());
50 role_attr->set_channel_name(statistics::TIMER_COMPONENT_CHAN_NAME);
51 statistics::Statistics::Instance()->RegisterChanVar(*role_attr);
52
53 std::shared_ptr<TimerComponent> self =
54 std::dynamic_pointer_cast<TimerComponent>(shared_from_this());
55 auto func = [self, role_attr]() {
57 self->Process();
59
60 statistics::Statistics::Instance()->SamplingProcLatency<
61 uint64_t>(*role_attr, (end_time-start_time)/1000);
62 };
63 timer_.reset(new Timer(config.interval(), func, false));
64 timer_->Start();
65 return true;
66}
std::shared_ptr< Node > node_
void LoadConfigFiles(const ComponentConfig &config)
uint64_t ToNanosecond() const
convert time to nanosecond.
static Time Now()
get the current time.