void VMProc::getUsageOfVM(long &sys_time, long& user_time, unsigned long &max_image, unsigned long& rss, unsigned long& pss, bool &pss_available) { updateUsageOfVM(); sys_time = m_vm_exited_pinfo.sys_time + m_vm_alive_pinfo.sys_time; user_time = m_vm_exited_pinfo.user_time + m_vm_alive_pinfo.user_time; rss = (m_vm_exited_pinfo.rssize > m_vm_alive_pinfo.rssize) ? m_vm_exited_pinfo.rssize : m_vm_alive_pinfo.rssize; #if HAVE_PSS pss = (m_vm_exited_pinfo.pssize > m_vm_alive_pinfo.pssize) ? m_vm_exited_pinfo.pssize : m_vm_alive_pinfo.pssize; pss_available = m_vm_exited_pinfo.pssize_available || m_vm_alive_pinfo.pssize_available; #else pss_available = false; pss = 0; #endif #if defined(WIN32) max_image = (m_vm_exited_pinfo.rssize > m_vm_alive_pinfo.rssize) ? m_vm_exited_pinfo.rssize : m_vm_alive_pinfo.rssize; #else max_image = (m_vm_exited_pinfo.imgsize > m_vm_alive_pinfo.imgsize) ? m_vm_exited_pinfo.imgsize : m_vm_alive_pinfo.imgsize; #endif }
void VMProc::killProcessForVM() { if( m_vm_pid > 0 ) { updateUsageOfVM(); dprintf(D_FULLDEBUG,"Sending SIGKILL to process for VM\n"); daemonCore->Send_Signal(m_vm_pid, SIGKILL); } return; }
void VMStarterInfo::getUsageOfVM(ProcFamilyUsage &usage) { bool updated = updateUsageOfVM(); usage.user_cpu_time = m_vm_exited_pinfo.user_time + m_vm_alive_pinfo.user_time; usage.sys_cpu_time = m_vm_exited_pinfo.sys_time + m_vm_alive_pinfo.sys_time; if( updated ) { usage.percent_cpu = m_vm_alive_pinfo.cpuusage; }else usage.percent_cpu = 0; unsigned long exited_max_image = get_image_size(m_vm_exited_pinfo); unsigned long alive_max_image = get_image_size(m_vm_alive_pinfo); usage.max_image_size = (exited_max_image > alive_max_image ) ? exited_max_image : alive_max_image; if( updated ) { usage.total_image_size = m_vm_alive_pinfo.imgsize; usage.total_resident_set_size = m_vm_alive_pinfo.rssize; #if HAVE_PSS usage.total_proportional_set_size = m_vm_alive_pinfo.pssize; usage.total_proportional_set_size = m_vm_alive_pinfo.pssize_available; #endif }else { usage.total_image_size = 0; usage.total_resident_set_size = 0; #if HAVE_PSS usage.total_proportional_set_size = 0; usage.total_proportional_set_size = false; #endif } if( IsDebugVerbose(D_LOAD) ) { dprintf( D_LOAD, "VMStarterInfo::getUsageOfVM(): Percent CPU usage " "for VM process with pid %u is: %f\n", m_vm_pid, usage.percent_cpu ); } }
void VMProc::setVMPID(int vm_pid) { if( m_vm_pid == vm_pid ) { // PID doesn't change return; } dprintf(D_FULLDEBUG,"PID for VM is changed from [%d] to [%d]\n", m_vm_pid, vm_pid); //PID changes m_vm_pid = vm_pid; // Add the old usage to m_vm_exited_pinfo m_vm_exited_pinfo.sys_time += m_vm_alive_pinfo.sys_time; m_vm_exited_pinfo.user_time += m_vm_alive_pinfo.user_time; if( m_vm_alive_pinfo.rssize > m_vm_exited_pinfo.rssize ) { m_vm_exited_pinfo.rssize = m_vm_alive_pinfo.rssize; } if( m_vm_alive_pinfo.imgsize > m_vm_exited_pinfo.imgsize ) { m_vm_exited_pinfo.imgsize = m_vm_alive_pinfo.imgsize; } // Reset usage of the current process for VM memset(&m_vm_alive_pinfo, 0, sizeof(m_vm_alive_pinfo)); // Get initial usage of the process updateUsageOfVM(); MyString pid_string; pid_string += (int)m_vm_pid; // Report this PID to local startd reportVMInfoToStartd(VM_UNIV_VMPID, pid_string.Value()); }
bool VMProc::process_vm_status_result(Gahp_Args *result_args) { // status result // argv[1] : should be 0, it means success. // From argv[2] : representing some info about VM if( !result_args || ( result_args->argc < 3) ) { dprintf(D_ALWAYS, "Bad Result for VM status\n"); vm_status_error(); return true; } int tmp_argv = (int)strtol(result_args->argv[1], (char **)NULL, 10); if( tmp_argv != 0 || !strcasecmp(result_args->argv[2], NULLSTRING)) { dprintf(D_ALWAYS, "Received VM status, result(%s,%s)\n", result_args->argv[1], result_args->argv[2]); vm_status_error(); return true; } // We got valid info about VM MyString vm_status; float cpu_time = 0; int vm_pid = 0; MyString vm_ip; MyString vm_mac; MyString tmp_name; MyString tmp_value; MyString one_arg; int i = 2; m_vm_utilization = 0.0; for( ; i < result_args->argc; i++ ) { one_arg = result_args->argv[i]; one_arg.trim(); if(one_arg.IsEmpty()) { continue; } parse_param_string(one_arg.Value(), tmp_name, tmp_value, true); if( tmp_name.IsEmpty() || tmp_value.IsEmpty() ) { continue; } if(!strcasecmp(tmp_name.Value(), VMGAHP_STATUS_COMMAND_STATUS)) { vm_status = tmp_value; }else if( !strcasecmp(tmp_name.Value(), VMGAHP_STATUS_COMMAND_CPUTIME) ) { cpu_time = (float)strtod(tmp_value.Value(), (char **)NULL); if( cpu_time <= 0 ) { cpu_time = 0; } }else if( !strcasecmp(tmp_name.Value(), VMGAHP_STATUS_COMMAND_PID) ) { vm_pid = (int)strtol(tmp_value.Value(), (char **)NULL, 10); if( vm_pid <= 0 ) { vm_pid = 0; } }else if( !strcasecmp(tmp_name.Value(), VMGAHP_STATUS_COMMAND_MAC) ) { vm_mac = tmp_value; }else if( !strcasecmp(tmp_name.Value(), VMGAHP_STATUS_COMMAND_IP) ) { vm_ip = tmp_value; }else if ( !strcasecmp(tmp_name.Value(),VMGAHP_STATUS_COMMAND_CPUUTILIZATION) ) { /* This is here for vm's which are spun via libvirt*/ m_vm_utilization = (float)strtod(tmp_value.Value(), (char **)NULL); } } if( vm_status.IsEmpty() ) { // We don't receive status of VM dprintf(D_ALWAYS, "No VM status in result\n"); vm_status_error(); return true; } if( vm_mac.IsEmpty() == false ) { setVMMAC(vm_mac.Value()); } if( vm_ip.IsEmpty() == false ) { setVMIP(vm_ip.Value()); } int old_status_error_count = m_status_error_count; // Reset status error count to 0 m_status_error_count = 0; if( !strcasecmp(vm_status.Value(),"Stopped") ) { dprintf(D_ALWAYS, "Virtual machine is stopped\n"); is_suspended = false; m_is_soft_suspended = false; is_checkpointed = false; // VM finished. setVMPID(0); // destroy the vmgahp server cleanup(); return false; }else { dprintf(D_FULLDEBUG, "Virtual machine status is %s, utilization is %f\n", vm_status.Value(), m_vm_utilization ); if( !strcasecmp(vm_status.Value(), "Running") ) { is_suspended = false; m_is_soft_suspended = false; is_checkpointed = false; if( cpu_time > 0 ) { // update statistics for Xen m_vm_cputime = cpu_time; } if( vm_pid > 0 ) { setVMPID(vm_pid); } // Update usage of process for a VM updateUsageOfVM(); }else if( !strcasecmp(vm_status.Value(), "Suspended") ) { if( !is_checkpointed ) { is_suspended = true; } m_is_soft_suspended = false; // VM is suspended setVMPID(0); }else if( !strcasecmp(vm_status.Value(), "SoftSuspended") ) { is_suspended = true; m_is_soft_suspended = true; is_checkpointed = false; }else { dprintf(D_ALWAYS, "Unknown VM status: %s\n", vm_status.Value()); // Restore status error count m_status_error_count = old_status_error_count; vm_status_error(); } } return true; }