void thorium_worker_enable_profiler(struct thorium_worker *self) { char file_name[100]; core_bitmap_set_bit_uint32_t(&self->flags, FLAG_ENABLE_ACTOR_LOAD_PROFILER); sprintf(file_name, "node_%d_worker_%d_actor_load_profile.txt", thorium_node_name(self->node), self->name); core_buffered_file_writer_init(&self->load_profile_writer, file_name); core_buffered_file_writer_printf(&self->load_profile_writer, "start_time\tend_time\tactor\tscript\taction\tcompute_time\twaiting_time\n"); }
void core_writer_process_receive(struct thorium_actor *self, struct thorium_message *message) { int action; int count; int source; char *buffer; char *file_name; struct core_writer_process *concrete_self; concrete_self = thorium_actor_concrete_actor(self); action = thorium_message_action(message); count = thorium_message_count(message); buffer = thorium_message_buffer(message); source = thorium_message_source(message); if (action == ACTION_OPEN) { if (concrete_self->has_file) { thorium_actor_log(self, "actor error, already open, can not open\n"); return; } file_name = buffer; core_buffered_file_writer_init(&concrete_self->writer, file_name); concrete_self->has_file = 1; thorium_actor_send_reply_empty(self, ACTION_OPEN_REPLY); } else if (action == ACTION_WRITE) { core_buffered_file_writer_write(&concrete_self->writer, buffer, count); thorium_actor_send_reply_empty(self, ACTION_WRITE_REPLY); } else if (action == ACTION_CLOSE) { if (!concrete_self->has_file) { thorium_actor_log(self, "Error, can not close a file that is not open\n"); return; } core_buffered_file_writer_destroy(&concrete_self->writer); concrete_self->has_file = 0; thorium_actor_send_reply_empty(self, ACTION_CLOSE_REPLY); } else if (action == ACTION_ASK_TO_STOP && source == thorium_actor_supervisor(self)) { /* * Close the file if it is open * right now. */ if (concrete_self->has_file) { core_buffered_file_writer_destroy(&concrete_self->writer); concrete_self->has_file = 0; } thorium_actor_send_to_self_empty(self, ACTION_STOP); thorium_actor_send_reply_empty(self, ACTION_ASK_TO_STOP_REPLY); } }
void biosal_coverage_distribution_write_distribution(struct thorium_actor *self) { struct core_map_iterator iterator; int *coverage; uint64_t *canonical_frequency; uint64_t frequency; struct biosal_coverage_distribution *concrete_actor; struct core_vector coverage_values; struct core_vector_iterator vector_iterator; struct core_buffered_file_writer descriptor; struct core_buffered_file_writer descriptor_canonical; struct core_string file_name; struct core_string canonical_file_name; int argc; char **argv; int name; char *directory_name; name = thorium_actor_name(self); argc = thorium_actor_argc(self); argv = thorium_actor_argv(self); directory_name = biosal_command_get_output_directory(argc, argv); /* Create the directory if it does not exist */ if (!core_directory_verify_existence(directory_name)) { core_directory_create(directory_name); } core_string_init(&file_name, ""); core_string_append(&file_name, directory_name); core_string_append(&file_name, "/"); core_string_append(&file_name, BIOSAL_COVERAGE_DISTRIBUTION_DEFAULT_OUTPUT_FILE); core_string_init(&canonical_file_name, ""); core_string_append(&canonical_file_name, directory_name); core_string_append(&canonical_file_name, "/"); core_string_append(&canonical_file_name, BIOSAL_COVERAGE_DISTRIBUTION_DEFAULT_OUTPUT_FILE_CANONICAL); core_buffered_file_writer_init(&descriptor, core_string_get(&file_name)); core_buffered_file_writer_init(&descriptor_canonical, core_string_get(&canonical_file_name)); concrete_actor = (struct biosal_coverage_distribution *)thorium_actor_concrete_actor(self); core_vector_init(&coverage_values, sizeof(int)); core_map_iterator_init(&iterator, &concrete_actor->distribution); #ifdef BIOSAL_COVERAGE_DISTRIBUTION_DEBUG thorium_actor_log(self, "map size %d\n", (int)core_map_size(&concrete_actor->distribution)); #endif while (core_map_iterator_has_next(&iterator)) { core_map_iterator_next(&iterator, (void **)&coverage, (void **)&canonical_frequency); #ifdef BIOSAL_COVERAGE_DISTRIBUTION_DEBUG thorium_actor_log(self, "DEBUG COVERAGE %d FREQUENCY %" PRIu64 "\n", *coverage, *frequency); #endif core_vector_push_back(&coverage_values, coverage); } core_map_iterator_destroy(&iterator); core_vector_sort_int(&coverage_values); #ifdef BIOSAL_COVERAGE_DISTRIBUTION_DEBUG thorium_actor_log(self, "after sort "); core_vector_print_int(&coverage_values); thorium_actor_log(self, "\n"); #endif core_vector_iterator_init(&vector_iterator, &coverage_values); #if 0 core_buffered_file_writer_printf(&descriptor_canonical, "Coverage\tFrequency\n"); #endif core_buffered_file_writer_printf(&descriptor, "Coverage\tFrequency\n"); #ifdef BIOSAL_COVERAGE_DISTRIBUTION_DEBUG #endif while (core_vector_iterator_has_next(&vector_iterator)) { core_vector_iterator_next(&vector_iterator, (void **)&coverage); canonical_frequency = (uint64_t *)core_map_get(&concrete_actor->distribution, coverage); frequency = 2 * *canonical_frequency; core_buffered_file_writer_printf(&descriptor_canonical, "%d %" PRIu64 "\n", *coverage, *canonical_frequency); core_buffered_file_writer_printf(&descriptor, "%d\t%" PRIu64 "\n", *coverage, frequency); } core_vector_destroy(&coverage_values); core_vector_iterator_destroy(&vector_iterator); thorium_actor_log(self, "distribution %d wrote %s\n", name, core_string_get(&file_name)); thorium_actor_log(self, "distribution %d wrote %s\n", name, core_string_get(&canonical_file_name)); core_buffered_file_writer_destroy(&descriptor); core_buffered_file_writer_destroy(&descriptor_canonical); core_string_destroy(&file_name); core_string_destroy(&canonical_file_name); }