Move {start,end}_cpu_timing into util.c
This commit is contained in:
parent
b1149f344d
commit
bfc4b742af
15
dump1090.c
15
dump1090.c
|
@ -96,21 +96,6 @@ static void sigtermHandler(int dummy) {
|
||||||
log_with_timestamp("Caught SIGTERM, shutting down..\n");
|
log_with_timestamp("Caught SIGTERM, shutting down..\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void start_cpu_timing(struct timespec *start_time)
|
|
||||||
{
|
|
||||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, start_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void end_cpu_timing(const struct timespec *start_time, struct timespec *add_to)
|
|
||||||
{
|
|
||||||
struct timespec end_time;
|
|
||||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end_time);
|
|
||||||
add_to->tv_sec += (end_time.tv_sec - start_time->tv_sec - 1);
|
|
||||||
add_to->tv_nsec += (1000000000L + end_time.tv_nsec - start_time->tv_nsec);
|
|
||||||
add_to->tv_sec += add_to->tv_nsec / 1000000000L;
|
|
||||||
add_to->tv_nsec = add_to->tv_nsec % 1000000000L;
|
|
||||||
}
|
|
||||||
|
|
||||||
void receiverPositionChanged(float lat, float lon, float alt)
|
void receiverPositionChanged(float lat, float lon, float alt)
|
||||||
{
|
{
|
||||||
log_with_timestamp("Autodetected receiver location: %.5f, %.5f at %.0fm AMSL", lat, lon, alt);
|
log_with_timestamp("Autodetected receiver location: %.5f, %.5f at %.0fm AMSL", lat, lon, alt);
|
||||||
|
|
19
util.c
19
util.c
|
@ -47,7 +47,7 @@
|
||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "util.h"
|
#include "dump1090.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
@ -79,3 +79,20 @@ void normalize_timespec(struct timespec *ts)
|
||||||
ts->tv_nsec = (ts->tv_nsec + 1000000000 * adjust) % 1000000000;
|
ts->tv_nsec = (ts->tv_nsec + 1000000000 * adjust) % 1000000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* record current CPU time in start_time */
|
||||||
|
void start_cpu_timing(struct timespec *start_time)
|
||||||
|
{
|
||||||
|
clock_gettime(CLOCK_THREAD_CPUTIME_ID, start_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add difference between start_time and the current CPU time to add_to */
|
||||||
|
void end_cpu_timing(const struct timespec *start_time, struct timespec *add_to)
|
||||||
|
{
|
||||||
|
struct timespec end_time;
|
||||||
|
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end_time);
|
||||||
|
add_to->tv_sec += (end_time.tv_sec - start_time->tv_sec - 1);
|
||||||
|
add_to->tv_nsec += (1000000000L + end_time.tv_nsec - start_time->tv_nsec);
|
||||||
|
add_to->tv_sec += add_to->tv_nsec / 1000000000L;
|
||||||
|
add_to->tv_nsec = add_to->tv_nsec % 1000000000L;
|
||||||
|
}
|
||||||
|
|
6
util.h
6
util.h
|
@ -36,4 +36,10 @@ int64_t receiveclock_ns_elapsed(uint64_t t1, uint64_t t2);
|
||||||
struct timespec;
|
struct timespec;
|
||||||
void normalize_timespec(struct timespec *ts);
|
void normalize_timespec(struct timespec *ts);
|
||||||
|
|
||||||
|
/* record current CPU time in start_time */
|
||||||
|
void start_cpu_timing(struct timespec *start_time);
|
||||||
|
|
||||||
|
/* add difference between start_time and the current CPU time to add_to */
|
||||||
|
void end_cpu_timing(const struct timespec *start_time, struct timespec *add_to);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue