aboutsummaryrefslogtreecommitdiffstats
path: root/longbow/src/LongBow/longBow_MeasureTime.h
diff options
context:
space:
mode:
authorMichele Papalini <micpapal+fdio@cisco.com>2017-02-24 08:00:33 +0000
committerGerrit Code Review <gerrit@fd.io>2017-02-24 08:00:33 +0000
commit4df7f4cc98b6288177df256e1db70ddc3f7d00db (patch)
tree55e71277b419e4830ae641868ab8e751c8b86972 /longbow/src/LongBow/longBow_MeasureTime.h
parentf28308bd99381ef5f1e178e2e1f870f245e35873 (diff)
parentec688b4723a041044226358bcd4dd6e2da39da49 (diff)
Merge "Initial commit: cframework. Longbow and Libparc" into cframework/master
Diffstat (limited to 'longbow/src/LongBow/longBow_MeasureTime.h')
-rw-r--r--longbow/src/LongBow/longBow_MeasureTime.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/longbow/src/LongBow/longBow_MeasureTime.h b/longbow/src/LongBow/longBow_MeasureTime.h
new file mode 100644
index 00000000..5e2931e0
--- /dev/null
+++ b/longbow/src/LongBow/longBow_MeasureTime.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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.
+ */
+
+/**
+ * @file longBow_MeasureTime.h
+ *
+ * Measure elapsed time, providing various fetching and reporting mechanisms.
+ *
+ */
+#ifndef __LongBow__longBow_Measure__
+#define __LongBow__longBow_Measure__
+#include <stdint.h>
+#include <stdbool.h>
+
+#ifdef LongBow_DISABLE_MEASUREMENTS
+# define longBowMeasureTime(_iterations_)
+#else
+# define longBowMeasureTime(_iterations_) for (LongBowMeasureTime *_measure = longBowMeasureTime_Start(_iterations_); \
+ longBowMeasureTime_CountDown(_measure) ? true : (longBowMeasureTime_Report(_measure, __FILE__, __func__, __LINE__), longBowMeasureTime_Destroy(&_measure), false); )
+
+#endif
+
+struct longBowMeasureTime;
+typedef struct longBowMeasureTime LongBowMeasureTime;
+
+/**
+ * Create and start a `LongBowMeasureTime` instance.
+ *
+ * @param [in] iterations The number of iterations to perform when used with `longBowMeasureTime_CountDown`
+ *
+ * @return non-NULL A pointer to a valid LongBowMeasureTime instance that must be destroyed by `longBowMeasureTime_Destroy`
+ */
+LongBowMeasureTime *longBowMeasureTime_Start(unsigned int iterations);
+
+/**
+ * Report on the `LongBowMeasureTime` instance.
+ *
+ * @param [in] measure A pointer to a valid LongBowMeasureTime instance.
+ * @param [in] file A pointer to a nul-terminated C string representing the file name causing the report.
+ * @param [in] function A pointer to a nul-terminated C string representing the function name causing the report.
+ * @param [in] line An unsigned integer representing the line number of the file causing the report.
+ *
+ * @return true The report was successful.
+ */
+bool longBowMeasureTime_Report(LongBowMeasureTime *measure, const char *file, const char *function, unsigned int line);
+
+/**
+ * A simple count-down supporting measurement iterations.
+ *
+ * See {@link longBowMeasureTime} for an example.
+ *
+ * @param [in] measure A pointer to a valid LongBowMeasureTime instance.
+ *
+ * @return The current value of the counter.
+ */
+unsigned int longBowMeasureTime_CountDown(LongBowMeasureTime *measure);
+
+/**
+ * Get the total number of microseconds represented by the `LongBowMeasureTime` instance.
+ *
+ * @param [in] measure A pointer to a valid LongBowMeasureTime instance.
+ *
+ * @return The number of microseconds represented by the `LongBowMeasureTime` instance.
+ */
+uint64_t longBowMeasureTime_GetMicroseconds(const LongBowMeasureTime *measure);
+
+/**
+ * Get the total number of nanoseconds represented by the `LongBowMeasureTime` instance.
+ *
+ * @param [in] measure A pointer to a valid LongBowMeasureTime instance.
+ *
+ * @return The number of nanoseconds represented by the `LongBowMeasureTime` instance.
+ */
+uint64_t longBowMeasureTime_GetNanoseconds(const LongBowMeasureTime *measure);
+
+/**
+ * Destroy a valid `LongBowMeasureTime` instance.
+ *
+ * @param [in,out] instancePtr A pointer to a pointer to a valid LongBowMeasureTime instance, that will be set to zero.
+ */
+void longBowMeasureTime_Destroy(LongBowMeasureTime **instancePtr);
+
+#endif /* defined(__LongBow__longBow_Measure__) */