示例#1
0
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);
}
示例#2
0
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);
    }
}
示例#3
0
文件: worker.c 项目: huyba/biosal
void thorium_worker_destroy(struct thorium_worker *worker)
{
    void *buffer;

    thorium_load_profiler_destroy(&worker->profiler);

    if (core_bitmap_get_bit_uint32_t(&worker->flags, FLAG_ENABLE_ACTOR_LOAD_PROFILER)) {
        core_buffered_file_writer_destroy(&worker->load_profile_writer);
    }

    core_map_destroy(&worker->actor_received_messages);

    /*
    thorium_worker_print_balance(worker);
    */
    while (thorium_worker_fetch_clean_outbound_buffer(worker, &buffer)) {

        core_memory_pool_free(&worker->outbound_message_memory_pool, buffer);

#ifdef THORIUM_WORKER_DEBUG_INJECTION
        ++worker->counter_freed_outbound_buffers_from_other_workers;
#endif
    }

#ifdef THORIUM_WORKER_DEBUG_INJECTION
    printf("AFTER COLLECTION\n");
    thorium_worker_print_balance(worker);

    printf("THORIUM-> clean_message_queue_for_triage has %d items\n",
                    core_fast_queue_size(&worker->clean_message_queue_for_triage));
    printf("THORIUM-> clean_message_ring_for_triage has %d items\n",
                    core_fast_ring_size_from_producer(&worker->clean_message_ring_for_triage));
    printf("THORIUM-> injected_clean_outbound_buffers has %d items\n",
                    core_fast_ring_size_from_producer(&worker->injected_clean_outbound_buffers));
#endif

    core_timer_destroy(&worker->timer);

#ifdef THORIUM_WORKER_ENABLE_LOCK
    core_lock_destroy(&worker->lock);
#endif

    core_fast_ring_destroy(&worker->actors_to_schedule);

#ifdef THORIUM_NODE_INJECT_CLEAN_WORKER_BUFFERS
    core_fast_ring_destroy(&worker->injected_clean_outbound_buffers);

    core_fast_ring_destroy(&worker->clean_message_ring_for_triage);
    core_fast_queue_destroy(&worker->clean_message_queue_for_triage);
#endif

    thorium_scheduler_destroy(&worker->scheduler);
    core_fast_ring_destroy(&worker->outbound_message_queue);
    core_fast_queue_destroy(&worker->outbound_message_queue_buffer);

    core_map_destroy(&worker->actors);
    core_map_iterator_destroy(&worker->actor_iterator);
    core_set_destroy(&worker->evicted_actors);

    worker->node = NULL;

    worker->name = -1;
    core_bitmap_set_bit_uint32_t(&worker->flags, FLAG_DEAD);

    core_memory_pool_destroy(&worker->ephemeral_memory);
    core_memory_pool_destroy(&worker->outbound_message_memory_pool);

    thorium_priority_assigner_destroy(&worker->assigner);
}