Browse code

- corrected BUG in handling PUBLISH in PA module - cosmetical changes in PA, libs - added some trace logs for performance tests

Vaclav Kubart authored on 11/05/2006 07:29:49
Showing 8 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+2006-05-11
2
+	* added changelog
3
+	* added "simple profiling" capability (need to call PROF_START and
4
+	PROF_STOP macros in profiled routine)
0 5
new file mode 100644
... ...
@@ -0,0 +1,89 @@
1
+#ifdef SER
2
+
3
+#include <cds/ser_profile.h>
4
+#include "dprint.h"
5
+
6
+#include <stdio.h>
7
+#include <sys/types.h>
8
+#include <unistd.h>
9
+
10
+DEFINE_PROF_POINT(pa_handle_subscription)
11
+DEFINE_PROF_POINT(pa_timer_presentity)
12
+DEFINE_PROF_POINT(pa_timer_pdomain)
13
+DEFINE_PROF_POINT(pa_response_generation)
14
+	
15
+DEFINE_PROF_POINT(rls_handle_subscription)
16
+DEFINE_PROF_POINT(rls_timer_cb)
17
+DEFINE_PROF_POINT(rls_is_simple_rls_target)
18
+DEFINE_PROF_POINT(rls_query_rls_sevices)
19
+DEFINE_PROF_POINT(rls_query_resource_list)
20
+DEFINE_PROF_POINT(rls_have_flat_list)
21
+	
22
+DEFINE_PROF_POINT(tem_timer_cb)
23
+DEFINE_PROF_POINT(tem_add_event)
24
+DEFINE_PROF_POINT(tem_remove_event)
25
+DEFINE_PROF_POINT(tem_do_step)
26
+
27
+DEFINE_PROF_POINT(b2b_handle_notify)
28
+	
29
+void prof_trace(FILE *f, int pid, const char *s, profile_data_t a)	
30
+{
31
+	fprintf(f, "%d\t%30s\t%d\t%u\n", 
32
+			pid, s, a.count, a.spent_time);
33
+	if (a.start_count != a.stop_count) 
34
+		fprintf(f, "%s, %d start_count != stop_count (%d != %d)\n", 
35
+				s, pid, a.start_count, a.stop_count);
36
+}
37
+
38
+void prof_trace_nested(FILE *f, int pid, const char *s, profile_data_t a)	
39
+{
40
+	fprintf(f, "%d\t%29s*\t%d\t%u\n", 
41
+			pid, s, a.count, a.spent_time);
42
+	if (a.start_count != a.stop_count) 
43
+		fprintf(f, "%s, %d start_count != stop_count (%d != %d)\n", 
44
+				s, pid, a.start_count, a.stop_count);
45
+}
46
+
47
+#define trace(f, p, name)	prof_trace(f, p, #name , prof_point(name))
48
+#define trace_nested(f, p, name)	prof_trace_nested(f, p, #name , prof_point(name))
49
+
50
+void trace_func()
51
+{
52
+	pid_t p = getpid();
53
+	FILE *f;
54
+
55
+	f = fopen("/tmp/ser.profile", "at");
56
+	if (!f) ERR("can't write into profile file\n");
57
+	else {
58
+		
59
+		trace(f, p, pa_handle_subscription);
60
+		trace(f, p, pa_timer_pdomain);
61
+		trace_nested(f, p, pa_timer_presentity);
62
+		trace_nested(f, p, pa_response_generation);
63
+		
64
+		trace(f, p, rls_handle_subscription);
65
+		trace(f, p, rls_timer_cb);
66
+		trace(f, p, rls_is_simple_rls_target);
67
+		trace(f, p, rls_query_rls_sevices);
68
+		trace(f, p, rls_query_resource_list);
69
+		trace(f, p, rls_have_flat_list);
70
+		
71
+	/* 	trace_nested(f, p, tem_timer_cb); */
72
+		trace(f, p, tem_add_event);
73
+		trace(f, p, tem_remove_event);
74
+		trace(f, p, tem_do_step);
75
+		
76
+		trace(f, p, b2b_handle_notify);
77
+		
78
+		fprintf(f, "%d\t%30s\t1\t%u\n", p, "all", get_prof_time());
79
+		
80
+		fclose(f);
81
+	}
82
+}
83
+	
84
+void ser_profile_init()
85
+{
86
+	start_profile(trace_func);
87
+}
88
+
89
+#endif
0 90
new file mode 100644
... ...
@@ -0,0 +1,35 @@
1
+#ifndef __SER_PROFILE
2
+#define __SER_PROFILE
3
+
4
+#ifdef SER
5
+
6
+/* declarations of watched profile points */
7
+
8
+#include <cds/simple_profile.h>
9
+
10
+DECLARE_PROF_POINT(pa_handle_subscription)
11
+DECLARE_PROF_POINT(pa_timer_presentity)
12
+DECLARE_PROF_POINT(pa_timer_pdomain)
13
+DECLARE_PROF_POINT(pa_response_generation)
14
+	
15
+DECLARE_PROF_POINT(rls_handle_subscription)
16
+DECLARE_PROF_POINT(rls_timer_cb)
17
+DECLARE_PROF_POINT(rls_is_simple_rls_target)
18
+DECLARE_PROF_POINT(rls_query_rls_sevices)
19
+DECLARE_PROF_POINT(rls_query_resource_list)
20
+DECLARE_PROF_POINT(rls_have_flat_list)
21
+DECLARE_PROF_POINT(tem_timer_cb)
22
+DECLARE_PROF_POINT(tem_add_event)
23
+DECLARE_PROF_POINT(tem_remove_event)
24
+DECLARE_PROF_POINT(tem_do_step)
25
+
26
+DECLARE_PROF_POINT(b2b_handle_notify)
27
+
28
+/* do NOT use directly this */
29
+void ser_profile_init();
30
+
31
+#define SER_PROFILE_INIT	ser_profile_init();
32
+
33
+#endif
34
+
35
+#endif
0 36
new file mode 100644
... ...
@@ -0,0 +1,87 @@
1
+#include <stdio.h>
2
+#include <cds/simple_profile.h>
3
+#include <signal.h>
4
+#include <sys/time.h>
5
+#include <string.h>
6
+
7
+/* FIXME: only for testing */
8
+/*#include "dprint.h"*/
9
+
10
+#define trace_signal SIGTRAP
11
+
12
+unsigned int tick_counter = 0;
13
+static struct sigaction old_sigprof_action;
14
+__sighandler_t old_sigx_action;
15
+static int initialized = 0;
16
+static trace_f trace_function = NULL;
17
+
18
+int reset_timer()
19
+{
20
+	struct itimerval tv;
21
+	int res;
22
+	
23
+	tv.it_interval.tv_sec = 0;
24
+	tv.it_interval.tv_usec = 1000; 
25
+	/*tv.it_interval.tv_usec = 10 * 1000; */
26
+	tv.it_value.tv_sec = tv.it_interval.tv_sec;
27
+	tv.it_value.tv_usec = tv.it_interval.tv_usec;
28
+
29
+	res = setitimer(ITIMER_PROF, &tv, NULL);
30
+
31
+	return res;
32
+}
33
+
34
+void prof_handler(int a, siginfo_t *info, void *b)
35
+{
36
+	tick_counter++;
37
+/*	LOG(L_ERR, "PROFILE HANDLER called\n"); */
38
+	/* reset_timer(); */
39
+}
40
+
41
+void trace_handler(int a)
42
+{
43
+	if (trace_function) trace_function();
44
+}
45
+
46
+int start_profile(trace_f tf)
47
+{
48
+	struct sigaction action;
49
+	int res;
50
+
51
+	if (initialized) return 1;
52
+	initialized = 1;
53
+	trace_function = tf;
54
+
55
+	memset(&action, 0, sizeof(action));
56
+	action.sa_sigaction = prof_handler;
57
+    sigemptyset(&action.sa_mask);
58
+	action.sa_flags = SA_SIGINFO;
59
+	res = sigaction(SIGPROF, &action, &old_sigprof_action);
60
+	if (res != 0) {
61
+		/* ERROR_LOG("can't set signal handle (%d)\n", res);*/
62
+		return -1;
63
+	}
64
+	
65
+	old_sigx_action = signal(trace_signal, &trace_handler);
66
+
67
+	res = reset_timer();
68
+	if (res != 0) {
69
+		/* ERROR_LOG("can't set itimer (%d)\n", res);*/
70
+		signal(trace_signal, old_sigx_action);
71
+		sigaction(SIGPROF, &old_sigprof_action, NULL);
72
+		return -1;
73
+	}
74
+
75
+	return 0;
76
+}
77
+
78
+int stop_profile()
79
+{
80
+	if (initialized) {
81
+		initialized = 0;
82
+		signal(trace_signal, old_sigx_action);
83
+		return sigaction(SIGPROF, &old_sigprof_action, NULL);
84
+	}
85
+	else return -1;
86
+}
87
+
0 88
new file mode 100644
... ...
@@ -0,0 +1,47 @@
1
+#ifndef __SIMPLE_PROFILE_H
2
+#define __SIMPLE_PROFILE_H
3
+
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+	
8
+typedef void(*trace_f)();
9
+
10
+int start_profile(trace_f tf);
11
+int stop_profile();
12
+
13
+/* do NOT use this directly ! */
14
+extern unsigned int tick_counter;
15
+
16
+#define get_prof_time()	tick_counter
17
+
18
+typedef struct {
19
+	int count;
20
+	int start_count, stop_count;
21
+	unsigned int spent_time;
22
+} profile_data_t;
23
+
24
+#define DEFINE_PROF_POINT(name) profile_data_t prof_##name = { 0, 0, 0 };
25
+#define DECLARE_PROF_POINT(name) extern profile_data_t prof_##name;
26
+
27
+#define prof_point(name)	prof_##name
28
+#define PROF_START_DECL(name)	int _prof_act_##name;
29
+#define PROF_START_BODY(name)	prof_point(name).count++; \
30
+							prof_point(name).start_count++; \
31
+							_prof_act_##name = get_prof_time();
32
+
33
+#define PROF_START(name)	int _prof_act_##name; \
34
+							prof_point(name).count++; \
35
+							prof_point(name).start_count++; \
36
+							_prof_act_##name = get_prof_time();
37
+
38
+#define PROF_STOP(name)	prof_point(name).stop_count++; \
39
+						prof_point(name).spent_time += get_prof_time() - _prof_act_##name;
40
+
41
+#define prof_return(a, val)	prof_stop(a) return val;
42
+
43
+#ifdef __cplusplus
44
+}
45
+#endif
46
+ 
47
+#endif
... ...
@@ -1,3 +1,7 @@
1
+2006-04-01 (?)
2
+	* xcap queries goes through xcap module if compiled with SER (removes
3
+	dependency on libcurl3 for PA module)
4
+
1 5
 2006-03-30
2 6
 	* corrected bug (library couldn't be compiled)
3 7
 
... ...
@@ -61,7 +61,9 @@ int get_pres_rules(const str_t *username, const str_t *filename,
61 61
 	/* parse input data */
62 62
 	res = parse_pres_rules(data, dsize, dst);
63 63
 	if (res != RES_OK) {
64
-		ERROR_LOG("Error occured during document parsing!\n");
64
+		ERROR_LOG("Error occured during parsing pres-rules for %.*s!\n", 
65
+				str_len(username), 
66
+				username ? username->s : "");
65 67
 	}
66 68
 
67 69
 	if (data) cds_free(data);
... ...
@@ -638,11 +638,11 @@ int get_rls_from_full_doc(const str_t *uri,
638 638
 	/* try to find given service according to uri */
639 639
 	canonicalize_uri(uri, &curi);
640 640
 	service = find_service(rls, &curi); 
641
+	if (!service) DEBUG_LOG("Service %.*s not found!\n", FMT_STR(curi));
641 642
 	str_free_content(&curi);
642 643
 	
643 644
 	if (!service) {
644 645
 		if (rls) free_rls_services(rls);
645
-		DEBUG_LOG("Empty service!\n");
646 646
 		return RES_XCAP_QUERY_ERR;
647 647
 	}
648 648
 
... ...
@@ -740,7 +740,9 @@ int get_resource_list_from_full_doc(const str_t *user,
740 740
 	
741 741
 	if (!list) {
742 742
 		ERROR_LOG("Empty resource list!\n");
743
-		return RES_INTERNAL_ERR;
743
+		*dst = NULL;
744
+		return 0; /* this is not error! */
745
+		/* return RES_INTERNAL_ERR; */
744 746
 	}
745 747
 
746 748
 	/* search for right list element */