NVIDIA DeepStream SDK API Reference

9.2 Release
sources/libs/nvmultiobjecttracker/include/modules/utility/timeStamp.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include "modules/NvMultiObjectTracker/nvdstracker.h"
19 
20 #ifndef UTILITY_TIMESTAMP_HPP
21 #define UTILITY_TIMESTAMP_HPP
22 
24 class Time {
25  public:
27 #ifdef _WIN32
29  std::chrono::duration_cast<std::chrono::system_clock::duration>(
30  std::chrono::nanoseconds(NvDsCurrentTimestampNs())))) {}
31 #else
32  Time() : m_timePoint(std::chrono::nanoseconds(NvDsCurrentTimestampNs())) {}
33 #endif
34 
39  Time(std::chrono::system_clock::time_point time) : m_timePoint(time) {}
40 
42  ~Time() {}
43 
46  {
47  return std::chrono::duration_cast<std::chrono::nanoseconds>(m_timePoint.time_since_epoch()).count();
48  }
49 
52  {
53  return m_timePoint;
54  }
55 
61  {
62  TimeStamp nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(m_timePoint - time).count();
63  return getStrTimeFromNanoseconds(nanoseconds, "%H:%M:%S");
64  }
65 
67  std::string getStrSystemTime()
68  {
69  TimeStamp nanoseconds = getUnixTimestampNanoSeconds();
70  return getStrTimeFromNanoseconds(nanoseconds, "%Y-%m-%d %H:%M:%S");
71  }
72 
73  private:
75 
81  std::string getStrTimeFromNanoseconds(TimeStamp nanoseconds, std::string format)
82  {
83  std::tm tm;
84  std::stringstream ss;
85  std::time_t seconds = static_cast<std::time_t>(nanoseconds / 1000000000ULL);
86  TimeStamp frac_ns = nanoseconds % 1000000000ULL;
87  TimeStamp frac_us = frac_ns / 1000ULL;
88 #ifdef _WIN32
89  localtime_s(&tm, &seconds);
90 #else
91  localtime_r(&seconds, &tm);
92 #endif
93  ss << std::put_time(&tm, format.c_str()) << "." << std::setfill('0') << std::setw(6) << frac_us;
94  return ss.str();
95  }
96 };
97 
98 #endif // UTILITY_TIMESTAMP_HPP
Time::~Time
~Time()
Release the timestamp wrapper.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/timeStamp.hpp:42
Time::Time
Time(std::chrono::system_clock::time_point time)
Initialize from a system-clock time point.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/timeStamp.hpp:39
Time::getStrSystemTime
std::string getStrSystemTime()
Format the stored timestamp as a system date and time.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/timeStamp.hpp:67
NvDsCurrentTimestampNs
static TimeStamp NvDsCurrentTimestampNs(void)
Wall-clock time in nanoseconds since the Unix epoch (std::chrono::system_clock).
Definition: includes/nvdstracker.h:59
Time::getTimePoint
std::chrono::system_clock::time_point getTimePoint()
Return the stored system-clock time point.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/timeStamp.hpp:51
std
Extensions to the C++ standard library.
Definition: includes/opentelemetry/nostd/string_view.h:212
Time
Formats and compares system-clock timestamps.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/timeStamp.hpp:24
TimeStamp
NvMOTTimeStamp TimeStamp
Definition: includes/nvdstracker.h:56
Time::getStrTimeRelativeTo
std::string getStrTimeRelativeTo(std::chrono::system_clock::time_point time)
Format the stored timestamp relative to another time point.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/timeStamp.hpp:60
Time::Time
Time()
Initialize the timestamp to the current system time.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/timeStamp.hpp:32
deepstream::time_point
std::chrono::steady_clock::time_point time_point
Definition: service-maker/sources/modules/measure_fps_probe/measure_fps_probe.hpp:37
ds3d::v2xinfer::format
static std::string format(const char *fmt,...)
Definition: sources/libs/ds3d/inference_custom_lib/ds3d_v2x_infer_custom_preprocess/tensor.hpp:31
Time::getUnixTimestampNanoSeconds
TimeStamp getUnixTimestampNanoSeconds()
Return nanoseconds elapsed since the Unix epoch.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/timeStamp.hpp:45