4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2008-2009, Intel Corporation.
23 * All Rights Reserved.
29 #include <sys/types.h>
38 * We define our own conversions in order to avoid compiler warnings.
40 #define LT_INT_TO_POINTER(a) ((void *)(unsigned long)(a))
42 #define TITLE "LatencyTOP for OpenSolaris, version 1.0"
43 #define COPYRIGHT "Copyright (c) 2008-2009, Intel Corporation."
44 #define DEFAULT_KLOG_FILE "/var/log/latencytop.log"
46 #define INVALID_PID (~0)
47 #define INVALID_TID (~0)
48 #define PID_SYS_GLOBAL INVALID_PID
49 #define INVALID_CAUSE 0
50 #define HIGHER_PRIORITY(a, b) ((a) > (b))
54 * LatencyTOP configuration is embedded in the binary.
55 * Array will be generated by elfwrap.
57 extern char latencytop_d_start
;
58 extern char latencytop_d_end
;
59 extern char latencytop_trans_start
;
60 extern char latencytop_trans_end
;
63 * LatencyTOP configuration is provided externally by user.
65 #define DEFAULT_CONFIG_NAME "./latencytop.trans"
66 #define DEFAULT_D_SCRIPT_NAME "./latencytop.d"
75 #define LT_KLOG_LEVEL_NONE 0 /* Log nothing */
76 #define LT_KLOG_LEVEL_UNMAPPED 1 /* Log only stacks not mapped */
77 #define LT_KLOG_LEVEL_MAPPED 2 /* Log only stacks mapped */
78 #define LT_KLOG_LEVEL_ALL 3 /* Log all stacks, mapped or not */
81 LT_LEVEL_GLOBAL
, /* System wide statistics */
82 LT_LEVEL_PROCESS
, /* Per-process statistics */
83 LT_LEVEL_THREAD
, /* Per-thread statistics */
99 LT_LIST_CAUSE
, /* List latency by causes (default) */
100 LT_LIST_SPECIALS
, /* List only "special" causes */
101 LT_LIST_SOBJ
/* List synchronization objects */
105 * Data structure which contains statistics.
114 * Data structure that stores statistics along with the name.
121 const char *lt_se_string
;
122 lt_stat_data_t lt_se_data
;
131 } lt_se_tsdata
; /* type specific data */
135 int lt_cfg_enable_filter
;
136 int lt_cfg_trace_sched
;
137 int lt_cfg_trace_syncobj
;
138 int lt_cfg_low_overhead_mode
;
139 int lt_cfg_snap_interval
;
140 char *lt_cfg_config_name
;
141 unsigned int lt_cfg_trace_pid
;
142 unsigned int lt_cfg_trace_pgid
;
145 extern lt_config_t g_config
; /* The global settings */
148 * Causes can be disabled through the configuration file.
149 * When disabled, though D script will continue to capture causes, they will
150 * not be counted by LatencyTOP.
152 #define CAUSE_FLAG_DISABLED 1
154 * This flag will not show and count causes as part of summary in
157 #define CAUSE_FLAG_HIDE_IN_SUMMARY 2
159 * This is generated from D script (named cause), and is "special".
161 #define CAUSE_FLAG_SPECIAL 4
162 #define CAUSE_ALL_FLAGS 0xffffffff
164 extern boolean_t lt_drop_detected
;
167 * These functions collect statistics using DTrace.
169 extern int lt_dtrace_init(void);
170 extern int lt_dtrace_work(int);
171 extern int lt_dtrace_collect(void);
172 extern int lt_dtrace_deinit(void);
175 * These functions maintain configuration, e.g. symbol to cause mapping.
177 extern int lt_table_init(void);
178 extern int lt_table_cause_from_stack(const char *, int *, int *);
179 extern const char *lt_table_get_cause_name(int);
180 extern int lt_table_get_cause_flag(int, int);
181 extern int lt_table_cause_from_name(char *, int, int);
182 extern int lt_table_append_trans(FILE *fp
);
183 extern void lt_table_deinit(void);
186 * These functions update statistic of all causes of latency, collected
189 extern void lt_stat_update(pid_t
, id_t
, char *, char *, unsigned int,
190 lt_stat_type_t
, uint64_t);
191 extern void lt_stat_update_cause(pid_t
, id_t
, int, lt_stat_type_t
, uint64_t);
192 extern void lt_stat_update_sobj(pid_t
, id_t
, int, unsigned long long,
193 lt_stat_type_t
, uint64_t);
194 extern void lt_stat_clear_all(void);
195 extern void lt_stat_free_all(void);
198 * These functions produce lists for display panes.
199 * Note: after a call to lt_stat_update_*, the old lists will become invalid.
201 extern void *lt_stat_list_create(lt_list_type_t
, lt_stat_level_t
,
202 pid_t
, id_t
, int, lt_sort_t
);
203 extern int lt_stat_list_has_item(void *, int);
204 extern const char *lt_stat_list_get_reason(void *, int);
205 extern uint64_t lt_stat_list_get_max(void *, int);
206 extern uint64_t lt_stat_list_get_sum(void *, int);
207 extern uint64_t lt_stat_list_get_count(void *, int);
208 extern uint64_t lt_stat_list_get_gtotal(void *);
209 extern void lt_stat_list_free(void *);
212 * These functions produce the process list and the thread list.
214 extern int lt_stat_proc_list_create(pid_t
**, id_t
**);
215 extern void lt_stat_proc_list_free(pid_t
*, id_t
*);
216 extern const char *lt_stat_proc_get_name(pid_t
);
217 extern int lt_stat_proc_get_nthreads(pid_t
);
220 * These functions use ncurses to create console-based display.
222 extern void lt_display_init(void);
223 extern int lt_display_loop(int);
224 extern void lt_display_error(const char *, ...);
225 extern void lt_display_deinit(void);
228 * Write statistics to log file - useful for debugging and offline analysis.
230 extern void lt_klog_init(void);
231 extern void lt_klog_deinit(void);
232 extern int lt_klog_set_log_file(const char *);
233 extern int lt_klog_set_log_level(int);
234 extern void lt_klog_write(void);
235 extern void lt_klog_log(int, pid_t
, char *, lt_stat_type_t
,
241 extern uint64_t lt_millisecond(void);
242 extern void *lt_malloc(size_t);
243 extern void *lt_zalloc(size_t);
244 extern char *lt_strdup(const char *);
245 extern void lt_check_null(void *);
246 extern void lt_time_str(char *);
247 extern char *lt_get_proc_field(pid_t
, lt_field_t
);
248 extern void lt_update_stat_value(lt_stat_data_t
*, lt_stat_type_t
, uint64_t);
249 extern int lt_sort_by_total_desc(lt_stat_entry_t
*, lt_stat_entry_t
*);
250 extern int lt_sort_by_max_desc(lt_stat_entry_t
*, lt_stat_entry_t
*);
251 extern int lt_sort_by_count_desc(lt_stat_entry_t
*, lt_stat_entry_t
*);
252 extern int lt_sort_by_avg_desc(lt_stat_entry_t
*, lt_stat_entry_t
*);
253 extern void lt_gpipe_init(void);
254 extern void lt_gpipe_deinit(void);
255 extern void lt_gpipe_break(const char *);
256 extern int lt_gpipe_readfd(void);
257 extern int lt_file_exist(const char *);
263 #endif /* _LATENCYTOP_H */