2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.transport.modbus.internal;
15 import java.util.UUID;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * Utility for timing operations
22 * @author Sami Salonen - initial contribution
26 public class AggregateStopWatch {
28 * ID associated with this modbus operation
30 final String operationId;
33 * Total operation time
35 final SimpleStopWatch total = new SimpleStopWatch();
38 * Time for connection related actions
40 final SimpleStopWatch connection = new SimpleStopWatch();
43 * Time for actual the actual transaction (read/write to slave)
45 final SimpleStopWatch transaction = new SimpleStopWatch();
48 * Time for calling calling the callback
50 final SimpleStopWatch callback = new SimpleStopWatch();
52 public AggregateStopWatch() {
53 this.operationId = UUID.randomUUID().toString();
57 * Suspend all running stopwatches of this aggregate
59 public void suspendAllRunning() {
60 for (SimpleStopWatch watch : new SimpleStopWatch[] { total, connection, transaction, callback }) {
61 if (watch.isRunning()) {
68 public String toString() {
69 return String.format("{total: %d ms, connection: %d, transaction=%d, callback=%d}", total.getTotalTimeMillis(),
70 connection.getTotalTimeMillis(), transaction.getTotalTimeMillis(), callback.getTotalTimeMillis());