tick_count.h
Go to the documentation of this file.
/*
Copyright (c) 2005-2020 Intel Corporation
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.
*/
#ifndef __TBB_tick_count_H
#define __TBB_tick_count_H
#include "tbb_stddef.h"
#if _WIN32||_WIN64
#include "machine/windows_api.h"
#elif __linux__
#include <ctime>
#else /* generic Unix */
#include <sys/time.h>
#endif /* (choice of OS) */
namespace tbb {
class tick_count {
public:
class interval_t {
long long value;
explicit interval_t( long long value_ ) : value(value_) {}
public:
interval_t() : value(0) {};
explicit interval_t( double sec );
double seconds() const;
friend class tbb::tick_count;
friend interval_t operator-( const tick_count& t1, const tick_count& t0 );
friend interval_t operator+( const interval_t& i, const interval_t& j ) {
return interval_t(i.value+j.value);
}
friend interval_t operator-( const interval_t& i, const interval_t& j ) {
return interval_t(i.value-j.value);
}
interval_t& operator+=( const interval_t& i ) {value += i.value; return *this;}
interval_t& operator-=( const interval_t& i ) {value -= i.value; return *this;}
private:
static long long ticks_per_second(){
#if _WIN32||_WIN64
LARGE_INTEGER qpfreq;
int rval = QueryPerformanceFrequency(&qpfreq);
__TBB_ASSERT_EX(rval, "QueryPerformanceFrequency returned zero");
return static_cast<long long>(qpfreq.QuadPart);
#elif __linux__
return static_cast<long long>(1E9);
#else /* generic Unix */
return static_cast<long long>(1E6);
#endif /* (choice of OS) */
}
};
tick_count() : my_count(0) {};
static tick_count now();
friend interval_t operator-( const tick_count& t1, const tick_count& t0 );
static double resolution() { return 1.0 / interval_t::ticks_per_second(); }
private:
long long my_count;
};
inline tick_count tick_count::now() {
tick_count result;
#if _WIN32||_WIN64
LARGE_INTEGER qpcnt;
int rval = QueryPerformanceCounter(&qpcnt);
__TBB_ASSERT_EX(rval, "QueryPerformanceCounter failed");
result.my_count = qpcnt.QuadPart;
#elif __linux__
struct timespec ts;
int status = clock_gettime( CLOCK_REALTIME, &ts );
__TBB_ASSERT_EX( status==0, "CLOCK_REALTIME not supported" );
result.my_count = static_cast<long long>(1000000000UL)*static_cast<long long>(ts.tv_sec) + static_cast<long long>(ts.tv_nsec);
#else /* generic Unix */
struct timeval tv;
int status = gettimeofday(&tv, NULL);
__TBB_ASSERT_EX( status==0, "gettimeofday failed" );
result.my_count = static_cast<long long>(1000000)*static_cast<long long>(tv.tv_sec) + static_cast<long long>(tv.tv_usec);
#endif /*(choice of OS) */
return result;
}
inline tick_count::interval_t::interval_t( double sec ) {
value = static_cast<long long>(sec*interval_t::ticks_per_second());
}
inline tick_count::interval_t operator-( const tick_count& t1, const tick_count& t0 ) {
return tick_count::interval_t( t1.my_count-t0.my_count );
}
inline double tick_count::interval_t::seconds() const {
return value*tick_count::resolution();
}
} // namespace tbb
#endif /* __TBB_tick_count_H */
tbb::tick_count::interval_t
Relative time interval.
Definition: tick_count.h:37
tbb::tick_count::interval_t::value
long long value
Definition: tick_count.h:38
tbb::tick_count::interval_t::operator-
friend interval_t operator-(const interval_t &i, const interval_t &j)
Subtract two intervals.
Definition: tick_count.h:61
tbb::tick_count::operator-
friend interval_t operator-(const tick_count &t1, const tick_count &t0)
Subtract two timestamps to get the time interval between.
Definition: tick_count.h:126
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::tick_count
Absolute timestamp.
Definition: tick_count.h:34
windows_api.h
tbb::tick_count::interval_t::interval_t
interval_t(long long value_)
Definition: tick_count.h:39
tbb::tick_count::interval_t::operator+=
interval_t & operator+=(const interval_t &i)
Accumulation operator.
Definition: tick_count.h:66
tbb::tick_count::interval_t::ticks_per_second
static long long ticks_per_second()
Definition: tick_count.h:71
tbb::tick_count::now
static tick_count now()
Return current time.
Definition: tick_count.h:101
tbb::tick_count::resolution
static double resolution()
Return the resolution of the clock in seconds per tick.
Definition: tick_count.h:95
tbb::tick_count::interval_t::seconds
double seconds() const
Return the length of a time interval in seconds.
Definition: tick_count.h:130
tbb::tick_count::interval_t::operator-
friend interval_t operator-(const tick_count &t1, const tick_count &t0)
Extract the intervals from the tick_counts and subtract them.
Definition: tick_count.h:126
tbb::tick_count::tick_count
tick_count()
Construct an absolute timestamp initialized to zero.
Definition: tick_count.h:86
tbb::tick_count::interval_t::operator+
friend interval_t operator+(const interval_t &i, const interval_t &j)
Add two intervals.
Definition: tick_count.h:56
tbb::tick_count::my_count
long long my_count
Definition: tick_count.h:98
value
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
Definition: ittnotify_static.h:192
tbb_stddef.h
tbb::tick_count::interval_t::interval_t
interval_t()
Construct a time interval representing zero time duration.
Definition: tick_count.h:42
tbb::tick_count::interval_t::operator-=
interval_t & operator-=(const interval_t &i)
Subtraction operator.
Definition: tick_count.h:69
__TBB_ASSERT_EX
#define __TBB_ASSERT_EX(predicate, comment)
"Extended" version is useful to suppress warnings if a variable is only used with an assert
Definition: tbb_stddef.h:167

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.