2#ifndef __ASE_PLATFORM_HH__
3#define __ASE_PLATFORM_HH__
13extern const int ase_major_version;
14extern const int ase_minor_version;
15extern const int ase_micro_version;
16extern const char *
const ase_version_long;
17extern const char *
const ase_version_short;
18extern const char *
const ase_gettext_domain;
19extern const char *
const ase_sharedir;
22const char* (
_) (
const char *
string) __attribute__ ((__format_arg__ (1)));
24const char* (
_) (
const char *
string,
const char *plural, int64_t n) __attribute__ ((__format_arg__ (1), __format_arg__ (2)));
49 UNDERLINE, UNDERLINE_OFF,
51 STRIKETHROUGH, STRIKETHROUGH_OFF,
52 FG_BLACK, FG_RED, FG_GREEN, FG_YELLOW, FG_BLUE, FG_MAGENTA, FG_CYAN, FG_WHITE,
54 BG_BLACK, BG_RED, BG_GREEN, BG_YELLOW, BG_BLUE, BG_MAGENTA, BG_CYAN, BG_WHITE,
57enum class Colorize :
int8 { NEVER = 0, ALWAYS = 1, AUTO = 2 };
105 unsigned long mem_[4];
110 int post ()
noexcept;
111 int wait ()
noexcept;
123 void push (
const Value &v);
137 enum State { UNKNOWN =
'?', RUNNING =
'R', SLEEPING =
'S', DISKWAIT =
'D', STOPPED =
'T', PAGING =
'W', ZOMBIE =
'Z', DEBUG =
'X', };
149 uint64 ac_utime, ac_stime, ac_cutime, ac_cstime;
162 static bool remove (
int tid);
165 static void setup_ase (
const String &name16chars);
172void this_thread_set_name (
const String &name16chars);
173String this_thread_get_name ();
174int this_thread_getpid ();
175int this_thread_gettid ();
176int this_thread_online_cpus ();
177inline bool this_thread_is_ase () {
return TaskRegistry::is_ase(); }
180extern inline void breakpoint () ASE_ALWAYS_INLINE;
183#if defined __x86_64__ || defined __amd64__
184#define ASE_MFENCE __sync_synchronize()
185#define ASE_SFENCE __asm__ __volatile__ ("sfence" ::: "memory")
186#define ASE_LFENCE __asm__ __volatile__ ("lfence" ::: "memory")
188#define ASE_SFENCE __sync_synchronize()
189#define ASE_LFENCE __sync_synchronize()
191#define ASE_MFENCE __sync_synchronize()
194#define ASE_CFENCE __asm__ __volatile__ ("" ::: "memory")
197#if (defined __i386__ || defined __x86_64__)
198inline void breakpoint() { __asm__ __volatile__ (
"int $03"); }
199#elif defined __alpha__ && !defined __osf__
200inline void breakpoint() { __asm__ __volatile__ (
"bpt"); }
205template<
class Value>
void
206AsyncBlockingQueue<Value>::push (
const Value &v)
209 const bool notify = list_.empty();
215template<
class Value> Value
216AsyncBlockingQueue<Value>::pop ()
219 while (list_.empty())
221 Value v = list_.front();
226template<
class Value>
bool
227AsyncBlockingQueue<Value>::pending()
230 return !list_.empty();
233template<
class Value>
void
237 const bool notify = list_.empty();
239 if (notify && !list_.empty())
This is a thread-safe asyncronous queue which blocks in pop() until data is provided through push().
~Stopwatch()
Stop and print a previous msg if still running.
void stop(const String &msg="")
Stop stop watch, print msg.
double seconds() const
Provide seconds elapsed between start() and stop().
void start(const String &msg="")
Start or restart stop watch, printing msg later on.
double milliseconds() const
Provide milliseconds elapsed between start() and stop().
The task registry keeps track of runtime threads for profiling and statistical purposes.
static void add(const std::string &name, int pid, int tid=-1)
Add process/thread to registry for runtime profiling.
static void update()
Issue TaskStatus.update on all tasks in registry.
static bool remove(int tid)
Remove process/thread based on thread_id.
static List list()
Retrieve a copy to the list of all tasks in registry.
#define ASE_UNLIKELY(expr)
Compiler hint to optimize for expr evaluating to false.
#define _(...)
Retrieve the translation of a C or C++ string.
std::string color(Colors acolor, Colors c1, Colors c2, Colors c3, Colors c4, Colors c5, Colors c6)
Return ANSI code for the specified color if stdout & stderr should be colorized, see colorize_tty().
Colors
ANSI color symbols.
@ RESET
Reset combines BOLD_OFF, ITALICS_OFF, UNDERLINE_OFF, INVERSE_OFF, STRIKETHROUGH_OFF.
void configure(Colorize colorize)
Override the environment variable $ASE_COLOR (which may contain "always", "never" or "auto").
bool colorize_tty(int fd)
Check whether the tty fd should use colorization, checks ASE_COLOR if fd == -1.
const char * color_code(Colors acolor)
Return ANSI code for the specified color.
The Anklang C++ API namespace.
uint64 timestamp_resolution()
Provide resolution of timestamp_benchmark() in nano-seconds.
uint64_t uint64
A 64-bit unsigned integer, use PRI*64 in format strings.
String cpu_info()
Retrieve string identifying the runtime CPU type.
uint64 monotonic_counter()
A monotonically increasing counter, increments are atomic and visible in all threads.
String application_name()
Retrieve the localized program name intended for user display.
void breakpoint()
Cause a debugging breakpoint, for development only.
uint64 timestamp_benchmark()
Returns benchmark timestamp in nano-seconds, clock starts around program startup.
std::string executable_path()
Retrieve the path to the currently running executable.
int8_t int8
An 8-bit signed integer.
void program_alias_init(String customname)
Set program_alias to a non-localized alias other than program_argv0 if desired.
void application_name_init(String desktopname)
Set the application_name to a name other than program_alias if desired.
std::string anklang_runpath(RPath rpath, const String &segment)
Retrieve various resource paths at runtime.
bool sched_set_priority(int tid, int nicelevel)
Try to set the nice level of process or thread tid to nicelevel.
String program_cwd()
The current working directory during startup.
String anklang_home_dir(const String &subdir)
Get Anklang home dir, possibly adding subdir.
std::string cpu_arch()
Retrieve string identifying the CPU architecture.
bool sched_fast_priority(int tid)
Try to acquire low latency scheduling priority, returns true if nice level is < 0.
String program_alias()
Retrieve the program name as used for logging or debug messages.
const char * ase_version()
Provide a string containing the package version.
std::string String
Convenience alias for std::string.
std::string executable_name()
Retrieve the name part of executable_path().
uint32_t uint
Provide 'uint' as convenience type.
int sched_get_priority(int tid)
Retrieve the nice level of process or thread tid.
uint64 timestamp_startup()
Provides the timestamp_realtime() value from program startup.
uint64 timestamp_realtime()
Return the current time as uint64 in µseconds.
String timestamp_format(uint64 stamp, uint maxlength)
Convert stamp into a string, adding µsecond fractions if space permits.
const char * ase_build_id()
Provide a string containing the ASE library build id.
Acquire information about a task (process or thread) at runtime.
int priority
Priority or nice value.
String string()
Retrieve string representation of the status information.
uint64 utime
Userspace time.
uint64 ac_stamp
Accounting stamp.
uint64 cutime
Userspace time of dead children.
int processor
Rrunning processor number.
uint64 cstime
System time of dead children.
bool update()
Update status information, might return false if called too frequently.
int process_id
Process ID.
int task_id
Process ID or thread ID.
String name
Thread name (set by user).
Value type used to interface with various property types.