<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dlfcn.h>
#include <sys/prctl.h>
#include <pthread.h>
#include <signal.h>
#include <time.h>

#include "opro.h"
#include "load.h"

int finish = 0;
#define NUM_THREADS 5
pthread_t threads[NUM_THREADS];
pthread_t threads_lazy[NUM_THREADS];
pthread_t threads_wob[NUM_THREADS];

void rate_limit(int milliseconds)
{
    long step_ns = milliseconds * 1000000;
    struct timespec t;
    clock_gettime(CLOCK_REALTIME, &t);
    long sleep_ns = step_ns - (t.tv_nsec % step_ns);
    t.tv_sec = 0;
    t.tv_nsec = sleep_ns;
    nanosleep(&t, NULL);    
}

void work_lazy(void* arg)
{
    while (!finish)
        rate_limit(100);
}

void work(void* arg)
{
    while (!finish)
    {
        // do some work
        int i;
        for (i = 0; i < 100; i++)
            free(malloc(0x1000));
        // rate limit
        rate_limit(10);
    }
}

void kill_test(int sig)
{
    load_stop(&finish, NUM_THREADS, threads);
    load_stop(&finish, NUM_THREADS, threads_lazy);
    load_stop(&finish, NUM_THREADS, threads_wob);
}

void main()
{
    pid_t pid = fork();
    if (pid == 0)
    {
        printf("main() entry, pid: %d\n", getpid());
        // opro start
        opro_test_unwind();
        opro_ignore_address(load_wob_address_get);
        opro_start("libload.so", 10);<commit_msg>better workload on android (more CPU'y)<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dlfcn.h>
#include <sys/prctl.h>
#include <pthread.h>
#include <signal.h>
#include <time.h>

#include "opro.h"
#include "load.h"

int finish = 0;
#define NUM_THREADS 5
pthread_t threads[NUM_THREADS];
pthread_t threads_lazy[NUM_THREADS];
pthread_t threads_wob[NUM_THREADS];

void rate_limit(int milliseconds)
{
    long step_ns = milliseconds * 1000000;
    struct timespec t;
    clock_gettime(CLOCK_REALTIME, &t);
    long sleep_ns = step_ns - (t.tv_nsec % step_ns);
    t.tv_sec = 0;
    t.tv_nsec = sleep_ns;
    nanosleep(&t, NULL);    
}

void work_lazy(void* arg)
{
    while (!finish)
        rate_limit(100);
}

int gt;
void work(void* arg)
{
    while (!finish)
    {
        // do some work
        int i;
        int t = 0;
        for (i = 0; i < 1000000; i++)
            t += i;
        gt = t;
        // rate limit
        rate_limit(10);
    }
}

void kill_test(int sig)
{
    load_stop(&finish, NUM_THREADS, threads);
    load_stop(&finish, NUM_THREADS, threads_lazy);
    load_stop(&finish, NUM_THREADS, threads_wob);
}

void main()
{
    pid_t pid = fork();
    if (pid == 0)
    {
        printf("main() entry, pid: %d\n", getpid());
        // opro start
        opro_test_unwind();
        opro_ignore_address(load_wob_address_get);
        opro_start("libload.so", 10);
{'fraction_non_alphanumeric': 0.14084507042253522, 'fraction_numerical': 0.01950162513542795, 'mean_word_length': 2.884992987377279, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3562409', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1054, 'n_words': 236}