int main( int argc, const char* argv[] ) { int i,j,iret; double first[SIZE][SIZE]; double second[SIZE][SIZE]; double multiply[SIZE][SIZE]; double dtime; for (i = 0; i < SIZE; i++) { //rows in first for (j = 0; j < SIZE; j++) { //columns in first first[i][j]=i+j; second[j][i]=i-j; multiply[i][j]=0.0; } } profiler_init(); dtime = dclock(); profiler_start(); iret=mm(first,second,multiply); profiler_stop(); dtime = dclock()-dtime; profiler_print(); printf( "Time: %le \n", dtime); fflush( stdout ); double check=0.0; for(i=0;i<SIZE;i++){ for(j=0;j<SIZE;j++){ check+=multiply[i][j]; } } printf("check %le \n",check); return iret; }
void graphics_show_cairo_surface(void *data, Environment *environment) { if (environment -> fast_run) {return;} cairo_surface_t *surface = (cairo_surface_t *) data; cairo_set_source_surface(environment -> cairo, surface, 0, 0); profiler_start(profile_cairo); cairo_paint(environment -> cairo); profiler_end(profile_cairo); }
void mozilla_sampler_init(void* stackTop) { sInitCount++; if (stack_key_initialized) return; LOG("BEGIN mozilla_sampler_init"); if (!tlsPseudoStack.init() || !tlsTicker.init()) { LOG("Failed to init."); return; } stack_key_initialized = true; Sampler::Startup(); PseudoStack *stack = new PseudoStack(); tlsPseudoStack.set(stack); Sampler::RegisterCurrentThread("Gecko", stack, true, stackTop); // Read mode settings from MOZ_PROFILER_MODE and interval // settings from MOZ_PROFILER_INTERVAL and stack-scan threshhold // from MOZ_PROFILER_STACK_SCAN. read_profiler_env_vars(); // Allow the profiler to be started using signals OS::RegisterStartHandler(); // Initialize (but don't enable) I/O interposing sInterposeObserver = new mozilla::ProfilerIOInterposeObserver(); // We can't open pref so we use an environment variable // to know if we should trigger the profiler on startup // NOTE: Default const char *val = PR_GetEnv("MOZ_PROFILER_STARTUP"); if (!val || !*val) { return; } const char* features[] = {"js" , "leaf" #if defined(XP_WIN) || defined(XP_MACOSX) , "stackwalk" #endif #if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK) , "java" #endif }; profiler_start(PROFILE_DEFAULT_ENTRY, PROFILE_DEFAULT_INTERVAL, features, sizeof(features)/sizeof(const char*), // TODO Add env variable to select threads NULL, 0); LOG("END mozilla_sampler_init"); }
static VALUE rb_profile_block(VALUE module, VALUE usec) { rb_need_block(); profiler_start(module, usec); rb_yield(Qundef); profiler_stop(module); return Qnil; }
void graphics_present(Environment *environment) { if (environment -> fast_run) {return;} profiler_start(profile_present); void *pixels; int pitch; SDL_Rect rect; rect.x = 0; rect.y = 0; rect.w = environment -> width; rect.h = environment -> height; cairo_surface_flush(environment -> cairo_surface); SDL_UnlockTexture(environment -> base_texture); SDL_RenderCopy(environment -> renderer, environment -> base_texture, &rect, &rect); SDL_RenderPresent(environment -> renderer); SDL_LockTexture(environment -> base_texture, NULL, &pixels, &pitch); profiler_end(profile_present); }
Result send_from_buffer(void* buffer, u32 size) { Result res; profiler_start(); res = ctrnet_send(client, &size, 4, 0, &client_addr); if (res < 0) return res; res = ctrnet_send(client, buffer, size, 0, &client_addr); if (res < 0) return res; profiler_stop(); profiler_speed("sent", size); return res; }
void mozilla_sampler_init(void* stackTop) { sInitCount++; if (stack_key_initialized) return; #ifdef SPS_STANDALONE mozilla::TimeStamp::Startup(); #endif LOG("BEGIN mozilla_sampler_init"); if (!tlsPseudoStack.init() || !tlsTicker.init() || !tlsStackTop.init()) { LOG("Failed to init."); return; } bool ignore; sStartTime = mozilla::TimeStamp::ProcessCreation(ignore); stack_key_initialized = true; Sampler::Startup(); PseudoStack *stack = PseudoStack::create(); tlsPseudoStack.set(stack); bool isMainThread = true; Sampler::RegisterCurrentThread(isMainThread ? gGeckoThreadName : "Application Thread", stack, isMainThread, stackTop); // Read interval settings from MOZ_PROFILER_INTERVAL and stack-scan // threshhold from MOZ_PROFILER_STACK_SCAN. read_profiler_env_vars(); // platform specific initialization OS::Startup(); #ifndef SPS_STANDALONE set_stderr_callback(mozilla_sampler_log); #endif // We can't open pref so we use an environment variable // to know if we should trigger the profiler on startup // NOTE: Default const char *val = getenv("MOZ_PROFILER_STARTUP"); if (!val || !*val) { return; } const char* features[] = {"js" , "leaf" , "threads" #if defined(XP_WIN) || defined(XP_MACOSX) \ || (defined(SPS_ARCH_arm) && defined(linux)) \ || defined(SPS_PLAT_amd64_linux) || defined(SPS_PLAT_x86_linux) , "stackwalk" #endif #if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK) , "java" #endif }; const char* threadFilters[] = { "GeckoMain", "Compositor" }; profiler_start(PROFILE_DEFAULT_ENTRY, PROFILE_DEFAULT_INTERVAL, features, MOZ_ARRAY_LENGTH(features), threadFilters, MOZ_ARRAY_LENGTH(threadFilters)); LOG("END mozilla_sampler_init"); }
void mozilla_sampler_init(void* stackTop) { sInitCount++; if (stack_key_initialized) return; LOG("BEGIN mozilla_sampler_init"); if (!tlsPseudoStack.init() || !tlsTicker.init() || !tlsStackTop.init()) { LOG("Failed to init."); return; } stack_key_initialized = true; Sampler::Startup(); PseudoStack *stack = new PseudoStack(); tlsPseudoStack.set(stack); bool isMainThread = true; #ifdef XP_WIN // For metrofx, we'll register the main thread once it's created. isMainThread = !(XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro); #endif Sampler::RegisterCurrentThread(isMainThread ? gGeckoThreadName : "Application Thread", stack, isMainThread, stackTop); // Read mode settings from MOZ_PROFILER_MODE and interval // settings from MOZ_PROFILER_INTERVAL and stack-scan threshhold // from MOZ_PROFILER_STACK_SCAN. read_profiler_env_vars(); // Allow the profiler to be started using signals OS::RegisterStartHandler(); // Initialize I/O interposing mozilla::IOInterposer::Init(); // Initialize NSPR I/O Interposing mozilla::InitNSPRIOInterposing(); // We can't open pref so we use an environment variable // to know if we should trigger the profiler on startup // NOTE: Default const char *val = PR_GetEnv("MOZ_PROFILER_STARTUP"); if (!val || !*val) { return; } const char* features[] = {"js" , "leaf" #if defined(XP_WIN) || defined(XP_MACOSX) || (defined(SPS_ARCH_arm) && defined(linux)) , "stackwalk" #endif #if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK) , "java" #endif }; profiler_start(PROFILE_DEFAULT_ENTRY, PROFILE_DEFAULT_INTERVAL, features, sizeof(features)/sizeof(const char*), // TODO Add env variable to select threads nullptr, 0); LOG("END mozilla_sampler_init"); }
void mozilla_sampler_init() { sInitCount++; if (stack_key_initialized) return; LOG("BEGIN mozilla_sampler_init"); if (!tlsPseudoStack.init() || !tlsTicker.init()) { LOG("Failed to init."); return; } stack_key_initialized = true; Sampler::Startup(); PseudoStack *stack = new PseudoStack(); tlsPseudoStack.set(stack); Sampler::RegisterCurrentThread("Gecko", stack, true); if (sps_version2()) { // Read mode settings from MOZ_PROFILER_MODE and interval // settings from MOZ_PROFILER_INTERVAL and stack-scan threshhold // from MOZ_PROFILER_STACK_SCAN. read_profiler_env_vars(); // Create the unwinder thread. ATM there is only one. uwt__init(); # if defined(SPS_PLAT_amd64_linux) || defined(SPS_PLAT_arm_android) \ || defined(SPS_PLAT_x86_linux) || defined(SPS_PLAT_x86_android) \ || defined(SPS_PLAT_x86_windows) || defined(SPS_PLAT_amd64_windows) /* no idea if windows is correct */ // On Linuxes, register this thread (temporarily) for profiling int aLocal; uwt__register_thread_for_profiling( &aLocal ); # elif defined(SPS_PLAT_amd64_darwin) || defined(SPS_PLAT_x86_darwin) // Registration is done in platform-macos.cc # else # error "Unknown plat" # endif } // Allow the profiler to be started using signals OS::RegisterStartHandler(); // We can't open pref so we use an environment variable // to know if we should trigger the profiler on startup // NOTE: Default const char *val = PR_GetEnv("MOZ_PROFILER_STARTUP"); if (!val || !*val) { return; } const char* features[] = {"js" , "leaf" #if defined(XP_WIN) || defined(XP_MACOSX) , "stackwalk" #endif }; profiler_start(PROFILE_DEFAULT_ENTRY, PROFILE_DEFAULT_INTERVAL, features, sizeof(features)/sizeof(const char*)); LOG("END mozilla_sampler_init"); }
/** * position must be a list * If the list consists of two numbers (x y) the surface will be rendered at location x,y * the same is true for (plain x y) * (x y) * (plain x y) x,y = numbers, rendered with top left corner at x,y with scale=1 * (full) fullscreen * (centered) * (scaled) * (sized) * (rotated) * (windowed) */ Bool graphics_render_at_position(Renderable *renderable, Value position, Environment *environment) { if (environment -> fast_run) {return false;} profiler_start(profile_render); Double width = renderable -> width; Double height = renderable -> height; Double screen_width = environment -> width; Double screen_height = environment -> height; cairo_save(environment -> cairo); if (position.type == NIL) { cairo_scale(environment -> cairo, screen_width/width, screen_height/height); goto RENDER; } if (!IS_LIST(position)) { log_error_in; goto ERROR; } if (position.type != CONS) { log_error_in; goto ERROR; } Value length_val = list_length(position); if (length_val.type != INTEGER) { log_error_in; goto ERROR; } Unt length = NUM_VAL(length_val); Value first = NEXT(position); if (first.type == SYMBOL) { if (equal(first, symbols_plain)) { /**** plain ****/ /* Render at coords, unscaled */ if (length == 3) { Value x = NEXT(position); Value y = NEXT(position); if (IS_NUMERIC(x) && IS_NUMERIC(y)) { cairo_translate(environment -> cairo, NUM_VAL(x), NUM_VAL(y)); goto RENDER; } /* Return a specific error? */ } } else if (equal(first, symbols_full)) { /**** full ****/ /* Stretch image to fill entire screen */ if (length == 1) { cairo_scale(environment -> cairo, screen_width/width, screen_height/height); goto RENDER; } } else if (equal(first, symbols_centered)) { /**** centered ****/ if (length == 3) { Value x = NEXT(position); Value y = NEXT(position); if (x.type == INTEGER && y.type == INTEGER) { /* Render offset from center */ Double dx = (screen_width - width) / 2 + NUM_VAL(x); Double dy = (screen_height - height) / 2 + NUM_VAL(y); cairo_translate(environment -> cairo, dx, dy); goto RENDER; } if (x.type == FLOAT && y.type == FLOAT) { /* As in sized */ Double dx = (screen_width - width) / 2 + ((screen_width - width)/2 * NUM_VAL(x)); Double dy = (screen_height - height) / 2 + ((screen_height - height)/2 * NUM_VAL(y)); cairo_translate(environment -> cairo, dx, dy); goto RENDER; } } else if (length == 1) { Double dx = (screen_width - width) / 2; Double dy = (screen_height - height) / 2; cairo_translate(environment -> cairo, dx, dy); } } else if (equal(first, symbols_scaled)) { /**** scaled ****/ /* ('scaled x y scale) */ /* ('scaled x y scalex scaley) */ /* TODO: make it work with relative float positions */ if (length < 4 || length > 5) { log_error_in; goto ERROR; } Value x_val = NEXT(position); Value y_val = NEXT(position); Value scale_x = NEXT(position); Value scale_y = scale_x; if (length == 5) { scale_y = NEXT(position); } Double new_width; Double new_height; if (scale_x.type == INTEGER) { new_width = NUM_VAL(scale_x); } else if (scale_x.type == FLOAT) { new_width = width * NUM_VAL(scale_x); } else { log_error_in; goto ERROR; } if (scale_y.type == INTEGER) { new_height = NUM_VAL(scale_y); } else if (scale_y.type == FLOAT) { new_height = height * NUM_VAL(scale_y); } else { log_error_in; goto ERROR; } Double x = 0; Double y = 0; if (x_val.type == INTEGER) { x = NUM_VAL(x_val); } else if (x_val.type == FLOAT) { x = (screen_width - new_width) / 2 + ((screen_width - new_width)/2 * NUM_VAL(x_val)); } else { log_error_in; goto ERROR; } if (y_val.type == INTEGER) { y = NUM_VAL(y_val); } else if (y_val.type == FLOAT) { y = (screen_height - new_height) / 2 + ((screen_height - new_height)/2 * NUM_VAL(y_val)); } else { log_error_in; goto ERROR; } cairo_translate(environment -> cairo, x, y); cairo_scale(environment -> cairo, new_width/width, new_height/height); goto RENDER; } else if (equal(first, symbols_sized)) { /**** sized ****/ /* ('sized x y sizex/boundx sizey/boundy) */ /* Render scaled but keep aspect ratio */ if (length < 4 || length > 5) { log_error_in; goto ERROR; } Value x_val = NEXT(position); Value y_val = NEXT(position); Value size_x = NEXT(position); Value size_y = size_x; if (length == 5) { size_y = NEXT(position); } Double desired_width; Double desired_height; if (size_x.type == INTEGER) { desired_width = NUM_VAL(size_x); } else if (size_x.type == FLOAT) { desired_width = screen_width * NUM_VAL(size_x); } else { log_error_in; goto ERROR; } if (size_y.type == INTEGER) { desired_height = NUM_VAL(size_y); } else if (size_y.type == FLOAT) { desired_height = screen_height * NUM_VAL(size_y); } else { log_error_in; goto ERROR; } Double new_width; Double new_height; Double ratio_w = desired_width / width; Double ratio_h = desired_height / height; if (ratio_w <= ratio_h) { new_height = desired_width * ((Double) height / (Double) width); new_width = desired_width; } else { new_width = desired_height * ((Double) width / (Double) height); new_height = desired_height; } Double x = 0; Double y = 0; if (x_val.type == INTEGER) { x = NUM_VAL(x_val); } else if (x_val.type == FLOAT) { x = (screen_width - new_width) / 2 + ((screen_width - new_width)/2 * NUM_VAL(x_val)); } else { log_error_in; goto ERROR; } if (y_val.type == INTEGER) { y = NUM_VAL(y_val); } else if (y_val.type == FLOAT) { y = (screen_height - new_height) / 2 + ((screen_height - new_height)/2 * NUM_VAL(y_val)); } else { log_error_in; goto ERROR; } cairo_translate(environment -> cairo, x, y); cairo_scale(environment -> cairo, new_width/width, new_height/height); goto RENDER; } else if (equal(first, symbols_rotated)) { /**** Rotated ****/ if (length < 4) { log_error_in; goto ERROR; } Value angle_v = NEXT(position); if (!IS_NUMERIC(angle_v)) { log_error_in; goto ERROR; } Double angle = NUM_VAL(angle_v); Value x = NEXT(position); Value y = NEXT(position); if (!IS_NUMERIC(x) || !IS_NUMERIC(y)) { log_error_in; goto ERROR; } Double dx = NUM_VAL(x); Double dy = NUM_VAL(y); Value scale_x; Value scale_y; if (length == 5) { scale_x = NEXT(position); scale_y = scale_x; } else if (length == 6) { scale_x = NEXT(position); scale_y = NEXT(position); } else { log_error_in; goto ERROR; } Double sx; Double sy; if (scale_x.type == INTEGER && scale_y.type == INTEGER) { sx = NUM_VAL(scale_x)/width; sy = NUM_VAL(scale_y)/height; } else if (scale_x.type == FLOAT && scale_y.type == FLOAT) { sx = NUM_VAL(scale_x); sy = NUM_VAL(scale_y); } else { log_error_in; goto ERROR; } if (sx == 0.0 || sy == 0.0) { /* Scaled to 0, thus is not shown. Cairo freezes if given scales of 0 */ return true; } cairo_translate(environment -> cairo, dx, dy); cairo_translate(environment -> cairo, sx*width/2, sx*height/2); cairo_rotate(environment -> cairo, angle); cairo_scale(environment -> cairo, sx, sy); cairo_translate(environment -> cairo, -width/2, -height/2); goto RENDER; } } else if (IS_NUMERIC(first) && length == 2) {/* (x y) */ Value second = NEXT(position); if (IS_NUMERIC(second)) { Double x = NUM_VAL(first); Double y = NUM_VAL(second); cairo_translate(environment -> cairo, x, y); goto RENDER; } } ERROR: cairo_restore(environment -> cairo); profiler_end(profile_render); return false; RENDER: renderable -> render(renderable -> data, environment); /* cairo_set_source_surface(environment -> cairo, surface, 0, 0); */ /* cairo_paint(environment -> cairo); */ cairo_restore(environment -> cairo); profiler_end(profile_render); return true; }