aboutsummaryrefslogtreecommitdiff
path: root/src/library.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/library.js')
-rw-r--r--src/library.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js
index faa86c68..75010afb 100644
--- a/src/library.js
+++ b/src/library.js
@@ -5372,6 +5372,21 @@ LibraryManager.library = {
},
__01getrlimit64_: 'getrlimit',
+ // TODO: Implement for real. We just do time used, and no useful data
+ __rusage_struct_layout: Runtime.generateStructInfo(null, '%struct.rusage'),
+ getrusage__deps: ['__rusage_struct_layout'],
+ getrusage: function(resource, rlp) {
+ // %struct.timeval = type { i32, i32 }
+ var timeval = Runtime.calculateStructAlignment({ fields: ['i32', 'i32'] });
+
+ // int getrusage(int resource, struct rusage *rlp);
+ {{{ makeSetValue('rlp', '___rusage_struct_layout.ru_utime+timeval[0]', '1', 'i32') }}}
+ {{{ makeSetValue('rlp', '___rusage_struct_layout.ru_utime+timeval[1]', '2', 'i32') }}}
+ {{{ makeSetValue('rlp', '___rusage_struct_layout.ru_stime+timeval[0]', '3', 'i32') }}}
+ {{{ makeSetValue('rlp', '___rusage_struct_layout.ru_stime+timeval[1]', '4', 'i32') }}}
+ return 0;
+ },
+
// ==========================================================================
// pthread.h (stubs for mutexes only - no thread support yet!)
// ==========================================================================
@@ -5417,6 +5432,36 @@ LibraryManager.library = {
EMSCRIPTEN_COMMENT__inline: function(param) {
param = stripCorrections(param);
return '// ' + Variables.globals[param].value.text.replace('\\00', '') + ' ';
+ },
+
+ $Profiling: {
+ max_: 0,
+ times: null,
+ invalid: 0,
+ dump: function() {
+ if (Profiling.invalid) {
+ print('Invalid # of calls to Profiling begin and end!');
+ return;
+ }
+ print('Profiling data:')
+ for (var i = 0; i < Profiling.max_; i++) {
+ print('Block ' + i + ': ' + Profiling.times[i]);
+ }
+ }
+ },
+ EMSCRIPTEN_PROFILE_INIT__deps: ['$Profiling'],
+ EMSCRIPTEN_PROFILE_INIT: function(max_) {
+ Profiling.max_ = max_;
+ Profiling.times = new Array(max_);
+ for (var i = 0; i < max_; i++) Profiling.times[i] = 0;
+ },
+ EMSCRIPTEN_PROFILE_BEGIN__inline: function(id) {
+ return 'Profiling.times[' + id + '] -= Date.now();'
+ + 'Profiling.invalid++;'
+ },
+ EMSCRIPTEN_PROFILE_END__inline: function(id) {
+ return 'Profiling.times[' + id + '] += Date.now();'
+ + 'Profiling.invalid--;'
}
};