/src/opensips/lib/dbg/profiling.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2023 OpenSIPS Solutions |
3 | | * |
4 | | * This file is part of opensips, a free SIP server. |
5 | | * |
6 | | * opensips is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 2 of the License, or |
9 | | * (at your option) any later version |
10 | | * |
11 | | * opensips is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | | */ |
20 | | |
21 | | #ifndef __OSS_PROFILING_H__ |
22 | | #define __OSS_PROFILING_H__ |
23 | | |
24 | | #include <stdio.h> |
25 | | #include <string.h> |
26 | | |
27 | | #include "../../pt.h" |
28 | | #include "../../dprint.h" |
29 | | |
30 | | #ifdef PROFILING |
31 | | #include <gperftools/profiler.h> |
32 | | |
33 | | static inline int _ProfilerStart(pid_t pid, const char *proc_desc) |
34 | | { |
35 | | char fname[50]; |
36 | | int rval; |
37 | | |
38 | | LM_NOTICE("START profiling in process %s (%d)\n", |
39 | | proc_desc, pid); |
40 | | |
41 | | if (pid == 0) { |
42 | | rval = ProfilerStart("gperf-attendant.prof") == 0 ? -1 : 0; |
43 | | return rval; |
44 | | } |
45 | | |
46 | | if (!strcmp(proc_desc, "UDP receiver")) |
47 | | sprintf(fname, "gperf-udp-%d.prof", getpid()); |
48 | | else if (!strcmp(proc_desc, "SIP receiver TCP")) |
49 | | sprintf(fname, "gperf-tcp-%d.prof", getpid()); |
50 | | else if (!strcmp(proc_desc, "Timer handler")) |
51 | | sprintf(fname, "gperf-timer-%d.prof", getpid()); |
52 | | else |
53 | | sprintf(fname, "gperf-%d.prof", getpid()); |
54 | | |
55 | | return ProfilerStart(fname) == 0 ? -1 : 0; |
56 | | } |
57 | | |
58 | | static inline int _ProfilerStart_child(const struct internal_fork_params *ifpp) |
59 | | { |
60 | | if (_ProfilerStart(pt[process_no].pid, ifpp->proc_desc) != 0) { |
61 | | LM_CRIT("failed to start profiler for process %d", process_no); |
62 | | return -1; |
63 | | } |
64 | | return 0; |
65 | | } |
66 | | |
67 | | static inline int _ProfilerStart_parent(void) |
68 | | { |
69 | | |
70 | | if (_ProfilerStart(0, "attendant") != 0) { |
71 | | LM_CRIT("failed to start profiling\n"); |
72 | | return -1; |
73 | | } |
74 | | return 0; |
75 | | } |
76 | | |
77 | | static inline void _ProfilerStop(void) |
78 | | { |
79 | | ProfilerStop(); |
80 | | |
81 | | LM_NOTICE("STOP profiling in process %s (%d)\n", |
82 | | pt ? pt[process_no].desc : "<none>", |
83 | | pt ? pt[process_no].pid : -1); |
84 | | } |
85 | | #else |
86 | 0 | static inline int _ProfilerStart(pid_t pid, const char *proc_desc) { return 0; } Unexecuted instantiation: pt.c:_ProfilerStart Unexecuted instantiation: shutdown.c:_ProfilerStart |
87 | 0 | static inline int _ProfilerStart_child(const struct internal_fork_params *ifpp) { return 0; } Unexecuted instantiation: pt.c:_ProfilerStart_child Unexecuted instantiation: shutdown.c:_ProfilerStart_child |
88 | 0 | static inline int _ProfilerStart_parent(void) { return 0; } Unexecuted instantiation: pt.c:_ProfilerStart_parent Unexecuted instantiation: shutdown.c:_ProfilerStart_parent |
89 | | #define ProfilerStart(...) |
90 | | #define ProfilerStop(...) |
91 | | #define _ProfilerStop(...) |
92 | | #endif |
93 | | |
94 | | #endif /* __OSS_PROFILING_H__ */ |