Creates a timer for tracking long running tasks.

@param registry
Registry to use.
@param id
Identifier for the metric being registered.
@return
Timer instance.
186410
public static LongTaskTimer get(Registry registry, Id id) {
    ConcurrentMap<Id, Object> state = registry.state();
    Object obj = Utils.computeIfAbsent(state, id, i -> {
      LongTaskTimer timer = new LongTaskTimer(registry, id);
      PolledMeter.using(registry)
          .withId(id)
          .withTag(Statistic.activeTasks)
          .monitorValue(timer, LongTaskTimer::activeTasks);
      PolledMeter.using(registry)
          .withId(id)
          .withTag(Statistic.duration)
          .monitorValue(timer, t -> t.duration() / NANOS_PER_SECOND);
      return timer;
    });
    if (!(obj instanceof LongTaskTimer)) {
      Utils.propagateTypeError(registry, id, LongTaskTimer.class, obj.getClass());
      obj = new LongTaskTimer(new NoopRegistry(), id);
    }
    return (LongTaskTimer) obj;
  }
1326806
def timer(self, key, **dims):
        """"""
        return super(MetricsRegistry, self).timer(
            self.metadata.register(key, **dims))
688931
protected void updateTimer(String containerId, Long processInstanceId, long timerId, long delay, long period, int repeatLimit, boolean relative) {
        Map<String, Number> timerUpdate = new HashMap<>();
        timerUpdate.put("delay", delay);
        timerUpdate.put("period", period);
        timerUpdate.put("repeatLimit", repeatLimit);

        if( config.isRest() ) {
            Map<String, Object> valuesMap = new HashMap<String, Object>();
            valuesMap.put(CONTAINER_ID, containerId);
            valuesMap.put(PROCESS_INST_ID, processInstanceId);
            valuesMap.put(TIMER_INSTANCE_ID, timerId);

            Map<String, String> headers = new HashMap<String, String>();


            makeHttpPutRequestAndCreateCustomResponse(
                    build(loadBalancer.getUrl(), ADMIN_PROCESS_URI + "/" + UPDATE_TIMER_PROCESS_INST_PUT_URI, valuesMap)+ "?relative=" + relative, timerUpdate, null, headers);
        } else {
            CommandScript script = new CommandScript( Collections.singletonList(
                    (KieServerCommand) new DescriptorCommand( "ProcessAdminService", "updateTimer", serialize(timerUpdate), marshaller.getFormat().getType(), new Object[]{containerId, processInstanceId, timerId, relative})));
            ServiceResponse<?> response = (ServiceResponse<?>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0);
            throwExceptionOnFailure(response);
        }
    }
716612
public static PrometheusMeterRegistry newRegistry(CollectorRegistry registry, Clock clock) {
        final PrometheusMeterRegistry meterRegistry = new PrometheusMeterRegistry(
                PrometheusConfig.DEFAULT, requireNonNull(registry, "registry"), requireNonNull(clock, "clock"));
        meterRegistry.config().namingConvention(MoreNamingConventions.prometheus());
        meterRegistry.config().pauseDetector(new NoPauseDetector());
        return meterRegistry;
    }
153104
public static void registerObject(String id, Object obj) {
    DefaultMonitorRegistry.getInstance().register(newObjectMonitor(id, obj));
  }
842530
private Counter initAndRegisterCounter(String name) {
        BasicCounter counter = new BasicCounter(MonitorConfig.builder(name).build());
        DefaultMonitorRegistry.getInstance().register(counter);
        return counter;
    }
748182
Timer timer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetectorOverride) {
        return registerMeterIfNecessary(Timer.class, id, distributionStatisticConfig, (id2, filteredConfig) -> {
            Meter.Id withUnit = id2.withBaseUnit(getBaseTimeUnitStr());
            return newTimer(withUnit, filteredConfig.merge(defaultHistogramConfig()), pauseDetectorOverride);
        }, NoopTimer::new);
    }
1313948
def init_timer(client_id):
    
    if client_id in timers and timers[client_id]:
        timers[client_id].start()
        return
    # Create a timer to call check_new_message function after every 2 seconds.
    # client_id param is needed to be passed to check_new_message
    timers[client_id] = RepeatedTimer(2, check_new_messages, client_id)
1016422
public static Timer newTimer(String name, TimeUnit unit, TaggingContext context) {
    final MonitorConfig config = MonitorConfig.builder(name).build();
    return new ContextualTimer(config, context, new TimerFactory(unit));
  }
244365
public void setMetricRegistry(Object metricRegistry)
   {
      if (metricRegistry != null && safeIsAssignableFrom(metricRegistry, "com.codahale.metrics.MetricRegistry")) {
         setMetricsTrackerFactory(new CodahaleMetricsTrackerFactory((MetricRegistry) metricRegistry));
      }
      else if (metricRegistry != null && safeIsAssignableFrom(metricRegistry, "io.micrometer.core.instrument.MeterRegistry")) {
         setMetricsTrackerFactory(new MicrometerMetricsTrackerFactory((MeterRegistry) metricRegistry));
      }
      else {
         setMetricsTrackerFactory(null);
      }
   }
479856
@SuppressWarnings("unchecked")
    private <T> List<WatcherRegistration<T>> getWatcherRegistrations(Id<T> id) {
        return (List<WatcherRegistration<T>>)((Container)watcherRegistry).getAll(id.type());
    }
188327
public static void register(FastProtocolId id, Method m) {
    synchronized (FastProtocolRegister.class) {
      String name = id.toString();
      if (name.length() != NAME_LEN) {
        // we only allow two-byte serialization codes
        throw new RuntimeException("Code must be " + NAME_LEN + " bytes long");
      }
      if (m == null) {
        throw new RuntimeException("Method cannot be null");
      }
      Method registeredMethod = idToMethod.get(name);
      if (registeredMethod != null && registeredMethod != m) {
        throw new RuntimeException(
            "Trying to register different method with name: " + name);
      } else if (registeredMethod == m) {
        return; // quietly
      }
      LOG.info("FastProtocol - Registering method: " + name + " method: "
          + m.getName());
      idToMethod.put(name, m);
      methodToId.put(m, name);
    }
  }
136301
private static ThreadFactory newThreadFactory(final String id) {
    return new ThreadFactory() {
      private final AtomicInteger next = new AtomicInteger();

      @Override public Thread newThread(Runnable r) {
        final String name = "spectator-" + id + "-" + next.getAndIncrement();
        final Thread t = new Thread(r, name);
        t.setDaemon(true);
        return t;
      }
    };
  }
756676
public MetricRegistry registerMetrics(final MetricRegistry registry) {
      registry.register(MetricRegistry.name(ConnectionPool.class, name), metrics);
      return registry;
   }
1273628
function pause(id) {
  if (!timers[id]) return start(id);

  timers[id].elapsed += msDiff(process.hrtime(), timers[id].start);
}
1005708
public void startTask(int id, String taskName) {
        if (isActivated) {
            durations.add(new Duration(id, taskName, BenchmarkUtil.elapsedRealTimeNanos()));
        }
    }
10336
public void cancelTimer(IPollEvents sink, int id)
    {
        assert (Thread.currentThread() == worker);

        TimerInfo copy = new TimerInfo(sink, id);
        //  Complexity of this operation is O(n). We assume it is rarely used.

        TimerInfo timerInfo = timers.find(copy);
        if (timerInfo != null) {
            // let's defer the removal during the loop
            timerInfo.cancelled = true;
        }
    }