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 * Without this lint seems to be confused by glib header file.
42 #define g_assert(x) ((void)(x))
48 * We define our own conversions in order to avoid compiler warnings.
50 #define LT_INT_TO_POINTER(a) ((void *)(unsigned long)(a))
52 #define TITLE "LatencyTOP for OpenSolaris, version 1.0"
53 #define COPYRIGHT "Copyright (c) 2008-2009, Intel Corporation."
54 #define DEFAULT_KLOG_FILE "/var/log/latencytop.log"
56 #define INVALID_PID (~0)
57 #define INVALID_TID (~0)
58 #define PID_SYS_GLOBAL INVALID_PID
59 #define INVALID_CAUSE 0
60 #define HIGHER_PRIORITY(a, b) ((a) > (b))
64 * LatencyTOP configuration is embedded in the binary.
65 * Array will be generated by elfwrap.
67 extern char latencytop_d_start
;
68 extern char latencytop_d_end
;
69 extern char latencytop_trans_start
;
70 extern char latencytop_trans_end
;
73 * LatencyTOP configuration is provided externally by user.
75 #define DEFAULT_CONFIG_NAME "./latencytop.trans"
76 #define DEFAULT_D_SCRIPT_NAME "./latencytop.d"
85 #define LT_KLOG_LEVEL_NONE 0 /* Log nothing */
86 #define LT_KLOG_LEVEL_UNMAPPED 1 /* Log only stacks not mapped */
87 #define LT_KLOG_LEVEL_MAPPED 2 /* Log only stacks mapped */
88 #define LT_KLOG_LEVEL_ALL 3 /* Log all stacks, mapped or not */
91 LT_LEVEL_GLOBAL
, /* System wide statistics */
92 LT_LEVEL_PROCESS
, /* Per-process statistics */
93 LT_LEVEL_THREAD
, /* Per-thread statistics */
109 LT_LIST_CAUSE
, /* List latency by causes (default) */
110 LT_LIST_SPECIALS
, /* List only "special" causes */
111 LT_LIST_SOBJ
/* List synchronization objects */
115 * Data structure which contains statistics.
124 * Data structure that stores statistics along with the name.
131 const char *lt_se_string
;
132 lt_stat_data_t lt_se_data
;
141 } lt_se_tsdata
; /* type specific data */
145 int lt_cfg_enable_filter
;
146 int lt_cfg_trace_sched
;
147 int lt_cfg_trace_syncobj
;
148 int lt_cfg_low_overhead_mode
;
149 int lt_cfg_snap_interval
;
150 char *lt_cfg_config_name
;
151 unsigned int lt_cfg_trace_pid
;
152 unsigned int lt_cfg_trace_pgid
;
155 extern lt_config_t g_config
; /* The global settings */
158 * Causes can be disabled through the configuration file.
159 * When disabled, though D script will continue to capture causes, they will
160 * not be counted by LatencyTOP.
162 #define CAUSE_FLAG_DISABLED 1
164 * This flag will not show and count causes as part of summary in
167 #define CAUSE_FLAG_HIDE_IN_SUMMARY 2
169 * This is generated from D script (named cause), and is "special".
171 #define CAUSE_FLAG_SPECIAL 4
172 #define CAUSE_ALL_FLAGS 0xffffffff
174 extern boolean_t lt_drop_detected
;
177 * These functions collect statistics using DTrace.
179 extern int lt_dtrace_init(void);
180 extern int lt_dtrace_work(int);
181 extern int lt_dtrace_collect(void);
182 extern int lt_dtrace_deinit(void);
185 * These functions maintain configuration, e.g. symbol to cause mapping.
187 extern int lt_table_init(void);
188 extern int lt_table_cause_from_stack(const char *, int *, int *);
189 extern const char *lt_table_get_cause_name(int);
190 extern int lt_table_get_cause_flag(int, int);
191 extern int lt_table_cause_from_name(char *, int, int);
192 extern int lt_table_append_trans(FILE *fp
);
193 extern void lt_table_deinit(void);
196 * These functions update statistic of all causes of latency, collected
199 extern void lt_stat_update(pid_t
, id_t
, char *, char *, unsigned int,
200 lt_stat_type_t
, uint64_t);
201 extern void lt_stat_update_cause(pid_t
, id_t
, int, lt_stat_type_t
, uint64_t);
202 extern void lt_stat_update_sobj(pid_t
, id_t
, int, unsigned long long,
203 lt_stat_type_t
, uint64_t);
204 extern void lt_stat_clear_all(void);
205 extern void lt_stat_free_all(void);
208 * These functions produce lists for display panes.
209 * Note: after a call to lt_stat_update_*, the old lists will become invalid.
211 extern void *lt_stat_list_create(lt_list_type_t
, lt_stat_level_t
,
212 pid_t
, id_t
, int, lt_sort_t
);
213 extern int lt_stat_list_has_item(void *, int);
214 extern const char *lt_stat_list_get_reason(void *, int);
215 extern uint64_t lt_stat_list_get_max(void *, int);
216 extern uint64_t lt_stat_list_get_sum(void *, int);
217 extern uint64_t lt_stat_list_get_count(void *, int);
218 extern uint64_t lt_stat_list_get_gtotal(void *);
219 extern void lt_stat_list_free(void *);
222 * These functions produce the process list and the thread list.
224 extern int lt_stat_proc_list_create(pid_t
**, id_t
**);
225 extern void lt_stat_proc_list_free(pid_t
*, id_t
*);
226 extern const char *lt_stat_proc_get_name(pid_t
);
227 extern int lt_stat_proc_get_nthreads(pid_t
);
230 * These functions use ncurses to create console-based display.
232 extern void lt_display_init(void);
233 extern int lt_display_loop(int);
234 extern void lt_display_error(const char *, ...);
235 extern void lt_display_deinit(void);
238 * Write statistics to log file - useful for debugging and offline analysis.
240 extern void lt_klog_init(void);
241 extern void lt_klog_deinit(void);
242 extern int lt_klog_set_log_file(const char *);
243 extern int lt_klog_set_log_level(int);
244 extern void lt_klog_write(void);
245 extern void lt_klog_log(int, pid_t
, char *, lt_stat_type_t
,
251 extern uint64_t lt_millisecond(void);
252 extern void *lt_malloc(size_t);
253 extern void *lt_zalloc(size_t);
254 extern char *lt_strdup(const char *);
255 extern void lt_check_null(void *);
256 extern void lt_time_str(char *, int);
257 extern char *lt_get_proc_field(pid_t
, lt_field_t
);
258 extern void lt_update_stat_value(lt_stat_data_t
*, lt_stat_type_t
, uint64_t);
259 extern int lt_sort_by_total_desc(lt_stat_entry_t
*, lt_stat_entry_t
*);
260 extern int lt_sort_by_max_desc(lt_stat_entry_t
*, lt_stat_entry_t
*);
261 extern int lt_sort_by_count_desc(lt_stat_entry_t
*, lt_stat_entry_t
*);
262 extern int lt_sort_by_avg_desc(lt_stat_entry_t
*, lt_stat_entry_t
*);
263 extern void lt_gpipe_init(void);
264 extern void lt_gpipe_deinit(void);
265 extern void lt_gpipe_break(const char *);
266 extern int lt_gpipe_readfd(void);
267 extern int lt_file_exist(const char *);
273 #endif /* _LATENCYTOP_H */