-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutil.cpp
More file actions
executable file
·90 lines (77 loc) · 2.56 KB
/
util.cpp
File metadata and controls
executable file
·90 lines (77 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* util.c
*
* Created on: 28 Feb 2010
* Author: sjf
*/
#include <sys/times.h>
#include <unistd.h>
#include <execinfo.h>
#include "util.h"
//void show_times(img *image, struct tms *start, struct tms *end, clock_t real_time) {
// long int ticks_per_sec = sysconf(_SC_CLK_TCK);
//
// clock_t user_time = end->tms_utime - start->tms_utime;
// clock_t sys_time = end->tms_stime - start->tms_stime;
// //DebugI(user_time);
// //DebugI(sys_time);
// //DebugI(real_time);
// //DebugI(ticks_per_sec);
// //long int user_time_ms = user_time / C
//
// double rt = (real_time * 1000) / (double)ticks_per_sec;
// double ut = (user_time * 1000) / (double)ticks_per_sec;
// double st = (sys_time * 1000) / (double)ticks_per_sec;
//
// if (settings->run_tests) {
// printf("%s, %d, %d, %f\n",settings->image_name,image->width, image->height,rt);
// } else {
// Info("Processing time: %s %f (ms) (%f user, %f system)",settings->image_name, rt, ut, st);
// }
//}
void quick_show_time(struct tms *start, struct tms *end, clock_t real_time,
const char *timer_name, int width, int height) {
long int ticks_per_sec = sysconf(_SC_CLK_TCK);
clock_t user_time = end->tms_utime - start->tms_utime;
clock_t sys_time = end->tms_stime - start->tms_stime;
//DebugI(user_time);
//DebugI(sys_time);
//DebugI(real_time);
//DebugI(ticks_per_sec);
//long int user_time_ms = user_time / C
double rt = (real_time * 1000) / (double)ticks_per_sec;
double ut = (user_time * 1000) / (double)ticks_per_sec;
double st = (sys_time * 1000) / (double)ticks_per_sec;
uint num_pixels = width * height;
if (settings->run_tests) {
printf("%s, %s, %d, %d, %d, %f, %f, %f, %f\n",
timer_name, settings->image_name, width, height, num_pixels, rt, ut, st, settings->mask_size);
} else {
const char *unit = "ms";
if (rt > 1000) {
rt /= 1000;
ut /= 1000;
st /= 1000;
unit = "s";
}
Info("Timer %s: %s: %0.3f (%s) (%0.3f user, %0.3f system)",
settings->image_name, timer_name, rt, unit, ut, st);
}
}
/* Obtain a backtrace and print it to stdout. */
/* libc Manual 33.1 Backtraces */
/* Compile with -rdynamic for better symbols */
/* http://www.gnu.org/software/libc/manual/html_node/Backtraces.html */
void print_stack_trace (void)
{
void *array[10];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
//printf ("Obtained %zd stack frames.\n", size);
for (i = 0; i < size; i++)
printf ("%s\n", strings[i]);
free (strings);
}