Exemple #1
0
MyWidget::MyWidget (QWidget * parent):QWidget (parent)
{

    Print_Version_Information();

    //
    //Print_Information_Processor ();
    bool cpuNehalem, cpuSandybridge, cpuIvybridge, cpuHaswell;
    Print_Information_Processor (&cpuNehalem, &cpuSandybridge, &cpuIvybridge, &cpuHaswell);

    Test_Or_Make_MSR_DEVICE_FILES ();

    Construct_Socket_Information_in_GUI(&numCPUs);

    char processor_str[100];
//    printf("MyWidget: Num Processors %d\n",numCPUs);
    int  i;

    for (i = 0; i < (int)numCPUs; i++)
    {
        C0_l[i] = new QProgressBar;
        C0_l[i]->setMaximum (99);
        C0_l[i]->setMinimum (0);
        C1_l[i] = new QProgressBar;
        C1_l[i]->setMaximum (99);
        C1_l[i]->setMinimum (0);
        C3_l[i] = new QProgressBar;
        C3_l[i]->setMaximum (99);
        C3_l[i]->setMinimum (0);
        C6_l[i] = new QProgressBar;
        C6_l[i]->setMaximum (99);
        C6_l[i]->setMinimum (0);
        Freq_[i] = new QLabel (tr (""));
    }

    QGridLayout * layout1 = new QGridLayout;

    curr_numCPUs = numCPUs;
    for (i = 0; i < (int)numCPUs; i++)
    {
        layout1->addWidget (C0_l[i], i + 1, 1);
        layout1->addWidget (C1_l[i], i + 1, 2);
        layout1->addWidget (C3_l[i], i + 1, 3);
        layout1->addWidget (C6_l[i], i + 1, 4);
    }

    C0 = new QLabel (tr ("C0"));
    C0->setAlignment (Qt::AlignCenter);
    C1 = new QLabel (tr ("C1"));
    C1->setAlignment (Qt::AlignCenter);
    C3 = new QLabel (tr ("C3"));
    C3->setAlignment (Qt::AlignCenter);
    C6 = new QLabel (tr ("C6"));
    C6->setAlignment (Qt::AlignCenter);

    snprintf(processor_str, 100, "Core-1 [id:%d,socket:%d]",core_list[0],socket_list[0]);
    ProcNames[0] = new QLabel (tr (processor_str));

    snprintf(processor_str, 100, "Core-2 [id:%d,socket:%d]",core_list[1],socket_list[1]);
    ProcNames[1] = new QLabel (tr (processor_str));

    snprintf(processor_str, 100, "Core-3 [id:%d,socket:%d]",core_list[2],socket_list[2]);
    ProcNames[2] = new QLabel (tr (processor_str));

    snprintf(processor_str, 100, "Core-4 [id:%d,socket:%d]",core_list[3],socket_list[3]);
    ProcNames[3] = new QLabel (tr (processor_str));

    snprintf(processor_str, 100, "Core-5 [id:%d,socket:%d]",core_list[4],socket_list[4]);
    ProcNames[4] = new QLabel (tr (processor_str));

    snprintf(processor_str, 100, "Core-6 [id:%d,socket:%d]",core_list[5],socket_list[5]);
    ProcNames[5] = new QLabel (tr (processor_str));

    snprintf(processor_str, 100, "Core-7 [id:%d,socket:%d]",core_list[6],socket_list[6]);
    ProcNames[6] = new QLabel (tr (processor_str));

    snprintf(processor_str, 100, "Core-8 [id:%d,socket:%d]",core_list[7],socket_list[7]);
    ProcNames[7] = new QLabel (tr (processor_str));

    snprintf(processor_str, 100, "Core-9 [id:%d,socket:%d]",core_list[8],socket_list[8]);
    ProcNames[8] = new QLabel (tr (processor_str));

    snprintf(processor_str, 100, "Core-10 [id:%d,socket:%d]",core_list[9],socket_list[9]);
    ProcNames[9] = new QLabel (tr (processor_str));

    snprintf(processor_str, 100, "Core-11 [id:%d,socket:%d]",core_list[10],socket_list[10]);
    ProcNames[10] = new QLabel (tr (processor_str));

    snprintf(processor_str, 100, "Core-12 [id:%d,socket:%d]",core_list[11],socket_list[11]);
    ProcNames[11] = new QLabel (tr (processor_str));

    StatusMessage0 = new QLabel (tr ("Wait"));
    Curr_Freq0 = new QLabel (tr ("Wait"));

    if ( (socket_0.num_physical_cores > 0) && (socket_1.num_physical_cores > 0)) {
        StatusMessage1 = new QLabel (tr ("Wait"));
        Curr_Freq1 = new QLabel (tr ("Wait"));
    }

    for (i = 0; i < (int)numCPUs; i++) {
        layout1->addWidget (ProcNames[i], i + 1, 0);
    }

    layout1->addWidget (C0, 0, 1);
    layout1->addWidget (C1, 0, 2);
    layout1->addWidget (C3, 0, 3);
    layout1->addWidget (C6, 0, 4);

    for (i = 0; i < (int)numCPUs; i++)
        layout1->addWidget (Freq_[i], i + 1, 5);

    layout1->addWidget (StatusMessage0, numCPUs + 1, 4);
    layout1->addWidget (Curr_Freq0, numCPUs + 1, 5);
    if ( (socket_0.num_physical_cores > 0) && (socket_1.num_physical_cores > 0)) {
        layout1->addWidget (StatusMessage1, numCPUs + 2, 4);
        layout1->addWidget (Curr_Freq1, numCPUs + 2, 5);
    }
    QTimer *timer = new QTimer (this);
    connect (timer, SIGNAL (timeout ()), this, SLOT (UpdateWidget ()));
    timer->start (1000);

    mythread = new MyThread ();
    mythread->start ();

    setLayout (layout1);
}
Exemple #2
0
int main (int argc, char **argv)
{
    atexit(atexit_runsttysane);

    char log_file_name[MAX_FILENAME_LENGTH], log_file_name2[MAX_FILENAME_LENGTH+3];
    prog_options.logging=0; //0=no logging, 1=logging, 2=appending, 3=stdout
    prog_options.debug = true;

    struct cpu_heirarchy_info chi;
    struct cpu_socket_info socket_0={.max_cpu=0, .socket_num=0, .processor_num={-1,-1,-1,-1,-1,-1,-1,-1}};
    struct cpu_socket_info socket_1={.max_cpu=0, .socket_num=1, .processor_num={-1,-1,-1,-1,-1,-1,-1,-1}};

    //////////////////// GET ARGUMENTS //////////////////////
    int c;
    //char *cvalue = NULL;
    //static bool logging_val_append=false, logging_val_replace=false;
    bool presupplied_socket_info = false;

    static struct option long_options[]=
    {
        {"write", required_argument, 0, 'w'},
        {"socket0", required_argument,0 ,'z'},
        {"socket1", required_argument,0 ,'y'},
        {"logfile", required_argument,0,'l'},
        {"help", no_argument, 0, 'h'},
        {"nogui", no_argument, 0, 'n'},
        {"stdout", no_argument, 0, 's'},
        {"run-times", required_argument, 0, 't'}
    };

    prog_options.logging = 0;
    while(1)
    {
        int option_index = 0;
        c = getopt_long(argc, argv,"w:z:y:l:hn", long_options, &option_index);
        if (c==-1)
            break;
        switch(c)
        {
            case 'z':
                socket_0_num = atoi(optarg);
                presupplied_socket_info = true;
                printf("Socket_0 information will be about socket %d\n", socket_0.socket_num);
                break;
            case 'y':
                socket_1_num = atoi(optarg);
                presupplied_socket_info = true;
                printf("Socket_1 information will be about socket %d\n", socket_1.socket_num);
                break;
            case 'w':
                //printf("write options specified %s\n", optarg);
                if (strcmp("l",optarg)==0)
                {
                    prog_options.logging = 1;
                    printf("Logging is ON and set to replace\n");
                }
                if (strcmp("a",optarg)==0)
                {
                    prog_options.logging = 2;
                    printf("Logging is ON and set to append\n");
                }
                break;
            case 'l':
                strncpy(log_file_name, optarg, MAX_FILENAME_LENGTH-3);
                strcpy(log_file_name2, log_file_name);
                strcat(log_file_name2, "_%d");
                CPU_FREQUENCY_LOGGING_FILE_single = log_file_name;
                CPU_FREQUENCY_LOGGING_FILE_dual = log_file_name2;
                printf("Logging frequencies to %s for single sockets, %s for dual sockets(0,1 for multiple sockets)\n", CPU_FREQUENCY_LOGGING_FILE_single, CPU_FREQUENCY_LOGGING_FILE_dual);
                break;

            case 'n':
                use_ncurses = false;
                printf("Not Spawning the GUI\n");
                break;
            case 's':
                // stdout mode, that prints statistics to standard output
                // disable ncurses
                use_ncurses = false;
                // enable stdout
                prog_options.debug = false;
                // setup standard  output files
                CPU_FREQUENCY_LOGGING_FILE_single = "/dev/stdout";
                CPU_FREQUENCY_LOGGING_FILE_dual = "/dev/stdout";
                CSTATE_LOGGING_FILE_single = "/dev/null";
                CSTATE_LOGGING_FILE_dual = "/dev/null";
                // append logs
                prog_options.logging = 3;
                break;
            case 't':
                run_times = atoi(optarg);
                if(prog_options.debug)
                    printf("Running %d times\n", run_times);
                // disable ncurses
                use_ncurses = false;
                break;
            case 'h':
                printf("\ni7z Tool Supports the following functions:\n");
                printf("Append to a log file:  ");
                printf("%c[%d;%d;%dm./i7z --write a ", 0x1B,1,31,40);
                printf("%c[%dm[OR] ",0x1B,0);
                printf("%c[%d;%d;%dm./i7z -w a\n", 0x1B,1,31,40);
                printf("%c[%dm",0x1B,0);

                printf("Replacement instead of Append:  ");
                printf("%c[%d;%d;%dm./i7z --write l ", 0x1B,1,31,40);
                printf("%c[%dm[OR]", 0x1B,0);
                printf(" %c[%d;%d;%dm./i7z -w l\n", 0x1B,1,31,40);
                printf("%c[%dm",0x1B,0);

                printf("Default log file name is %s (single socket) or %s (dual socket)\n", CPU_FREQUENCY_LOGGING_FILE_single, CPU_FREQUENCY_LOGGING_FILE_dual);
                printf("Specifying a different log file: ");
                printf("%c[%d;%d;%dm./i7z --logfile filename ", 0x1B,1,31,40);
                printf("%c[%dm[OR] ", 0x1B,0);
                printf("%c[%d;%d;%dm./i7z -l filename\n", 0x1B,1,31,40);
                printf("%c[%dm",0x1B,0);
                printf("Specifying a particular socket to print: %c[%d;%d;%dm./i7z --socket0 X \n", 0x1B,1,31,40);
                printf("%c[%dm",0x1B,0);
                printf("In order to print to a second socket use: %c[%d;%d;%dm./i7z --socket1 X \n", 0x1B,1,31,40);
                printf("%c[%dm",0x1B,0);
                printf("To turn the ncurses GUI off use: %c[%d;%d;%dm./i7z --nogui\n", 0x1B, 1, 31, 40);
                printf("%c[%dm",0x1B,0);
                printf("Print output to stdout rather than a log file: %c[%d;%d;%dm./i7z --stdout\n", 0x1B, 1, 31, 40);
                printf("%c[%dm",0x1B,0);
                printf("Run n times and exit: %c[%d;%d;%dm./i7z --run-times n\n", 0x1B, 1, 31, 40);
                printf("%c[%dm",0x1B,0);
                printf("Example: To print for two sockets and also change the log file %c[%d;%d;%dm./i7z --socket0 0 --socket1 1 -logfile /tmp/logfilei7z -w l\n", 0x1B, 1, 31, 40);
                printf("%c[%dm",0x1B,0);

                exit(1);
                break;
        }
    }

    if (prog_options.debug) {
        Print_Version_Information();
        Print_Information_Processor (&prog_options.i7_version.nehalem, &prog_options.i7_version.sandy_bridge, &prog_options.i7_version.ivy_bridge, &prog_options.i7_version.haswell);
    }

//	printf("nehalem %d, sandy brdige %d\n", prog_options.i7_version.nehalem, prog_options.i7_version.sandy_bridge);

    Test_Or_Make_MSR_DEVICE_FILES ();
    modprobing_msr();

    /*
    prog_options.logging = 0;
    if (logging_val_replace){
        prog_options.logging = 1;
        printf("Logging is ON and set to replace\n");
    }
    if (logging_val_append){
        prog_options.logging = 2;
        printf("Logging is ON and set to append\n");
    }
    */
    /*
    while( (c=getopt(argc,argv,"w:")) !=-1){
		cvalue = optarg;
    	//printf("argument %c\n",c);
    	if(cvalue == NULL){
    	    printf("With -w option, requires an argument for append or logging\n");
    	    exit(1);
    	}else{
     	    //printf("         %s\n",cvalue);
     	    if(strcmp(cvalue,"a")==0){
     		printf("Appending frequencies to %s (single_socket) or cpu_freq_log_dual_(%d/%d).txt (dual socket)\n", CPU_FREQUENCY_LOGGING_FILE_single,0,1);
     		prog_options.logging=2;
     	    }else if(strcmp(cvalue,"l")==0){
     		printf("Logging frequencies to %s (single socket) or cpu_freq_log_dual_(%d/%d).txt (dual socket) \n", CPU_FREQUENCY_LOGGING_FILE_single,0,1);
     		prog_options.logging=1;
     	    }else{
     		printf("Unknown Option, ignoring -w option.\n");
     		prog_options.logging=0;
     	    }
     	    sleep(3);
        }
    }
    */
    ///////////////////////////////////////////////////////////

    construct_CPU_Heirarchy_info(&chi);
    construct_sibling_list(&chi);
    construct_socket_information(&chi, &socket_0, &socket_1, socket_0_num, socket_1_num);
    if(prog_options.debug) {
        print_CPU_Heirarchy(chi);
        print_socket_information(&socket_0);
        print_socket_information(&socket_1);
    }

    if (!use_ncurses){
        if(prog_options.debug)
            printf("GUI has been Turned OFF\n");
        //print_options(prog_options);
    } else {
        printf("GUI has been Turned ON\n");
        init_ncurses();
        //print_options(prog_options);
        /*
        if (prog_options.logging ==0)
        {
            printf("Logging is OFF\n");
        } else {
            printf("Logging is ON\n");
            if (prog_options.cstatelogging) {
                printf("Cstate logging is enabled\n");
            }
            if (prog_options.templogging) {
                printf("temp logging is enabled\n");
            }
        }
        */
    }

    // Force dual-socket code
    Dual_Socket();
    return EXIT_SUCCESS;
}