trace-cmd: libtracecmd: Rename private functions to fix static building
PATCH 1/1 trace-cmd: libtracecmd: Rename private functions to fix static building
Building trace-cmd statically fails because of duplicated symbols for strstrip() function which is also implemented in libtracefs. The __hidden attribute does not resolve these conflicts for static builds due to the lack of namespacing support in C. Refer to the associated Bugzilla page [1] for further details.
Although only strstrip() breaks the static build as of now, we should fix the underlying issue comprehensively across the libtraceevent, libtracefs, and trace-cmd packages. The recommendation on [1] is prepending package name (e.g., "tracecmd_") to private functions (tagged with __hidden attribute).
Thus:
1. Retain private functions which already start with "tracecmd_".
2. If a private function starts with "trace_", then just change its prefix to "tracecmd_".
3. If prepending "tracecmd_" prefix to a private function's name clashes with an existing one, rename one of the functions per its context (e.g., rename trace_load_plugins() to tracecmd_load_plugins_from_handle() and trace_append_options() to tracecmd_append_options_to_file()).
4. Prepend "tracecmd_" prefix to all remaining "__hidden" functions.
Future __hidden functions should follow this prefixing schemed to avoid new naming conflicts.
[1] https://bugzilla.kernel.org/show_bug.cgi?id=217768
--- .../include/private/trace-cmd-private.h | 14 +- lib/trace-cmd/include/private/trace-hash.h | 10 +- lib/trace-cmd/include/private/trace-rbtree.h | 4 +- lib/trace-cmd/include/trace-cmd-local.h | 56 ++-- lib/trace-cmd/trace-hash.c | 10 +- lib/trace-cmd/trace-input.c | 206 ++++++------ lib/trace-cmd/trace-maps.c | 20 +- lib/trace-cmd/trace-msg.c | 6 +- lib/trace-cmd/trace-output.c | 303 +++++++++--------- lib/trace-cmd/trace-perf.c | 22 +- lib/trace-cmd/trace-rbtree.c | 6 +- lib/trace-cmd/trace-timesync.c | 2 +- lib/trace-cmd/trace-util.c | 18 +- tracecmd/include/trace-local.h | 24 +- tracecmd/trace-agent.c | 12 +- tracecmd/trace-check-events.c | 2 +- tracecmd/trace-list.c | 4 +- tracecmd/trace-listen.c | 6 +- tracecmd/trace-profile.c | 58 ++-- tracecmd/trace-read.c | 10 +- tracecmd/trace-record.c | 28 +- tracecmd/trace-vm.c | 2 +- tracecmd/trace-vsock.c | 14 +- 23 files changed, 419 insertions(+), 418 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +7 -7
@@ -28,7 +28,7 @@#define TSCNSEC_CLOCK "tsc2nsec" -struct tep_plugin_list *trace_load_plugins (struct tep_handle *tep,int flags); +struct tep_plugin_list *tracecmd_load_plugins_from_handle (struct tep_handle *tep,int flags);int *tracecmd_add_id (int *list,int id,int len);
@@ -504,7 +504,7 @@ enum tracecmd_time_sync_role {void tracecmd_tsync_init (void );int tracecmd_tsync_proto_getall (struct tracecmd_tsync_protos **protos,const char *clock,int role); -bool tsync_proto_is_supported (const char *proto_name); +bool tracecmd_tsync_proto_is_supported (const char *proto_name);struct tracecmd_time_sync *tracecmd_tsync_with_host (int fd,const char *proto,const char *clock,int remote_id,int local_id);
@@ -571,8 +571,8 @@ int tracecmd_load_chunks_info(struct tracecmd_compression *handle,/* --- Plugin handling --- */ extern struct tep_plugin_option trace_ftrace_options[]; -char **trace_util_find_plugin_files (const char *suffix); -void trace_util_free_plugin_files (char **files); +char **tracecmd_util_find_plugin_files (const char *suffix); +void tracecmd_util_free_plugin_files (char **files);/* Used for trace-cmd list */ void tracecmd_ftrace_load_options (void );
@@ -633,9 +633,9 @@ struct trace_perf {struct perf_event_attr pe;struct perf_event_mmap_page *mmap; }; -int trace_perf_init (struct trace_perf *perf,int pages,int cpu,int pid); -int trace_perf_open (struct trace_perf *perf); -void trace_perf_close (struct trace_perf *perf); +int tracecmd_perf_init (struct trace_perf *perf,int pages,int cpu,int pid); +int tracecmd_perf_open (struct trace_perf *perf); +void tracecmd_perf_close (struct trace_perf *perf);#endif #endif /* _TRACE_CMD_PRIVATE_H */
lib/trace-cmd/include/private/trace-hash.h +5 -5
@@ -18,10 +18,10 @@ struct trace_hash {int power; }; -int trace_hash_init (struct trace_hash *hash,int buckets); -void trace_hash_free (struct trace_hash *hash); -int trace_hash_add (struct trace_hash *hash,struct trace_hash_item *item); -int trace_hash_empty (struct trace_hash *hash); +int tracecmd_hash_init (struct trace_hash *hash,int buckets); +void tracecmd_hash_free (struct trace_hash *hash); +int tracecmd_hash_add (struct trace_hash *hash,struct trace_hash_item *item); +int tracecmd_hash_empty (struct trace_hash *hash);static inline void trace_hash_del (struct trace_hash_item *item) {
@@ -49,7 +49,7 @@ static inline void trace_hash_del(struct trace_hash_item *item)typedef int (*trace_hash_func )(struct trace_hash_item *item,void *data);struct trace_hash_item * -trace_hash_find (struct trace_hash *hash,unsigned long long key, +tracecmd_hash_find (struct trace_hash *hash,unsigned long long key,trace_hash_func match,void *data);#endif /* _TRACE_HASH_H */
lib/trace-cmd/include/private/trace-rbtree.h +2 -2
@@ -24,11 +24,11 @@ struct trace_rbtree { size_t nr_nodes; }; -void trace_rbtree_init (struct trace_rbtree *tree,trace_rbtree_cmp_fn cmp_fn, +void tracecmd_rbtree_init (struct trace_rbtree *tree,trace_rbtree_cmp_fn cmp_fn,trace_rbtree_search_fn search_fn);struct trace_rbtree_node *trace_rbtree_find (struct trace_rbtree *tree,const void *data);void trace_rbtree_delete (struct trace_rbtree *tree,struct trace_rbtree_node *node); -int trace_rbtree_insert (struct trace_rbtree *tree,struct trace_rbtree_node *node); +int tracecmd_rbtree_insert (struct trace_rbtree *tree,struct trace_rbtree_node *node);struct trace_rbtree_node *trace_rbtree_pop_nobalance (struct trace_rbtree *tree);#endif /* _TRACE_RBTREE_H */
lib/trace-cmd/include/trace-cmd-local.h +28 -28
84 lines not on this page · raw message
lib/trace-cmd/trace-hash.c +5 -5
@@ -12,7 +12,7 @@#include "trace-cmd-private.h" #include "trace-hash.h" -int __hidden trace_hash_init(struct trace_hash *hash, int buckets) +int __hidden tracecmd_hash_init(struct trace_hash *hash, int buckets) {memset (hash,0 ,sizeof (*hash));
@@ -28,12 +28,12 @@ int __hidden trace_hash_init(struct trace_hash *hash, int buckets)return 0 ; } -void __hidden trace_hash_free(struct trace_hash *hash) +void __hidden tracecmd_hash_free(struct trace_hash *hash) {free (hash->buckets); } -int __hidden trace_hash_empty(struct trace_hash *hash) +int __hidden tracecmd_hash_empty(struct trace_hash *hash) {struct trace_hash_item **bucket;
@@ -43,7 +43,7 @@ int __hidden trace_hash_empty(struct trace_hash *hash)return 1 ; } -int __hidden trace_hash_add(struct trace_hash *hash, struct trace_hash_item *item) +int __hidden tracecmd_hash_add(struct trace_hash *hash, struct trace_hash_item *item) {struct trace_hash_item *next; int bucket = hash->power ? item->key & hash->power :
@@ -64,7 +64,7 @@ int __hidden trace_hash_add(struct trace_hash *hash, struct trace_hash_item *ite } __hidden struct trace_hash_item * -trace_hash_find (struct trace_hash *hash,unsigned long long key, +tracecmd_hash_find (struct trace_hash *hash,unsigned long long key,trace_hash_func match,void *data) {struct trace_hash_item *item;
lib/trace-cmd/trace-input.c +103 -103
675 lines not on this page · raw message
lib/trace-cmd/trace-maps.c +10 -10
@@ -74,8 +74,8 @@ int tracecmd_map_vcpus(struct tracecmd_input **handles, int nr_handles) gmap[k].self = &gmap[k]; } -trace_set_guest_map (handles[i], gmap); -trace_set_guest_map_cnt (handles[i], vcpu_count); +tracecmd_set_guest_map (handles[i], gmap); +tracecmd_set_guest_map_cnt (handles[i], vcpu_count);/* Update the host mapping of all guests to the host */ map =realloc (vcpu_maps,sizeof (*map) * (nr_vcpu_maps + vcpu_count));
@@ -96,8 +96,8 @@ int tracecmd_map_vcpus(struct tracecmd_input **handles, int nr_handles)/* We want to do a binary search via host_pid to find these mappings */ qsort (vcpu_maps, nr_vcpu_maps,sizeof (*map), cmp_map); -trace_set_guest_map (handles[0 ], vcpu_maps); -trace_set_guest_map_cnt (handles[0 ], nr_vcpu_maps); +tracecmd_set_guest_map (handles[0 ], vcpu_maps); +tracecmd_set_guest_map_cnt (handles[0 ], nr_vcpu_maps);return mappings;
@@ -106,7 +106,7 @@ int tracecmd_map_vcpus(struct tracecmd_input **handles, int nr_handles)return -1 ; } -__hidden void trace_guest_map_free(struct tracecmd_cpu_map *map) +__hidden void tracecmd_guest_map_free(struct tracecmd_cpu_map *map) {free (map); }
@@ -118,7 +118,7 @@ struct tracecmd_cpu_map *tracecmd_map_find_by_host_pid(struct tracecmd_input *hastruct tracecmd_cpu_map key;int nr_maps; - map =trace_get_guest_map (handle); + map =tracecmd_get_guest_map (handle);if (!map)return NULL ;
@@ -126,11 +126,11 @@ struct tracecmd_cpu_map *tracecmd_map_find_by_host_pid(struct tracecmd_input *ha handle = map->host_handle;/* And again, get the mapping of the host, as it has all the mappings */ - map =trace_get_guest_map (handle); + map =tracecmd_get_guest_map (handle);if (!map)return NULL ; - nr_maps =trace_get_guest_map_cnt (handle); + nr_maps =tracecmd_get_guest_map_cnt (handle); key.host_pid = host_pid;
@@ -168,10 +168,10 @@ struct tracecmd_cpu_map *tracecmd_get_cpu_map(struct tracecmd_input *handle, intstruct tracecmd_cpu_map *map;int cnt; - map =trace_get_guest_map (handle); + map =tracecmd_get_guest_map (handle);/* Make sure it's for the guest handle, as this could be a host handle */ map = map->self; - cnt =trace_get_guest_map_cnt (map->guest_handle); + cnt =tracecmd_get_guest_map_cnt (map->guest_handle);if (cnt <= cpu)return NULL ;
lib/trace-cmd/trace-msg.c +3 -3
@@ -183,7 +183,7 @@ static int __msg_write(int fd, struct tracecmd_msg *msg, bool network)return __do_write_check (fd, msg->buf, data_size); } -__hidden off_t msg_lseek(struct tracecmd_msg_handle *msg_handle, off_t offset, int whence) +__hidden off_t tracecmd_msg_lseek(struct tracecmd_msg_handle *msg_handle, off_t offset, int whence) {off_t cache_offset = msg_handle->cache_start_offset;off_t ret;
@@ -855,7 +855,7 @@ int tracecmd_msg_send_options(struct tracecmd_msg_handle *msg_handle,void *buf;int ret; - buf =trace_get_options (handle, &len); + buf =tracecmd_get_options (handle, &len);if (!buf)return -1 ;
@@ -963,7 +963,7 @@ int tracecmd_msg_read_options(struct tracecmd_msg_handle *msg_handle, }msg_free (&msg); - ret =trace_append_options (handle, buf, len); + ret =tracecmd_append_options_to_file (handle, buf, len);free (buf);return ret;
lib/trace-cmd/trace-output.c +152 -151
1,004 lines not on this page · raw message
lib/trace-cmd/trace-perf.c +11 -11
@@ -31,7 +31,7 @@ static void default_perf_init_pe(struct perf_event_attr *pe) }/** -* trace_perf_init - Initialize perf context +* tracecmd_perf_init - Initialize perf context * * @perf: structure, representing perf context, that will be initialized. * @pages: Number of perf memory mapped pages.
@@ -39,12 +39,12 @@ static void default_perf_init_pe(struct perf_event_attr *pe)* @pid: PID, associated with this perf context. * * The perf context in initialized with default values. The caller can set -* custom perf parameters in perf->pe, before calling trace_perf_open() API. +* custom perf parameters in perf->pe, before calling tracecmd_perf_open() API. * * Returns 0 on success, or -1 in case of an error. * */ -int __hidden trace_perf_init(struct trace_perf *perf, int pages, int cpu, int pid) +int __hidden tracecmd_perf_init(struct trace_perf *perf, int pages, int cpu, int pid) {if (!perf)return -1 ;
@@ -60,13 +60,13 @@ int __hidden trace_perf_init(struct trace_perf *perf, int pages, int cpu, int pi }/** -* trace_perf_close - Close perf session +* tracecmd_perf_close - Close perf session * * @perf: structure, representing context of a running perf session, opened -* with trace_perf_open() +* with tracecmd_perf_open() * */ -void __hidden trace_perf_close(struct trace_perf *perf) +void __hidden tracecmd_perf_close(struct trace_perf *perf) {if (perf->fd >=0 )close (perf->fd);
@@ -77,15 +77,15 @@ void __hidden trace_perf_close(struct trace_perf *perf) }/** -* trace_perf_open - Open perf session +* tracecmd_perf_open - Open perf session * * @perf: structure, representing perf context that will be opened. It must be -* initialized with trace_perf_init(). +* initialized with tracecmd_perf_init(). * * Returns 0 on success, or -1 in case of an error. In case of success, the -* session must be closed with trace_perf_close() +* session must be closed with tracecmd_perf_close() */ -int __hidden trace_perf_open(struct trace_perf *perf) +int __hidden tracecmd_perf_open(struct trace_perf *perf) { perf->fd =syscall (__NR_perf_event_open, &perf->pe, perf->pid, perf->cpu,-1 ,0 );if (perf->fd <0 )
@@ -100,6 +100,6 @@ int __hidden trace_perf_open(struct trace_perf *perf)return 0 ; error: -trace_perf_close (perf); +tracecmd_perf_close (perf);return -1 ; }
lib/trace-cmd/trace-rbtree.c +3 -3
@@ -13,7 +13,7 @@ enum { BLACK, }; -void __hidden trace_rbtree_init(struct trace_rbtree *tree, trace_rbtree_cmp_fn cmp_fn, +void __hidden tracecmd_rbtree_init(struct trace_rbtree *tree, trace_rbtree_cmp_fn cmp_fn,trace_rbtree_search_fn search_fn) {memset (tree,0 ,sizeof (*tree));
@@ -163,7 +163,7 @@ static void check_tree(struct trace_rbtree *tree)static inline void check_tree (struct trace_rbtree *tree) { }#endif -int __hidden trace_rbtree_insert(struct trace_rbtree *tree, +int __hidden tracecmd_rbtree_insert(struct trace_rbtree *tree,struct trace_rbtree_node *node) {struct trace_rbtree_node *uncle;
@@ -371,7 +371,7 @@ void trace_rbtree_delete(struct trace_rbtree *tree, struct trace_rbtree_node *nocheck_tree (tree); } -__hidden struct trace_rbtree_node *trace_rbtree_next(struct trace_rbtree *tree, +__hidden struct trace_rbtree_node *tracecmd_rbtree_next(struct trace_rbtree *tree,struct trace_rbtree_node *node) {check_tree (tree);
lib/trace-cmd/trace-timesync.c +1 -1
@@ -116,7 +116,7 @@ int tracecmd_tsync_proto_unregister(char *proto_name)return -1 ; } -bool __hidden tsync_proto_is_supported(const char *proto_name) +bool __hidden tracecmd_tsync_proto_is_supported(const char *proto_name) {if (tsync_proto_find (proto_name))return true;
lib/trace-cmd/trace-util.c +9 -9
@@ -280,7 +280,7 @@ static void add_plugin_file(struct tep_handle *pevent, const char *path, }/** -* trace_util_find_plugin_files - find list of possible plugin files +* tracecmd_util_find_plugin_files - find list of possible plugin files * @suffix: The suffix of the plugin files to find * * Searches the plugin directory for files that end in @suffix, and
@@ -291,9 +291,9 @@ static void add_plugin_file(struct tep_handle *pevent, const char *path,* the errno will be returned with the TRACECMD_ERR_MSK to denote * such an error occurred. * -* Use trace_util_free_plugin_files() to free the result. +* Use tracecmd_util_free_plugin_files() to free the result. */ -__hidden char **trace_util_find_plugin_files(const char *suffix) +__hidden char **tracecmd_util_find_plugin_files(const char *suffix) {struct add_plugin_data pdata;
@@ -308,12 +308,12 @@ __hidden char **trace_util_find_plugin_files(const char *suffix) }/** -* trace_util_free_plugin_files - free the result of trace_util_find_plugin_files() -* @files: The result from trace_util_find_plugin_files() +* tracecmd_util_free_plugin_files - free the result of tracecmd_util_find_plugin_files() +* @files: The result from tracecmd_util_find_plugin_files() * -* Frees the contents that were allocated by trace_util_find_plugin_files(). +* Frees the contents that were allocated by tracecmd_util_find_plugin_files(). */ -void __hidden trace_util_free_plugin_files(char **files) +void __hidden tracecmd_util_free_plugin_files(char **files) {int i;
@@ -349,7 +349,7 @@ static char *get_source_plugins_dir(void) } __hidden struct tep_plugin_list * -trace_load_plugins (struct tep_handle *tep,int flags) +tracecmd_load_plugins_from_handle (struct tep_handle *tep,int flags) {struct tep_plugin_list *list;char *path;
@@ -659,7 +659,7 @@ static void __attribute__((destructor)) tracecmd_lib_free(void)tracecmd_compress_free (); } -__hidden bool check_file_state(unsigned long file_version, int current_state, int new_state) +__hidden bool tracecmd_check_file_state(unsigned long file_version, int current_state, int new_state) {if (file_version >=FILE_VERSION_SECTIONS ) {if (current_state <TRACECMD_FILE_INIT )
tracecmd/include/trace-local.h +12 -12
@@ -399,27 +399,27 @@ int get_local_cid(unsigned int *cid);char *trace_get_guest_file (const char *file,const char *guest);#ifdef VSOCK -int trace_vsock_open (unsigned int cid,unsigned int port); -int trace_vsock_make (unsigned int port); -int trace_vsock_make_any (void ); +int tracecmd_vsock_open (unsigned int cid,unsigned int port); +int tracecmd_vsock_make (unsigned int port); +int tracecmd_vsock_make_any (void );int get_vsocket_params (int fd,unsigned int *lcid,unsigned int *rcid); -int trace_vsock_get_port (int sd,unsigned int *port); -bool trace_vsock_can_splice_read (void ); -int trace_vsock_local_cid (void ); +int tracecmd_vsock_get_port (int sd,unsigned int *port); +bool tracecmd_vsock_can_splice_read (void ); +int tracecmd_vsock_local_cid (void );int trace_vsock_print_connection (int fd);#else -static inline int trace_vsock_open (unsigned int cid,unsigned int port) +static inline int tracecmd_vsock_open (unsigned int cid,unsigned int port) {return -ENOTSUP ; } -static inline int trace_vsock_make (unsigned int port) +static inline int tracecmd_vsock_make (unsigned int port) {return -ENOTSUP ; } -static inline int trace_vsock_make_any (void ) +static inline int tracecmd_vsock_make_any (void ) {return -ENOTSUP ;
@@ -430,17 +430,17 @@ static inline int get_vsocket_params(int fd, unsigned int *lcid, unsigned int *rreturn -ENOTSUP ; } -static inline int trace_vsock_get_port (int sd,unsigned int *port) +static inline int tracecmd_vsock_get_port (int sd,unsigned int *port) {return -ENOTSUP ; } -static inline bool trace_vsock_can_splice_read (void ) +static inline bool tracecmd_vsock_can_splice_read (void ) {return false; } -static inline int trace_vsock_local_cid (void ) +static inline int tracecmd_vsock_local_cid (void ) {return -ENOTSUP ; }
tracecmd/trace-agent.c +6 -6
@@ -32,11 +32,11 @@ static void make_vsocks(int nr, int *fds, unsigned int *ports)int i, fd, ret;for (i =0 ; i < nr; i++) { - fd =trace_vsock_make_any (); + fd =tracecmd_vsock_make_any ();if (fd <0 )die ("Failed to open vsocket" ); - ret =trace_vsock_get_port (fd, &port); + ret =tracecmd_vsock_get_port (fd, &port);if (ret <0 )die ("Failed to get vsocket address" );
@@ -223,9 +223,9 @@ static void agent_handle(int sd, int nr_cpus, int page_size, remote_id =-1 ; local_id =-2 ; } - fd =trace_vsock_make_any (); + fd =tracecmd_vsock_make_any ();if (fd >=0 && -trace_vsock_get_port (fd, &tsync_port) <0 ) { +tracecmd_vsock_get_port (fd, &tsync_port) <0 ) {close (fd); fd =-1 ; }
@@ -327,13 +327,13 @@ static void agent_serve(unsigned int port, bool do_daemon, int proxy_id,if (listen (sd,5 ) <0 )die ("Failed to listen on %d\n" , port); }else - sd =trace_vsock_make (port); + sd =tracecmd_vsock_make (port);if (sd <0 )die ("Failed to open socket" );tracecmd_tsync_init ();if (!network) { - cid =trace_vsock_local_cid (); + cid =tracecmd_vsock_local_cid ();if (cid >=0 )printf ("listening on @%u:%u\n" , cid, port); }
tracecmd/trace-check-events.c +1 -1
@@ -59,7 +59,7 @@ void trace_check_events(int argc, char **argv)if (!pevent)exit (EINVAL ); - list =trace_load_plugins (pevent, open_flags); + list =tracecmd_load_plugins_from_handle (pevent, open_flags); ret =tracefs_fill_local_events (tracing, pevent, &parsing_failures);if (ret || parsing_failures) ret =EINVAL ;
tracecmd/trace-list.c +2 -2
@@ -551,7 +551,7 @@ static void show_plugin_options(void)trace_seq_init (&s); - list =trace_load_plugins (pevent,0 ); + list =tracecmd_load_plugins_from_handle (pevent,0 );tep_plugin_print_options (&s);trace_seq_do_printf (&s);tep_unload_plugins (list, pevent);
@@ -577,7 +577,7 @@ static void show_plugins(void)trace_seq_init (&s); - list =trace_load_plugins (pevent,0 ); + list =tracecmd_load_plugins_from_handle (pevent,0 );tep_print_plugins (&s," " ,"\n" , list);trace_seq_do_printf (&s);
tracecmd/trace-listen.c +3 -3
@@ -225,7 +225,7 @@ static int setup_vsock_port(int start_port, int *sfd) {int sd; - sd =trace_vsock_make (start_port); + sd =tracecmd_vsock_make (start_port);if (sd <0 )return -errno; *sfd = sd;
@@ -1022,11 +1022,11 @@ static int get_vsock(const char *port)unsigned int cid;int sd; - sd =trace_vsock_make (atoi (port)); + sd =tracecmd_vsock_make (atoi (port));if (sd <0 )return sd; - cid =trace_vsock_local_cid (); + cid =tracecmd_vsock_local_cid ();if (cid >=0 )printf ("listening on @%u:%s\n" , cid, port);
tracecmd/trace-profile.c +29 -29
195 lines not on this page · raw message
tracecmd/trace-read.c +5 -5
@@ -609,7 +609,7 @@ static void init_wakeup(struct tracecmd_input *handle) pevent =tracecmd_get_tep (handle); -trace_hash_init (&wakeup_hash,WAKEUP_HASH_SIZE ); +tracecmd_hash_init (&wakeup_hash,WAKEUP_HASH_SIZE ); event =tep_find_event_by_name (pevent,"sched" ,"sched_wakeup" );if (!event)
@@ -657,7 +657,7 @@ static void add_wakeup(unsigned int val, unsigned long long start)struct wakeup_info *info;struct trace_hash_item *item; - item =trace_hash_find (&wakeup_hash, key,NULL ,NULL ); + item =tracecmd_hash_find (&wakeup_hash, key,NULL ,NULL );if (item) { info = container_of(item, struct wakeup_info, hash);/* Hmm, double wakeup? */
@@ -670,7 +670,7 @@ static void add_wakeup(unsigned int val, unsigned long long start)die ("Failed to allocate wakeup info" ); info->hash.key = key; info->start = start; -trace_hash_add (&wakeup_hash, &info->hash); +tracecmd_hash_add (&wakeup_hash, &info->hash); }static unsigned long long max_lat =0 ;
@@ -690,7 +690,7 @@ static void add_sched(unsigned int val, unsigned long long end, int rt)struct wakeup_info *info;unsigned long long cal; - item =trace_hash_find (&wakeup_hash, key,NULL ,NULL ); + item =tracecmd_hash_find (&wakeup_hash, key,NULL ,NULL );if (!item)return ;
@@ -817,7 +817,7 @@ static void finish_wakeup(void) } } -trace_hash_free (&wakeup_hash); +tracecmd_hash_free (&wakeup_hash); }void trace_show_data (struct tracecmd_input *handle,struct tep_record *record)
tracecmd/trace-record.c +14 -14
@@ -3438,7 +3438,7 @@ static int connect_port(const char *host, unsigned int port, enum port_type typeint sfd;if (type ==USE_VSOCK ) -return trace_vsock_open (atoi (host), port); +return tracecmd_vsock_open (atoi (host), port); results =do_getaddrinfo (host, port, type);
@@ -3579,14 +3579,14 @@ create_recorder_instance(struct buffer_instance *instance, const char *file, int fd =connect_addr (result);freeaddrinfo (result); }else - fd =trace_vsock_open (instance->cid, instance->client_ports[cpu]); + fd =tracecmd_vsock_open (instance->cid, instance->client_ports[cpu]);if (fd <0 )die ("Failed to connect to agent" ); flags = recorder_flags;if (instance->use_fifos) flags |=TRACECMD_RECORD_NOBRASS ; -else if (!trace_vsock_can_splice_read ()) +else if (!tracecmd_vsock_can_splice_read ()) flags |=TRACECMD_RECORD_NOSPLICE ;return tracecmd_create_recorder_virt (file, cpu, flags, fd, max_kb); }
@@ -3842,7 +3842,7 @@ static int connect_vsock(char *vhost)if (!port)die ("vsocket must have format of 'CID:PORT'" ); - sd =trace_vsock_open (atoi (cid),atoi (port)); + sd =tracecmd_vsock_open (atoi (cid),atoi (port));return sd; }
@@ -4102,7 +4102,7 @@ static int host_tsync(struct common_record_context *ctx, instance->port_type); }else { guest_id = instance->cid; - fd =trace_vsock_open (instance->cid, tsync_port); + fd =tracecmd_vsock_open (instance->cid, tsync_port); }if (is_proxy (instance)) {
@@ -4148,7 +4148,7 @@ static void connect_to_agent(struct common_record_context *ctx, role =TRACECMD_TIME_SYNC_ROLE_GUEST ; else role =TRACECMD_TIME_SYNC_ROLE_HOST ; - sd =trace_vsock_open (instance->cid, instance->port); + sd =tracecmd_vsock_open (instance->cid, instance->port);if (sd <0 )die ("Failed to connect to vsocket @%u:%u" , instance->cid, instance->port);
@@ -4189,7 +4189,7 @@ static void connect_to_agent(struct common_record_context *ctx,if (ret <0 )die ("Failed to receive trace response %d" , ret);if (tsync_protos_reply && tsync_protos_reply[0 ]) { -if (tsync_proto_is_supported (tsync_protos_reply)) { +if (tracecmd_tsync_proto_is_supported (tsync_protos_reply)) {printf ("Negotiated %s time sync protocol with guest %s\n" , tsync_protos_reply, instance->name);
@@ -6322,17 +6322,17 @@ static int get_tsc_nsec(int *shift, int *mult) goto out; supported =-1 ; -if (trace_perf_init (&perf,1 ,0 ,getpid ())) +if (tracecmd_perf_init (&perf,1 ,0 ,getpid ()))return -1 ; -if (trace_perf_open (&perf)) +if (tracecmd_perf_open (&perf))return -1 ; cpu_shift = perf.mmap->time_shift; cpu_mult = perf.mmap->time_mult;for (i =1 ; i < cpus; i++) { -trace_perf_close (&perf); -if (trace_perf_init (&perf,1 , i,getpid ())) +tracecmd_perf_close (&perf); +if (tracecmd_perf_init (&perf,1 , i,getpid ()))break ; -if (trace_perf_open (&perf)) +if (tracecmd_perf_open (&perf))break ;if (perf.mmap->time_shift != cpu_shift || perf.mmap->time_mult != cpu_mult) {
@@ -6341,7 +6341,7 @@ static int get_tsc_nsec(int *shift, int *mult)break ; } } -trace_perf_close (&perf); +tracecmd_perf_close (&perf);if (i < cpus)return -1 ;
@@ -7104,7 +7104,7 @@ static void set_tsync_params(struct common_record_context *ctx)* force using the x86-tsc clock for this host-guest tracing session * and store TSC to nsec multiplier and shift. */ -if (tsync_proto_is_supported ("kvm" ) && +if (tracecmd_tsync_proto_is_supported ("kvm" ) &&trace_have_guests_pid () &&clock_is_supported (NULL ,TSC_CLOCK ) && !get_tsc_nsec (&shift, &mult) && mult) {
tracecmd/trace-vm.c +1 -1
@@ -325,7 +325,7 @@ static void find_pid_by_cid(struct trace_guest *guest)int fd; instance =start_trace_connect (); - fd =trace_vsock_open (guest->cid,-1 ); + fd =tracecmd_vsock_open (guest->cid,-1 ); guest->pid =stop_trace_connect (instance);/* Just in case! */ if (fd >=0 )
tracecmd/trace-vsock.c +7 -7
@@ -6,7 +6,7 @@#include "trace-cmd-private.h" -int __hidden trace_vsock_open(unsigned int cid, unsigned int port) +int __hidden tracecmd_vsock_open(unsigned int cid, unsigned int port) {struct sockaddr_vm addr = { .svm_family =AF_VSOCK ,
@@ -27,7 +27,7 @@ int __hidden trace_vsock_open(unsigned int cid, unsigned int port)return sd; } -int __hidden trace_vsock_make(unsigned int port) +int __hidden tracecmd_vsock_make(unsigned int port) {struct sockaddr_vm addr = { .svm_family =AF_VSOCK ,
@@ -55,12 +55,12 @@ error:return -errno; } -int __hidden trace_vsock_make_any(void) +int __hidden tracecmd_vsock_make_any(void) { -return trace_vsock_make (VMADDR_PORT_ANY ); +return tracecmd_vsock_make (VMADDR_PORT_ANY ); } -int __hidden trace_vsock_get_port(int sd, unsigned int *port) +int __hidden tracecmd_vsock_get_port(int sd, unsigned int *port) {struct sockaddr_vm addr;socklen_t addr_len =sizeof (addr);
@@ -155,7 +155,7 @@ out_close_sd:return ret; } -bool __hidden trace_vsock_can_splice_read(void) +bool __hidden tracecmd_vsock_can_splice_read(void) {static bool initialized, res;
@@ -169,7 +169,7 @@ bool __hidden trace_vsock_can_splice_read(void)#define GET_LOCAL_CID 0x7b9 -int __hidden trace_vsock_local_cid(void) +int __hidden tracecmd_vsock_local_cid(void) {int cid;int fd;
base-commit: bbea061f69dab3a55dc5c077bf89a02f8f08cb6a
Signature · 1 line
2.34.1
Quoted 23 lines · On Mon, 28 Oct 2024 12:22:47 +0000 Metin Kaya <[email protected]> wrote:
Building trace-cmd statically fails because of duplicated symbols for
strstrip()function which is also implemented in libtracefs. The__hiddenattribute does not resolve these conflicts for static builds due to the lack of namespacing support in C. Refer to the associated Bugzilla page [1] for further details.Although only
strstrip()breaks the static build as of now, we should fix the underlying issue comprehensively across the libtraceevent, libtracefs, and trace-cmd packages. The recommendation on [1] is prepending package name (e.g., "tracecmd_") to private functions (tagged with__hiddenattribute).Thus:
1. Retain private functions which already start with "tracecmd_".
2. If a private function starts with "trace_", then just change its prefix to "tracecmd_".
3. If prepending "tracecmd_" prefix to a private function's name clashes with an existing one, rename one of the functions per its context (e.g., renametrace_load_plugins()totracecmd_load_plugins_from_handle()andtrace_append_options()totracecmd_append_options_to_file()).
4. Prepend "tracecmd_" prefix to all remaining "__hidden" functions.
Quoted 2 lines
Future
__hiddenfunctions should follow this prefixing schemed to avoid new naming conflicts.
I'm not against the change to make the hidden functions with a unique name, but I rather come up with something other than "tracecmd_". That prefix was to be used for functions that will eventually become public.
Would "tcmd_" work?
Same goes for the other libraries. The "tracefs_" is for functions that should be exported. Perhaps rename it to "tfs_"?
As for libtraceevent, it doesn't need a separate prefix for local variables compared to exported ones, but that prefix is "tep_" and not "traceevent_".
-- Steve
Quoted 29 lines · Steven Rostedt
Quoted 23 lines · On Mon, 28 Oct 2024 12:22:47 +0000 Metin Kaya <[email protected]> wrote:
Building trace-cmd statically fails because of duplicated symbols for
strstrip()function which is also implemented in libtracefs. The__hiddenattribute does not resolve these conflicts for static builds due to the lack of namespacing support in C. Refer to the associated Bugzilla page [1] for further details.Although only
strstrip()breaks the static build as of now, we should fix the underlying issue comprehensively across the libtraceevent, libtracefs, and trace-cmd packages. The recommendation on [1] is prepending package name (e.g., "tracecmd_") to private functions (tagged with__hiddenattribute).Thus:
1. Retain private functions which already start with "tracecmd_".
2. If a private function starts with "trace_", then just change its prefix to "tracecmd_".
3. If prepending "tracecmd_" prefix to a private function's name clashes with an existing one, rename one of the functions per its context (e.g., renametrace_load_plugins()totracecmd_load_plugins_from_handle()andtrace_append_options()totracecmd_append_options_to_file()).
4. Prepend "tracecmd_" prefix to all remaining "__hidden" functions.Quoted 2 lines
Future
__hiddenfunctions should follow this prefixing schemed to avoid new naming conflicts.
Quoted 8 lines
I'm not against the change to make the hidden functions with a unique name, but I rather come up with something other than "
tracecmd_". That prefix was to be used for functions that will eventually become public.Would "
tcmd_" work?Same goes for the other libraries. The "
tracefs_" is for functions that should be exported. Perhaps rename it to "tfs_"?
Hi Steve,
Ah, you are right. Those prefixes conflict with public ones. Perhaps I misread the discussion on Bugzilla page. I've no objection to using "tcmd_", "tfs_" and "tep_" prefixes. Will update all three patches accordingly.
Quoted 4 lines
As for libtraceevent, it doesn't need a separate prefix for local variables compared to exported ones, but that prefix is "
tep_" and not "traceevent_".
I believe I did not rename any variables in the libtraceevent patch [1]. However, I made the following changes in the libtracefs patch [2]:
-extern const struct tep_format_field common_stacktrace; +extern const struct tep_format_field tracefs_common_stacktrace;
-extern pthread_mutex_t toplevel_lock;
+extern pthread_mutex_t tracefs_toplevel_lock;
Do you recommend keeping them as is or using "tfs_" prefix?
[1] https://lore.kernel.org/linux-trace-devel/[email protected]
[2] https://lore.kernel.org/linux-trace-devel/[email protected]
Thanks,
Quoted 13 lines · On Thu, 31 Oct 2024 09:48:32 +0000 Metin Kaya <[email protected]> wrote:
Quoted 3 lines
As for libtraceevent, it doesn't need a separate prefix for local variables compared to exported ones, but that prefix is "
tep_" and not "traceevent_".I believe I did not rename any variables in the libtraceevent patch [1]. However, I made the following changes in the libtracefs patch [2]:
(quoted diff) +2
-2-extern const struct tep_format_field common_stacktrace; +extern const struct tep_format_field tracefs_common_stacktrace; -extern pthread_mutex_t toplevel_lock; +extern pthread_mutex_t tracefs_toplevel_lock;
Quoted 1 line
Do you recommend keeping them as is or using "
tfs_" prefix?
Might as well make the change. At least that tells us it's exposed across files in the library.
-- Steve