Unison Help
- Unison Kernel
- Pthreads
- pthread_create()
- pthread_exit()
- pthread_self()
- pthread_equal()
- pthread_join()
- pthread_detach()
- pthread_setschedparam()
- pthread_getschedparam()
- pthread_attr_init()
- pthread_attr_destroy()
- pthread_attr_setstackaddr()
- pthread_attr_getstackaddr()
- pthread_attr_setstacksize()
- pthread_attr_getstacksize()
- pthread_attr_setschedparam()
- pthread_attr_getschedparam()
- pthread_attr_setdetachstate()
- pthread_attr_getdetachstate()
- pthread_stackinfo()
- pthread_setprio()
- pthread_getprio()
- sched_get_priority_max()
- sched_get_priority_min()
- sched_yield()
- Pthread Cancellation
- Mutex
- Semaphores
- Message Queues
- Conditional Variables
- Barriers
- Timers
- Clocks
- Memory Allocation
- Rendezvous
- Interrupts
- Directory Services
- Miscellaneous
- Pthreads
- Unison I/O Library
- Unison STDIO Library
- STDIO Library Calls
- clearerr()
- dprintf()
- fclose()
- fdopen()
- feof()
- ferror()
- fileno()
- fflush()
- fgetc()
- fgetpos()
- fgets()
- fopen()
- fprintf()
- fputc()
- fputs()
- fread()
- freopen()
- fscanf()
- fseek()
- fseeko()
- fsetpos()
- ftell()
- ftello()
- fwrite()
- getc()
- getc_unlocked()
- getchar()
- getchar_unlocked()
- getdelim()
- getline()
- gets()
- get_stderr_ptr()
- get_stdin_ptr()
- get_stdout_ptr()
- noperprintf()
- perprintf()
- perror()
- posix_compat()
- printf()
- putc()
- putc_unlocked()
- putchar()
- putchar_unlocked()
- puts()
- remove()
- rewind()
- scanf()
- setbuf()
- setvbuf()
- snprintf()
- sprintf()
- sscanf()
- stderr_init()
- stderr_close()
- stdin_init()
- stdin_close()
- stdout_init()
- stdout_close()
- vdprintf()
- vscanf()
- vsscanf()
- vfscanf()
- vprintf()
- vsnprintf()
- vsprintf()
- vfprintf()
- ungetc()
- Do-nothing Stubs
- STDIO Library Calls
- Unison LIBC Library
- Unison I/O Servers
- Graphics, Camera, Video, Audio
- Network Protocols
- TCP and UDP Server - tcpd
- DHCP Client Service - dhcp client
- DHCP Server - dhcpd
- Telnet Server - telnetd
- Tiny FTP Server - tftpd
- Point to Point - pppd
- Network Translation - NAT with PAT
- Firewall
- Tiny HTTP Server - thttpd
- Tiny HTTP Server with TLS
- POP3 Server
- Simple Mail Transfer Protocol Services (SMTP)
- Bootp Protocol
- File Transfer Protocol Server (FTP)
- File Transfer Client Services
- RPC / XDR
- DNS Client
- HTTP/HTTPS Client
- REST Client
- AutoIP Service - autoip client
- mDNS server - mdnsd
- SNTP Client
- SNMP Agent - Snmpd server
- SSL/TLS library
- SSH server
- IP security
- Power Control
- Serial I/O
- System Services
- Universal Serial Bus (USB)
- Wireless
- Remedy Tools for Unison
1.14.12.thread_utilization_stop() #
NAME
thread_numb(), thread_util_t, threads_utilization_start(), threads_utilization_stop()
SYNOPSIS
#include <sys/sys.h>
int thread_numb();
void thread_utilization_start(thread_util_t thread_table[]);
void thread_utilization_stop();
DESCRIPTION
The function thread_numb gets the current number of threads in the system, returning an int. With this information, enough space may be allocated on a thread by thread basis to record scheduling results.
The thread_utilization_start function starts the utilization measurement and the thread_utilization_stop function indicates the end of the utilization measurements.
At the end of the measurements, the thread_util_t structures allocated for the thread table contain the following information for each thread:
- uint thread_id
- char *thread_name
- u_long util
Using the two first parameters, the thread information can be found. Using the util parameter the utilization can be found. The util parameter contains the % of the processor utilized by the thread with the upper sixteen bits providing the % and the lower 16 bits providing one extra byte of resolution after the decimal point. For example, 12.5% has the 12 encoded in the upper 16 bits and the 5 encoded in the lower 16 bits. See the Example for more details.
RETURN VALUES
thread_numb returns the number of threads in the system including the idle thread.
ERRORS
The above calls cannot fail and return no error codes.
EXAMPLES
#include < sys.h > thread_util_t *threads_table = NULL; int utilization_begin(void) { int threads_count; threads_count = threads_numb(); xprintf("found %d threads\n", threads_count); // Create table for utilization count threads_table = malloc(sizeof(thread_util_t) * threads_count); //Start utilization count threads_utilization_start(threads_table, threads_count); return threads_count; }
void utilization_end(int threads_count) { int i; threads_utilization_stop(); for (i=0; i < threads_count; i++) { xprintf("'%s' - %d.%d %%\n", threads_table[i].thread_name, (int)(threads_table[i].util >> 16), (int)(threads_table[i].util & 0xffff)); } free(threads_table); }
NOTES
The utilization measurements do not include the time spent in interrupt service routines. If your system spends a great deal of time in interrupt processing, these results are no less accurate in terms of thread processing time, but they reflect only the time spent for threads. For example, if interrupts flood the system and only one thread runs, it will indicate 100% of the utlization for the one thread. It will not tell you that there is significant interrupt processing that has not been measured.
The utilization measurements rely upon periodic timer measurements. It is rare but possible to end up with synchronization between the clock and the thread which distorts the utilization time measurement. In this case, there are modifications that can eliminate this problem. Please contact RoweBots for help.
SEE ALSO
For a tutorial with discussion and examples, see the Unison or DSPnano Programmer’s Guides and the demo directory.