void core_map_examine(struct core_map *self) { int key_size; int value_size; uint64_t size; key_size = core_map_get_key_size(self); value_size = core_map_get_value_size(self); size = core_map_size(self); printf("core_map_examine key_size %d value_size %d size %" PRIu64 "\n", key_size, value_size, size); }
void biosal_assembly_graph_store_push_data(struct thorium_actor *self, struct thorium_message *message) { struct biosal_assembly_graph_store *concrete_self; int name; int source; concrete_self = thorium_actor_concrete_actor(self); source = thorium_message_source(message); concrete_self->source = source; name = thorium_actor_name(self); core_map_init(&concrete_self->coverage_distribution, sizeof(int), sizeof(uint64_t)); printf("%s/%d: local table has %" PRIu64" canonical kmers (%" PRIu64 " kmers)\n", thorium_actor_script_name(self), name, core_map_size(&concrete_self->table), 2 * core_map_size(&concrete_self->table)); core_memory_pool_examine(&concrete_self->persistent_memory); core_map_iterator_init(&concrete_self->iterator, &concrete_self->table); thorium_actor_send_to_self_empty(self, ACTION_YIELD); }
void biosal_coverage_distribution_ask_to_stop(struct thorium_actor *self, struct thorium_message *message) { struct core_map_iterator iterator; struct core_vector coverage_values; struct biosal_coverage_distribution *concrete_actor; uint64_t *frequency; int *coverage; concrete_actor = (struct biosal_coverage_distribution *)thorium_actor_concrete_actor(self); core_map_iterator_init(&iterator, &concrete_actor->distribution); core_vector_init(&coverage_values, sizeof(int)); while (core_map_iterator_has_next(&iterator)) { #if 0 thorium_actor_log(self, "DEBUG EMIT iterator\n"); #endif core_map_iterator_next(&iterator, (void **)&coverage, (void **)&frequency); #ifdef CORE_DEBUGGER_ASSERT_ENABLED if (coverage == NULL) { thorium_actor_log(self, "DEBUG map has %d buckets\n", (int)core_map_size(&concrete_actor->distribution)); } #endif CORE_DEBUGGER_ASSERT(coverage != NULL); core_vector_push_back(&coverage_values, coverage); } core_vector_sort_int(&coverage_values); core_map_iterator_destroy(&iterator); core_vector_destroy(&coverage_values); thorium_actor_ask_to_stop(self, message); }
void biosal_assembly_graph_store_print_progress(struct thorium_actor *self) { struct biosal_assembly_graph_store *concrete_self; uint64_t total; uint64_t stride; uint64_t current_value; int steps; float ratio; char finished[] = " FINISHED"; char not_finished[] = ""; char *state; concrete_self = thorium_actor_concrete_actor(self); total = core_map_size(&concrete_self->table); steps = 20; stride = total / steps; current_value = concrete_self->consumed_canonical_vertex_count; if ((current_value == 0) || (current_value % stride == 0) || (current_value == total)) { state = not_finished; if (current_value == total) { state = finished; } ratio = (0.0 + current_value) / total; printf("%s/%d %.2f of vertices were consumed%s\n", thorium_actor_script_name(self), thorium_actor_name(self), ratio, state); } }
void biosal_assembly_graph_store_add_arc(struct thorium_actor *self, struct biosal_assembly_arc *arc, char *sequence, void *key) { struct biosal_assembly_graph_store *concrete_self; struct biosal_dna_kmer *source; struct biosal_dna_kmer real_source; int destination; int type; struct biosal_assembly_vertex *vertex; struct core_memory_pool *ephemeral_memory; int is_canonical; #if 0 /* * Don't do anything just to see if this code * is buggy. */ return; #endif #ifdef BIOSAL_ASSEMBLY_GRAPH_STORE_DEBUG_ARC int verbose; #endif ephemeral_memory = thorium_actor_get_ephemeral_memory(self); concrete_self = thorium_actor_concrete_actor(self); #ifdef BIOSAL_ASSEMBLY_GRAPH_STORE_DEBUG_ARC verbose = 0; if (concrete_self->received_arc_count == 0) { verbose = 1; } if (verbose) { printf("DEBUG BioSAL::GraphStore::AddArc\n"); biosal_assembly_arc_print(arc, concrete_self->kmer_length, &concrete_self->transport_codec, ephemeral_memory); } #endif source = biosal_assembly_arc_source(arc); destination = biosal_assembly_arc_destination(arc); type = biosal_assembly_arc_type(arc); /* * Don't convert the data if the transport codec and the * storage codec are the same. */ if (concrete_self->codec_are_different) { biosal_dna_kmer_get_sequence(source, sequence, concrete_self->kmer_length, &concrete_self->transport_codec); biosal_dna_kmer_init(&real_source, sequence, &concrete_self->storage_codec, ephemeral_memory); source = &real_source; } biosal_dna_kmer_pack_store_key(source, key, concrete_self->kmer_length, &concrete_self->storage_codec, ephemeral_memory); vertex = core_map_get(&concrete_self->table, key); #ifdef CORE_DEBUGGER_ENABLE_ASSERT if (vertex == NULL) { printf("Error: vertex is NULL, key_length_in_bytes %d size %" PRIu64 "\n", concrete_self->key_length_in_bytes, core_map_size(&concrete_self->table)); } #endif CORE_DEBUGGER_ASSERT(vertex != NULL); #ifdef BIOSAL_ASSEMBLY_GRAPH_STORE_DEBUG_ARC if (verbose) { printf("DEBUG BEFORE:\n"); biosal_assembly_vertex_print(vertex); } #endif /* * Inverse the arc if the source is not canonical */ is_canonical = biosal_dna_kmer_is_canonical(source, concrete_self->kmer_length, &concrete_self->storage_codec); if (!is_canonical) { if (type == BIOSAL_ARC_TYPE_PARENT) { type = BIOSAL_ARC_TYPE_CHILD; } else if (type == BIOSAL_ARC_TYPE_CHILD) { type = BIOSAL_ARC_TYPE_PARENT; } destination = biosal_dna_codec_get_complement(destination); } if (type == BIOSAL_ARC_TYPE_PARENT) { biosal_assembly_vertex_add_parent(vertex, destination); } else if (type == BIOSAL_ARC_TYPE_CHILD) { biosal_assembly_vertex_add_child(vertex, destination); } #ifdef BIOSAL_ASSEMBLY_GRAPH_STORE_DEBUG_ARC if (verbose) { printf("DEBUG AFTER:\n"); biosal_assembly_vertex_print(vertex); } #endif if (concrete_self->codec_are_different) { biosal_dna_kmer_destroy(&real_source, ephemeral_memory); } }
void biosal_assembly_graph_store_push_kmer_block(struct thorium_actor *self, struct thorium_message *message) { struct core_memory_pool *ephemeral_memory; struct biosal_dna_kmer_frequency_block block; struct biosal_assembly_vertex *bucket; void *packed_kmer; struct core_map_iterator iterator; struct biosal_assembly_graph_store *concrete_self; /*int tag;*/ void *key; struct core_map *kmers; struct biosal_dna_kmer kmer; void *buffer; int count; struct biosal_dna_kmer encoded_kmer; char *raw_kmer; int period; struct biosal_dna_kmer *kmer_pointer; int *frequency; ephemeral_memory = thorium_actor_get_ephemeral_memory(self); concrete_self = thorium_actor_concrete_actor(self); /*tag = thorium_message_action(message);*/ buffer = thorium_message_buffer(message); count = thorium_message_count(message); /* * Handler for PUSH_DATA */ biosal_dna_kmer_frequency_block_init(&block, concrete_self->kmer_length, ephemeral_memory, &concrete_self->transport_codec, 0); biosal_dna_kmer_frequency_block_unpack(&block, buffer, ephemeral_memory, &concrete_self->transport_codec); key = core_memory_pool_allocate(ephemeral_memory, concrete_self->key_length_in_bytes); kmers = biosal_dna_kmer_frequency_block_kmers(&block); core_map_iterator_init(&iterator, kmers); period = 2500000; raw_kmer = core_memory_pool_allocate(thorium_actor_get_ephemeral_memory(self), concrete_self->kmer_length + 1); if (!concrete_self->printed_vertex_size) { printf("DEBUG VERTEX DELIVERY %d bytes\n", count); concrete_self->printed_vertex_size = 1; } while (core_map_iterator_has_next(&iterator)) { /* * add kmers to store */ core_map_iterator_next(&iterator, (void **)&packed_kmer, (void **)&frequency); /* Store the kmer in 2 bit encoding */ biosal_dna_kmer_init_empty(&kmer); biosal_dna_kmer_unpack(&kmer, packed_kmer, concrete_self->kmer_length, ephemeral_memory, &concrete_self->transport_codec); kmer_pointer = &kmer; if (concrete_self->codec_are_different) { /* * Get a copy of the sequence */ biosal_dna_kmer_get_sequence(kmer_pointer, raw_kmer, concrete_self->kmer_length, &concrete_self->transport_codec); biosal_dna_kmer_init(&encoded_kmer, raw_kmer, &concrete_self->storage_codec, thorium_actor_get_ephemeral_memory(self)); kmer_pointer = &encoded_kmer; } biosal_dna_kmer_pack_store_key(kmer_pointer, key, concrete_self->kmer_length, &concrete_self->storage_codec, thorium_actor_get_ephemeral_memory(self)); #ifdef BIOSAL_DEBUG_ISSUE_540 if (strcmp(raw_kmer, "AGCTGGTAGTCATCACCAGACTGGAACAG") == 0 || strcmp(raw_kmer, "CGCGATCTGTTGCTGGGCCTAACGTGGTA") == 0 || strcmp(raw_kmer, "TACCACGTTAGGCCCAGCAACAGATCGCG") == 0) { printf("Examine store key for %s\n", raw_kmer); core_debugger_examine(key, concrete_self->key_length_in_bytes); } #endif bucket = core_map_get(&concrete_self->table, key); if (bucket == NULL) { /* This is the first time that this kmer is seen. */ bucket = core_map_add(&concrete_self->table, key); biosal_assembly_vertex_init(bucket); #if 0 printf("DEBUG303 ADD_KEY"); biosal_dna_kmer_print(&encoded_kmer, concrete_self->kmer_length, &concrete_self->storage_codec, ephemeral_memory); #endif } if (concrete_self->codec_are_different) { biosal_dna_kmer_destroy(&encoded_kmer, thorium_actor_get_ephemeral_memory(self)); } biosal_dna_kmer_destroy(&kmer, ephemeral_memory); biosal_assembly_vertex_increase_coverage_depth(bucket, *frequency); if (concrete_self->received >= concrete_self->last_received + period) { printf("%s/%d received %" PRIu64 " kmers so far," " store has %" PRIu64 " canonical kmers, %" PRIu64 " kmers\n", thorium_actor_script_name(self), thorium_actor_name(self), concrete_self->received, core_map_size(&concrete_self->table), 2 * core_map_size(&concrete_self->table)); concrete_self->last_received = concrete_self->received; } concrete_self->received += *frequency; } core_memory_pool_free(ephemeral_memory, key); core_memory_pool_free(ephemeral_memory, raw_kmer); core_map_iterator_destroy(&iterator); biosal_dna_kmer_frequency_block_destroy(&block, thorium_actor_get_ephemeral_memory(self)); thorium_actor_send_reply_empty(self, ACTION_PUSH_KMER_BLOCK_REPLY); }
void biosal_assembly_graph_store_yield_reply(struct thorium_actor *self, struct thorium_message *message) { struct biosal_dna_kmer kmer; void *key; struct biosal_assembly_vertex *value; int coverage; int customer; uint64_t *count; int new_count; void *new_buffer; struct thorium_message new_message; struct core_memory_pool *ephemeral_memory; struct biosal_assembly_graph_store *concrete_self; int i; int max; ephemeral_memory = thorium_actor_get_ephemeral_memory(self); concrete_self = thorium_actor_concrete_actor(self); customer = concrete_self->customer; #if 0 printf("YIELD REPLY\n"); #endif i = 0; max = 1024; key = NULL; value = NULL; while (i < max && core_map_iterator_has_next(&concrete_self->iterator)) { core_map_iterator_next(&concrete_self->iterator, (void **)&key, (void **)&value); biosal_dna_kmer_init_empty(&kmer); biosal_dna_kmer_unpack(&kmer, key, concrete_self->kmer_length, ephemeral_memory, &concrete_self->storage_codec); coverage = biosal_assembly_vertex_coverage_depth(value); count = (uint64_t *)core_map_get(&concrete_self->coverage_distribution, &coverage); if (count == NULL) { count = (uint64_t *)core_map_add(&concrete_self->coverage_distribution, &coverage); (*count) = 0; } /* increment for the lowest kmer (canonical) */ (*count)++; biosal_dna_kmer_destroy(&kmer, ephemeral_memory); ++i; } /* yield again if the iterator is not at the end */ if (core_map_iterator_has_next(&concrete_self->iterator)) { #if 0 printf("yield ! %d\n", i); #endif thorium_actor_send_to_self_empty(self, ACTION_YIELD); return; } /* printf("ready...\n"); */ core_map_iterator_destroy(&concrete_self->iterator); new_count = core_map_pack_size(&concrete_self->coverage_distribution); new_buffer = thorium_actor_allocate(self, new_count); core_map_pack(&concrete_self->coverage_distribution, new_buffer); printf("SENDING %s/%d sends map to %d, %d bytes / %d entries\n", thorium_actor_script_name(self), thorium_actor_name(self), customer, new_count, (int)core_map_size(&concrete_self->coverage_distribution)); thorium_message_init(&new_message, ACTION_PUSH_DATA, new_count, new_buffer); thorium_actor_send(self, customer, &new_message); thorium_message_destroy(&new_message); core_map_destroy(&concrete_self->coverage_distribution); thorium_actor_send_empty(self, concrete_self->source, ACTION_PUSH_DATA_REPLY); }
void biosal_assembly_graph_store_print(struct thorium_actor *self) { struct core_map_iterator iterator; struct biosal_dna_kmer kmer; void *key; struct biosal_assembly_vertex *value; int coverage; char *sequence; struct biosal_assembly_graph_store *concrete_self; int maximum_length; int length; struct core_memory_pool *ephemeral_memory; ephemeral_memory = thorium_actor_get_ephemeral_memory(self); concrete_self = thorium_actor_concrete_actor(self); core_map_iterator_init(&iterator, &concrete_self->table); printf("map size %d\n", (int)core_map_size(&concrete_self->table)); maximum_length = 0; while (core_map_iterator_has_next(&iterator)) { core_map_iterator_next(&iterator, (void **)&key, (void **)&value); biosal_dna_kmer_init_empty(&kmer); biosal_dna_kmer_unpack(&kmer, key, concrete_self->kmer_length, thorium_actor_get_ephemeral_memory(self), &concrete_self->storage_codec); length = biosal_dna_kmer_length(&kmer, concrete_self->kmer_length); /* printf("length %d\n", length); */ if (length > maximum_length) { maximum_length = length; } biosal_dna_kmer_destroy(&kmer, thorium_actor_get_ephemeral_memory(self)); } /* printf("MAx length %d\n", maximum_length); */ sequence = core_memory_pool_allocate(ephemeral_memory, maximum_length + 1); sequence[0] = '\0'; core_map_iterator_destroy(&iterator); core_map_iterator_init(&iterator, &concrete_self->table); while (core_map_iterator_has_next(&iterator)) { core_map_iterator_next(&iterator, (void **)&key, (void **)&value); biosal_dna_kmer_init_empty(&kmer); biosal_dna_kmer_unpack(&kmer, key, concrete_self->kmer_length, thorium_actor_get_ephemeral_memory(self), &concrete_self->storage_codec); biosal_dna_kmer_get_sequence(&kmer, sequence, concrete_self->kmer_length, &concrete_self->storage_codec); coverage = biosal_assembly_vertex_coverage_depth(value); printf("Sequence %s Coverage %d\n", sequence, coverage); biosal_dna_kmer_destroy(&kmer, thorium_actor_get_ephemeral_memory(self)); } core_map_iterator_destroy(&iterator); core_memory_pool_free(ephemeral_memory, sequence); }
int core_map_empty(struct core_map *self) { return core_map_size(self) == 0; }
void biosal_sequence_partitioner_receive(struct thorium_actor *actor, struct thorium_message *message) { int tag; int source; int count; void *buffer; int bytes; struct biosal_sequence_partitioner *concrete_actor; struct biosal_partition_command command; struct thorium_message response; int command_number; struct biosal_partition_command *active_command; int stream_index; struct biosal_partition_command *command_bucket; int i; thorium_message_get_all(message, &tag, &count, &buffer, &source); concrete_actor = (struct biosal_sequence_partitioner *)thorium_actor_concrete_actor(actor); if (tag == ACTION_SEQUENCE_PARTITIONER_SET_BLOCK_SIZE) { thorium_message_unpack_int(message, 0, &concrete_actor->block_size); thorium_actor_send_reply_empty(actor, ACTION_SEQUENCE_PARTITIONER_SET_BLOCK_SIZE_REPLY); biosal_sequence_partitioner_verify(actor); /* printf("DEBUG biosal_sequence_partitioner_receive received block size\n"); */ } else if (tag == ACTION_SEQUENCE_PARTITIONER_SET_ENTRY_VECTOR) { /* printf("DEBUG biosal_sequence_partitioner_receive unpacking vector, %d bytes\n", count); */ core_vector_init(&concrete_actor->stream_entries, 0); core_vector_unpack(&concrete_actor->stream_entries, buffer); /* printf("DEBUG after unpack\n"); */ thorium_actor_send_reply_empty(actor, ACTION_SEQUENCE_PARTITIONER_SET_ENTRY_VECTOR_REPLY); /* printf("DEBUG biosal_sequence_partitioner_receive received received entry vector\n"); */ biosal_sequence_partitioner_verify(actor); } else if (tag == ACTION_SEQUENCE_PARTITIONER_SET_ACTOR_COUNT) { thorium_message_unpack_int(message, 0, &concrete_actor->store_count); thorium_actor_send_reply_empty(actor, ACTION_SEQUENCE_PARTITIONER_SET_ACTOR_COUNT_REPLY); biosal_sequence_partitioner_verify(actor); /* printf("DEBUG biosal_sequence_partitioner_receive received received store count\n"); */ } else if (tag == ACTION_SEQUENCE_PARTITIONER_GET_COMMAND) { if (core_queue_dequeue(&concrete_actor->available_commands, &command)) { bytes = biosal_partition_command_pack_size(&command); /* printf("DEBUG partitioner has command, packing %d bytes!\n", bytes); */ buffer = thorium_actor_allocate(actor, bytes); biosal_partition_command_pack(&command, buffer); thorium_message_init(&response, ACTION_SEQUENCE_PARTITIONER_GET_COMMAND_REPLY, bytes, buffer); thorium_actor_send_reply(actor, &response); /* store the active command */ command_number = biosal_partition_command_name(&command); command_bucket = (struct biosal_partition_command *)core_map_add(&concrete_actor->active_commands, &command_number); *command_bucket = command; /* there may be other command available too ! */ } } else if (tag == ACTION_SEQUENCE_PARTITIONER_GET_COMMAND_REPLY_REPLY) { /* * take the name of the command, find it in the active * command, generate a new command, and send ACTION_SEQUENCE_PARTITIONER_COMMAND_IS_READY * as a reply */ thorium_message_unpack_int(message, 0, &command_number); active_command = core_map_get(&concrete_actor->active_commands, &command_number); if (active_command == NULL) { return; } stream_index = biosal_partition_command_stream_index(active_command); active_command = NULL; core_map_delete(&concrete_actor->active_commands, &command_number); biosal_sequence_partitioner_generate_command(actor, stream_index); if (core_map_size(&concrete_actor->active_commands) == 0 && core_queue_size(&concrete_actor->available_commands) == 0) { thorium_actor_send_reply_empty(actor, ACTION_SEQUENCE_PARTITIONER_FINISHED); } } else if (tag == ACTION_ASK_TO_STOP && source == thorium_actor_supervisor(actor)) { #ifdef BIOSAL_SEQUENCE_PARTITIONER_DEBUG printf("DEBUG biosal_sequence_partitioner_receive ACTION_ASK_TO_STOP\n"); #endif thorium_actor_send_to_self_empty(actor, ACTION_STOP); } else if (tag == ACTION_SEQUENCE_PARTITIONER_PROVIDE_STORE_ENTRY_COUNTS_REPLY) { /* generate commands */ for (i = 0; i < core_vector_size(&concrete_actor->stream_entries); i++) { biosal_sequence_partitioner_generate_command(actor, i); } } }
int main(int argc, char **argv) { BEGIN_TESTS(); { struct core_map big_map; int kmer_length = 43; struct biosal_dna_kmer kmer; int count; int run_test; int coverage; void *key; int key_length; int *bucket; int i; struct biosal_dna_codec codec; struct core_memory_pool memory; core_memory_pool_init(&memory, 1048576, -1); biosal_dna_codec_init(&codec); run_test = 1; count = 100000000; printf("STRESS TEST\n"); biosal_dna_kmer_init_mock(&kmer, kmer_length, &codec, &memory); key_length = biosal_dna_kmer_pack_size(&kmer, kmer_length, &codec); biosal_dna_kmer_destroy(&kmer, &memory); core_map_init(&big_map, key_length, sizeof(coverage)); key = core_memory_allocate(key_length, -1); i = 0; while (i < count && run_test) { biosal_dna_kmer_init_random(&kmer, kmer_length, &codec, &memory); biosal_dna_kmer_pack_store_key(&kmer, key, kmer_length, &codec, &memory); bucket = core_map_add(&big_map, key); coverage = 99; (*bucket) = coverage; biosal_dna_kmer_destroy(&kmer, &memory); if (i % 100000 == 0) { printf("ADD %d/%d %" PRIu64 "\n", i, count, core_map_size(&big_map)); } i++; } core_map_destroy(&big_map); core_memory_free(key, -1); biosal_dna_codec_destroy(&codec); core_memory_pool_destroy(&memory); } END_TESTS(); return 0; }
void biosal_coverage_distribution_receive(struct thorium_actor *self, struct thorium_message *message) { int tag; struct core_map map; struct core_map_iterator iterator; int *coverage_from_message; uint64_t *count_from_message; uint64_t *frequency; int count; void *buffer; struct biosal_coverage_distribution *concrete_actor; int name; int source; struct core_memory_pool *ephemeral_memory; ephemeral_memory = thorium_actor_get_ephemeral_memory(self); name = thorium_actor_name(self); source = thorium_message_source(message); concrete_actor = (struct biosal_coverage_distribution *)thorium_actor_concrete_actor(self); tag = thorium_message_action(message); count = thorium_message_count(message); buffer = thorium_message_buffer(message); if (tag == ACTION_PUSH_DATA) { core_map_init(&map, 0, 0); core_map_set_memory_pool(&map, ephemeral_memory); core_map_unpack(&map, buffer); core_map_iterator_init(&iterator, &map); while (core_map_iterator_has_next(&iterator)) { core_map_iterator_next(&iterator, (void **)&coverage_from_message, (void **)&count_from_message); #ifdef BIOSAL_COVERAGE_DISTRIBUTION_DEBUG thorium_actor_log(self, "DEBUG DATA %d %d\n", (int)*coverage_from_message, (int)*count_from_message); #endif frequency = core_map_get(&concrete_actor->distribution, coverage_from_message); if (frequency == NULL) { frequency = core_map_add(&concrete_actor->distribution, coverage_from_message); (*frequency) = 0; } (*frequency) += (*count_from_message); } core_map_iterator_destroy(&iterator); thorium_actor_send_reply_empty(self, ACTION_PUSH_DATA_REPLY); concrete_actor->actual++; thorium_actor_log(self, "distribution/%d receives coverage data from producer/%d, %d entries / %d bytes %d/%d\n", name, source, (int)core_map_size(&map), count, concrete_actor->actual, concrete_actor->expected); if (concrete_actor->expected != 0 && concrete_actor->expected == concrete_actor->actual) { thorium_actor_log(self, "received everything %d/%d\n", concrete_actor->actual, concrete_actor->expected); biosal_coverage_distribution_write_distribution(self); thorium_actor_send_empty(self, concrete_actor->source, ACTION_NOTIFY); } core_map_destroy(&map); } else if (tag == ACTION_ASK_TO_STOP) { biosal_coverage_distribution_ask_to_stop(self, message); } else if (tag == ACTION_SET_EXPECTED_MESSAGE_COUNT) { concrete_actor->source = source; thorium_message_unpack_int(message, 0, &concrete_actor->expected); thorium_actor_log(self, "distribution %d expects %d messages\n", thorium_actor_name(self), concrete_actor->expected); thorium_actor_send_reply_empty(self, ACTION_SET_EXPECTED_MESSAGE_COUNT_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); }
void thorium_worker_print_actors(struct thorium_worker *worker, struct thorium_balancer *scheduler) { struct core_map_iterator iterator; int name; int count; struct thorium_actor *actor; int producers; int consumers; int received; int difference; int script; struct core_map distribution; int frequency; struct thorium_script *script_object; int dead; int node_name; int worker_name; int previous_amount; node_name = thorium_node_name(worker->node); worker_name = worker->name; core_map_iterator_init(&iterator, &worker->actors); printf("node/%d worker/%d %d queued messages, received: %d busy: %d load: %f ring: %d scheduled actors: %d/%d\n", node_name, worker_name, thorium_worker_get_scheduled_message_count(worker), thorium_worker_get_sum_of_received_actor_messages(worker), thorium_worker_is_busy(worker), thorium_worker_get_scheduling_epoch_load(worker), core_fast_ring_size_from_producer(&worker->actors_to_schedule), thorium_scheduler_size(&worker->scheduler), (int)core_map_size(&worker->actors)); core_map_init(&distribution, sizeof(int), sizeof(int)); while (core_map_iterator_get_next_key_and_value(&iterator, &name, NULL)) { actor = thorium_node_get_actor_from_name(worker->node, name); if (actor == NULL) { continue; } dead = thorium_actor_dead(actor); if (dead) { continue; } count = thorium_actor_get_mailbox_size(actor); received = thorium_actor_get_sum_of_received_messages(actor); producers = core_map_size(thorium_actor_get_received_messages(actor)); consumers = core_map_size(thorium_actor_get_sent_messages(actor)); previous_amount = 0; core_map_get_value(&worker->actor_received_messages, &name, &previous_amount); difference = received - previous_amount;; if (!core_map_update_value(&worker->actor_received_messages, &name, &received)) { core_map_add_value(&worker->actor_received_messages, &name, &received); } printf(" [%s/%d] mailbox: %d received: %d (+%d) producers: %d consumers: %d\n", thorium_actor_script_name(actor), name, count, received, difference, producers, consumers); script = thorium_actor_script(actor); if (core_map_get_value(&distribution, &script, &frequency)) { ++frequency; core_map_update_value(&distribution, &script, &frequency); } else { frequency = 1; core_map_add_value(&distribution, &script, &frequency); } } /*printf("\n");*/ core_map_iterator_destroy(&iterator); core_map_iterator_init(&iterator, &distribution); printf("node/%d worker/%d Frequency list\n", node_name, worker_name); while (core_map_iterator_get_next_key_and_value(&iterator, &script, &frequency)) { script_object = thorium_node_find_script(worker->node, script); CORE_DEBUGGER_ASSERT(script_object != NULL); printf("node/%d worker/%d Frequency %s => %d\n", node_name, worker->name, thorium_script_name(script_object), frequency); } core_map_iterator_destroy(&iterator); core_map_destroy(&distribution); }