Line
Link Here
|
0 |
-- C:\Users\User\Documents\NetBeansProjects\ProfilingDemo_1\common.h |
0 |
++ C:\Program Files\TortoiseHg\cnd-main\cnd.makeproject\samples_src\profiling\common.h |
Lines 35-41
Link Here
|
35 |
#endif |
35 |
#endif |
36 |
|
36 |
|
37 |
#include <stdio.h> |
37 |
#include <stdio.h> |
38 |
#include <sys/time.h> |
|
|
39 |
|
38 |
|
40 |
// Tracing |
39 |
// Tracing |
41 |
typedef enum { |
40 |
typedef enum { |
Lines 88-95
Link Here
|
88 |
int cpucount(); |
87 |
int cpucount(); |
89 |
void mem2str(char* buf, long bytes); |
88 |
void mem2str(char* buf, long bytes); |
90 |
|
89 |
|
91 |
struct timeval globalstarttime; |
|
|
92 |
struct timeval globalcurrtime; |
93 |
|
90 |
|
94 |
// Check available pthread features |
91 |
// Check available pthread features |
95 |
#include <pthread.h> |
92 |
#include <pthread.h> |
96 |
-- C:\Users\User\Documents\NetBeansProjects\ProfilingDemo_1\mutex.c |
93 |
++ C:\Program Files\TortoiseHg\cnd-main\cnd.makeproject\samples_src\profiling\mutex.c |
Lines 109-117
Link Here
|
109 |
for (i = 0; i < work_count; ++i) { |
109 |
for (i = 0; i < work_count; ++i) { |
110 |
work_explain(&works[i]); |
110 |
work_explain(&works[i]); |
111 |
} |
111 |
} |
112 |
|
|
|
113 |
print_run_time(); |
114 |
|
115 |
PAUSE("Press [Enter] to start...\n"); |
112 |
PAUSE("Press [Enter] to start...\n"); |
116 |
|
113 |
|
117 |
estimate_usage(work_count, works, seconds); |
114 |
estimate_usage(work_count, works, seconds); |
Lines 137-144
Link Here
|
137 |
|
134 |
|
138 |
TRACE("Freeing memory used for thread descriptors\n", work_count * sizeof(pthread_t)); |
135 |
TRACE("Freeing memory used for thread descriptors\n", work_count * sizeof(pthread_t)); |
139 |
free(t); |
136 |
free(t); |
140 |
|
|
|
141 |
get_running_time(&globalcurrtime); |
142 |
TRACE("\nFinish time is %ld seconds.\n\n", globalcurrtime); |
143 |
PRINT("\n"); |
137 |
PRINT("\n"); |
144 |
} |
138 |
} |
145 |
-- C:\Users\User\Documents\NetBeansProjects\ProfilingDemo_1\main.c |
139 |
++ C:\Program Files\TortoiseHg\cnd-main\cnd.makeproject\samples_src\profiling\main.c |
Lines 41-47
Link Here
|
41 |
{ 0, cpu_sys, mem_none, 0 } |
41 |
{ 0, cpu_sys, mem_none, 0 } |
42 |
}; |
42 |
}; |
43 |
|
43 |
|
44 |
|
|
|
45 |
int main(int argc, char** argv) { |
44 |
int main(int argc, char** argv) { |
46 |
|
45 |
|
47 |
int i, work_count = MAX(cpucount(), 2); |
46 |
int i, work_count = MAX(cpucount(), 2); |
Lines 54-61
Link Here
|
54 |
|
53 |
|
55 |
msg_levels = msg_explain | msg_trace; |
54 |
msg_levels = msg_explain | msg_trace; |
56 |
|
55 |
|
57 |
gettimeofday(&globalstarttime,0); |
|
|
58 |
|
59 |
sequential_demo(work_count, works, 10); |
56 |
sequential_demo(work_count, works, 10); |
60 |
|
57 |
|
61 |
parallel_demo(work_count, works, 10); |
58 |
parallel_demo(work_count, works, 10); |
62 |
-- C:\Users\User\Documents\NetBeansProjects\ProfilingDemo_1\common.c |
59 |
++ C:\Program Files\TortoiseHg\cnd-main\cnd.makeproject\samples_src\profiling\common.c |
Lines 56-71
Link Here
|
56 |
TRACE("work %d: Done sleeping\n", work_id); |
56 |
TRACE("work %d: Done sleeping\n", work_id); |
57 |
} |
57 |
} |
58 |
|
58 |
|
59 |
void get_running_time(struct timeval* a) { |
|
|
60 |
gettimeofday(a, 0); |
61 |
a->tv_sec -= globalstarttime.tv_sec; |
62 |
} |
63 |
|
64 |
void print_run_time () { |
65 |
get_running_time(&globalcurrtime); |
66 |
TRACE("\nProgram works %ld seconds \n\n", globalcurrtime); |
67 |
} |
68 |
|
69 |
static void work_run_usrcpu(int work_id, long micros) { |
59 |
static void work_run_usrcpu(int work_id, long micros) { |
70 |
TRACE("work %d: Starting mathematical calculations...\n", work_id); |
60 |
TRACE("work %d: Starting mathematical calculations...\n", work_id); |
71 |
long i = 0, j = 0; |
61 |
long i = 0, j = 0; |
72 |
-- C:\Users\User\Documents\NetBeansProjects\ProfilingDemo_1\sequential.c |
62 |
++ C:\Program Files\TortoiseHg\cnd-main\cnd.makeproject\samples_src\profiling\sequential.c |
Lines 36-44
Link Here
|
36 |
int i; |
36 |
int i; |
37 |
for (i = 0; i < work_count; ++i) { |
37 |
for (i = 0; i < work_count; ++i) { |
38 |
work_explain(&works[i]); |
38 |
work_explain(&works[i]); |
39 |
|
|
|
40 |
print_run_time(); |
41 |
|
42 |
PAUSE("Press [Enter] to start this work...\n"); |
39 |
PAUSE("Press [Enter] to start this work...\n"); |
43 |
REF("Estimated resource usage for the following %d seconds\n", seconds_per_work); |
40 |
REF("Estimated resource usage for the following %d seconds\n", seconds_per_work); |
44 |
REF("CPU usage:\n"); |
41 |
REF("CPU usage:\n"); |
45 |
-- C:\Users\User\Documents\NetBeansProjects\ProfilingDemo_1\parallel.c |
42 |
++ C:\Program Files\TortoiseHg\cnd-main\cnd.makeproject\samples_src\profiling\parallel.c |
Lines 33-39
Link Here
|
33 |
#include <unistd.h> |
33 |
#include <unistd.h> |
34 |
#include "parallel.h" |
34 |
#include "parallel.h" |
35 |
|
35 |
|
36 |
|
|
|
37 |
static void estimate_usage(int work_count, work_t* works, int seconds) { |
36 |
static void estimate_usage(int work_count, work_t* works, int seconds) { |
38 |
int usrcpu = usrcpu_usage(work_count, works); |
37 |
int usrcpu = usrcpu_usage(work_count, works); |
39 |
int syscpu = syscpu_usage(work_count, works); |
38 |
int syscpu = syscpu_usage(work_count, works); |
Lines 70-78
Link Here
|
70 |
for (i = 0; i < work_count; ++i) { |
69 |
for (i = 0; i < work_count; ++i) { |
71 |
work_explain(&works[i]); |
70 |
work_explain(&works[i]); |
72 |
} |
71 |
} |
73 |
|
|
|
74 |
print_run_time(); |
75 |
|
76 |
PAUSE("Press [Enter] to start...\n"); |
72 |
PAUSE("Press [Enter] to start...\n"); |
77 |
|
73 |
|
78 |
estimate_usage(work_count, works, seconds_per_work); |
74 |
estimate_usage(work_count, works, seconds_per_work); |