Lolly 1.4.27
Loading...
Searching...
No Matches
Classes | Functions | Variables
lolly::system Namespace Reference

Classes

class  args
 
struct  shared_lib_rep
 

Functions

shared_lib load_shared_library (string name, url path)
 
 RESOURCE (shared_lib)
 
int call (string cmd)
 
int check_output (string s, string &result, bool stderr_only, int64_t timeout)
 
int check_stdout (string cmd, string &result)
 
int check_stderr (string cmd, string &result)
 
void timer_start (string task)
 
void timer_cumul (string task)
 
void timer_reset (string task)
 
void bench_print (tm_ostream &ostream, string task, uint32_t threshold)
 
static array< stringcollect (hashmap< string, uint32_t > h)
 
void bench_print (tm_ostream &ostream)
 

Variables

static hashmap< string, uint32_ttiming_level (0)
 
static hashmap< string, uint32_ttiming_nr (0)
 
static hashmap< string, uint32_ttiming_cumul (0)
 
static hashmap< string, uint32_ttiming_last (0)
 

Function Documentation

◆ load_shared_library()

shared_lib lolly::system::load_shared_library ( string name,
url path )

Definition at line 28 of file shared_lib.cpp.

28 {
29 return make (shared_lib, name, tm_new<shared_lib_rep> (name, path));
30}
The list class represents a linked list.
Definition list.hpp:48
#define make(T, s, im)
Definition resource.hpp:62

◆ RESOURCE()

lolly::system::RESOURCE ( shared_lib )

◆ call()

int lolly::system::call ( string cmd)

Definition at line 31 of file subprocess.cpp.

31 {
35
36#if defined(OS_MINGW) || defined(OS_WIN)
37 return (int) tb_process_run_cmd (cmd_c, &attr);
38#else
39 wordexp_t p;
40 int ret= wordexp (cmd_c, &p, 0);
41 if (ret != 0) {
42 return ret;
43 }
44 if (p.we_wordc == 0) {
45 wordfree (&p);
46 return EINVAL;
47 }
48 ret= (int) tb_process_run (p.we_wordv[0], (tb_char_t const**) p.we_wordv,
49 &attr);
50 wordfree (&p);
51 return ret;
52#endif
53}

◆ check_output()

int lolly::system::check_output ( string s,
string & result,
bool stderr_only,
int64_t timeout )

Definition at line 57 of file subprocess.cpp.

57 {
58 tb_long_t status= -1;
59 // init pipe files
60 tb_pipe_file_ref_t file[2]= {0};
61 if (!tb_pipe_file_init_pair (file, tb_null, 0)) {
62 return status;
63 }
64
65 // init process
66 c_string cmd_ (s);
69 if (stderr_only) {
70 attr.err.pipe= file[1];
72 }
73 else {
74 attr.out.pipe= file[1];
76 }
78 if (process) {
79 // read pipe data
80 tb_size_t read= 0;
81 // TODO: should be a config here
82 tb_byte_t data[8192]= {0};
83 tb_size_t size = sizeof (data);
84 tb_bool_t wait = tb_false;
85 while (read < size) {
86 tb_long_t real= tb_pipe_file_read (file[0], data + read, size - read);
87 if (real > 0) {
88 read+= real;
89 wait= tb_false;
90 }
91 else if (!real && !wait) {
92 tb_long_t ok = 0;
93 int retry= 25;
94 if (read > 0) {
95 retry= 2;
96 }
97 while (retry > 0 && (ok == 0)) {
99 retry= retry - 1;
100 }
101 tb_check_break (ok > 0);
102 wait= tb_true;
103 }
104 else break;
105 }
106
107 result= as_string ((tb_char_t*) data);
108
109 // wait process
110 tb_process_wait (process, &status, timeout);
111
112 // exit process
114 }
115
116 // exit pipe files
117 tb_pipe_file_exit (file[0]);
118 tb_pipe_file_exit (file[1]);
119 return status;
120}
bool read(string s, int &i, const char *test)
Definition analyze.cpp:589
string as_string(int16_t i)
Definition string.cpp:310

◆ check_stdout()

int lolly::system::check_stdout ( string cmd,
string & result )
inline

Definition at line 23 of file subprocess.hpp.

23 {
24 return check_output (cmd, result, false, 20);
25}

◆ check_stderr()

int lolly::system::check_stderr ( string cmd,
string & result )
inline

Definition at line 27 of file subprocess.hpp.

27 {
28 return check_output (cmd, result, true, 20);
29}

◆ timer_start()

void lolly::system::timer_start ( string task)

Definition at line 32 of file timer.cpp.

32 {
33 // start timer for a given type of task
34 if (timing_level[task] == 0) timing_last (task)= (uint32_t) texmacs_time ();
36}
static hashmap< string, uint32_t > timing_level(0)
static hashmap< string, uint32_t > timing_last(0)
time_t texmacs_time()
Definition tm_timer.cpp:47

◆ timer_cumul()

void lolly::system::timer_cumul ( string task)

Definition at line 39 of file timer.cpp.

39 {
40 // end timer for a given type of task, but don't reset timer
42 if (timing_level[task] == 0) {
43 uint32_t ms= ((uint32_t) texmacs_time ()) - timing_last (task);
44 timing_nr (task)++;
46 timing_last->reset (task);
47 }
48}
static hashmap< string, uint32_t > timing_cumul(0)
static hashmap< string, uint32_t > timing_nr(0)

◆ timer_reset()

void lolly::system::timer_reset ( string task)

Definition at line 51 of file timer.cpp.

51 {
52 // reset timer for a given type of task
53 timing_level->reset (task);
54 timing_nr->reset (task);
55 timing_cumul->reset (task);
56 timing_last->reset (task);
57}

◆ bench_print() [1/2]

void lolly::system::bench_print ( tm_ostream & ostream,
string task,
uint32_t threshold )

Definition at line 60 of file timer.cpp.

60 {
62 if (elapse_time < threshold) return;
63
65 ostream << "Task '" << task << "' took " << elapse_time << " ms";
66 if (nr > 1) ostream << " (" << nr << " invocations)";
67 ostream << LF;
68}
@ LF
Definition basic.hpp:287

◆ collect()

static array< string > lolly::system::collect ( hashmap< string, uint32_t > h)
static

Definition at line 71 of file timer.cpp.

71 {
74 while (it->busy ())
75 a << it->next ();
76 merge_sort (a);
77 return a;
78}
iterator< T > iterate(hashmap< T, U > h)
Generates an iterator for a container of type hashmap<T, U>.
Definition iterator.ipp:166
void merge_sort(array< T > &a)

◆ bench_print() [2/2]

void lolly::system::bench_print ( tm_ostream & ostream)

Definition at line 81 of file timer.cpp.

81 {
82 // print timings for all types of tasks
83 array<string> a= collect (timing_cumul);
84 int i, n= N (a);
85 for (i= 0; i < n; i++)
86 bench_print (ostream, a[i]);
87}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
static array< string > collect(hashmap< string, uint32_t > h)
Definition timer.cpp:71

Variable Documentation

◆ timing_level

hashmap< string, uint32_t > lolly::system::timing_level(0) ( 0 )
static

◆ timing_nr

hashmap< string, uint32_t > lolly::system::timing_nr(0) ( 0 )
static

◆ timing_cumul

hashmap< string, uint32_t > lolly::system::timing_cumul(0) ( 0 )
static

◆ timing_last

hashmap< string, uint32_t > lolly::system::timing_last(0) ( 0 )
static