Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:11.4
CodeAnalyst
ca-fix-su.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File ca-fix-su.patch of Package CodeAnalyst
Index: package/src/ca/utils/ca_oprofile_controller.cpp =================================================================== --- package/src/ca/utils/ca_oprofile_controller.cpp +++ package/src/ca/utils/ca_oprofile_controller.cpp @@ -44,6 +44,9 @@ static int sigkill = 0; static int rmlock = 0; static int reset = 0; +static int load = 0; +static int unload = 0; +static char* devConfig = NULL; enum { OPT_START = 1, @@ -51,19 +54,25 @@ OPT_KILL, OPT_RMLOCK, OPT_RESET, + OPT_LOAD, + OPT_UNLOAD, + OPT_DEVCONFIG, OPT_VERSION, OPT_HELP }; static struct poptOption options[] = { -{ "start" , 's', POPT_ARG_STRING, &start, OPT_START , "", NULL }, -{ "term" , 't', POPT_ARG_NONE, &sigterm, OPT_TERM , "", NULL }, -{ "kill" , 'k', POPT_ARG_NONE, &sigkill, OPT_KILL , "", NULL }, -{ "rmlock" , 'r', POPT_ARG_NONE, &rmlock , OPT_RMLOCK, "", NULL }, -{ "reset" , 'e', POPT_ARG_NONE, &reset, OPT_RESET , "", NULL }, -{ "version" , 'v', POPT_ARG_NONE, NULL, OPT_VERSION , "", NULL }, -{ "help" , 'h', POPT_ARG_NONE, NULL, OPT_HELP , "", NULL }, -{ NULL, 0, 0, NULL, 0, NULL, NULL }, +{ "start" , 's', POPT_ARG_STRING, &start, OPT_START , "", NULL }, +{ "term" , 't', POPT_ARG_NONE, &sigterm, OPT_TERM , "", NULL }, +{ "kill" , 'k', POPT_ARG_NONE, &sigkill, OPT_KILL , "", NULL }, +{ "rmlock" , 'r', POPT_ARG_NONE, &rmlock , OPT_RMLOCK, "", NULL }, +{ "reset" , 'e', POPT_ARG_NONE, &reset , OPT_RESET , "", NULL }, +{ "load-drv" , 'l', POPT_ARG_NONE, &load , OPT_LOAD , "", NULL }, +{ "unload-drv" , 'u', POPT_ARG_NONE, &unload , OPT_UNLOAD, "", NULL }, +{ "dev-config" , 'd', POPT_ARG_STRING, &devConfig, OPT_DEVCONFIG , "", NULL }, +{ "version" , 'v', POPT_ARG_NONE, NULL, OPT_VERSION , "", NULL }, +{ "help" , 'h', POPT_ARG_NONE, NULL, OPT_HELP , "", NULL }, +{ NULL , 0, 0, NULL, 0, NULL, NULL }, }; void show_version() @@ -87,6 +96,10 @@ " -k|--kill Send SIGKILL to Oprofile daemon.\n" " -r|--rmlock Remove Oprofile lock file (/var/lib/oprofile/samples/oprofiled.log).\n" " -e|--reset Delete Oprofile sample files in /var/lib/oprofile/samples/current.\n" + " -l|--load-drv Load OProfile driver.\n" + " -u|--unload-drv Unload OProfile driver.\n" + " -d|--dev_config=<file>:<value>\n" + " Configure OProfile /dev/oprofile/<file> device file.\n" " -v|--version Show version number.\n" " -h|--help Show this message.\n" "\n" @@ -118,6 +131,9 @@ case OPT_KILL: case OPT_RMLOCK: case OPT_RESET: + case OPT_LOAD: + case OPT_UNLOAD: + case OPT_DEVCONFIG: break; case OPT_HELP: show_usage(); @@ -179,6 +195,11 @@ return system("rm -rf /var/lib/oprofile/samples/current/*"); } +int remove_var_lib_oprofile_samples_ca_oprofile_cg() +{ + return system("rm -rf /var/lib/oprofile/samples/ca_oprofile.cg"); +} + int remove_var_lib_oprofile_jitdump_star() { return system("rm -rf /var/lib/oprofile/jitdump/*"); @@ -341,16 +362,67 @@ return ret; } +int device_config(const char * filePath, const char * val, int size) +{ + int ret = -1; + FILE * file = NULL; + string devFile = ("/dev/oprofile/"); + + if (!filePath || !val || !size) + return ret; + + devFile += filePath; + + file = fopen(devFile.c_str(), "w" ); + if (!file) { + perror(devFile.c_str()); + return ret; + } + + ret = fwrite(val, 1, size, file); + + fclose(file); + + return ret; +} + + +int device_config() +{ + // Parse input + string str(devConfig); + + int found = str.find_first_of(":"); + + if (!found) + return -1; + + string path = str.substr(0, found); + string val = str.substr(found+1, string::npos); + + return device_config(path.c_str(), val.c_str(), val.size()); + +} + + int main(int argc, char const * argv[]) { int ret = 1; // Check if root user - if(0 != getuid()){ - fprintf(stderr,"ca_oprofile_controller: Error, must be root.\n"); - goto out; - } + if(0 == getuid()) + goto permissionOk; + /* + *NOTE: + * In sudo approach, we check if this is a root user. + * Only root can run this. + */ + fprintf(stderr,"ca_oprofile_controller: Error, must be root.\n"); + goto out; + +permissionOk: + // Parse options if (0 != (ret = do_options(argc, argv))) { fprintf(stderr,"ca_oprofile_controller: Error, parsing option.\n"); @@ -367,10 +439,12 @@ // Handle Reset if(reset) { if( remove_var_lib_oprofile_samples_current_star() == 0 + && remove_var_lib_oprofile_samples_ca_oprofile_cg() == 0 && remove_var_lib_oprofile_samples_oprofiled_log() == 0 && remove_var_lib_oprofile_jitdump_star() == 0 - && remove_var_lib_oprofile_jit_star() == 0 - && remove_var_lib_oprofile_Java_star() == 0 + // TODO: [Suravee] Clean out this directory when no jitted process running + //&& remove_var_lib_oprofile_jit_star() == 0 + //&& remove_var_lib_oprofile_Java_star() == 0 && mkdir_var_lib_oprofile_samples_current() == 0 && mkdir_var_lib_oprofile_jitdump() == 0 && mkdir_var_lib_oprofile_jit() == 0 @@ -387,6 +461,31 @@ goto out; } + // Handle driver load + if(load) { + string cmd(OP_BINDIR); + cmd += "/opcontrol --init 2> /dev/null > /dev/null"; + ret = system(cmd.c_str()); + goto out; + } + + // Handle driver unload + if(unload) { + string cmd(OP_BINDIR); + cmd += "/opcontrol --deinit 2> /dev/null > /dev/null"; + ret = system(cmd.c_str()); + goto out; + } + + // Handle device file configuration + if (devConfig) { + if((ret = device_config()) <= 0) + fprintf(stderr,"ca_oprofile_controller: Error, Cannot configure /dev/oprofile.\n"); + else + ret = 0; + goto out; + } + // Sending SIGTERM or SIGKILL ret = send_signal(); out: Index: package/src/ca/gui/helperAPI.h =================================================================== --- package/src/ca/gui/helperAPI.h +++ package/src/ca/gui/helperAPI.h @@ -0,0 +1,49 @@ +/* +// CodeAnalyst for Open Source +// Copyright 2002 . 2009 Advanced Micro Devices, Inc. +// You may redistribute this program and/or modify this program under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program is distributed WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED +// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 59 Temple +// Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#ifndef _HELPERAPI_H_ +#define _HELPERAPI_H_ + +#include <qdir.h> + +extern bool folderRemove (const QDir & _d); + +extern void untar_packed_file(QString * packed_path, QString * temp_dir ); + +extern unsigned int rename_files(QString * temp_dir, + QString * op_sample_path, + QString * cpuinfo_path, + QString * dispatched_ops_path); + +extern int getBitness(const char * path); + +extern int ca_exec_command(QStringList & args, + QString & stdOut, + QString & stdErr, + int & status, + bool isBlock = true); + +extern int ca_exec_sudo_command(QStringList & args, + QString & stdOut, + QString & stdErr, + int & status, + bool isBlock = true); + +extern bool cssConversion(QString cgOutput); + +#endif //_HELPERAPI_H_ + Index: package/src/ca/gui/Makefile.am =================================================================== --- package/src/ca/gui/Makefile.am +++ package/src/ca/gui/Makefile.am @@ -134,7 +134,8 @@ EventMaskEncoding.cpp \ CpuAffinityDlg.cpp \ ProcessFilterDlg.cpp \ - NewDiffSessionDlg.cpp + NewDiffSessionDlg.cpp \ + helperAPI.cpp CodeAnalyst_generated_headers= iAboutDlg.h \ Index: package/src/ca/gui/application.cpp =================================================================== --- package/src/ca/gui/application.cpp +++ package/src/ca/gui/application.cpp @@ -48,6 +48,7 @@ #include "catranslate_gui_display.h" #include "opxmldata_handler.h" #include "config.h" +#include "helperAPI.h" #define _CODEANALYST_ICONS_ #include "xpm.h" @@ -757,8 +758,8 @@ + "This user does not have sufficient permission to run a profile.\n\n" + "Please make sure :\n" + " - You are root or a member of \"amdca\" group.\n" - + " - amdca group has the permission to sudo \n\n" - + " "+ CA_SBIN_DIR + "/ca_oprofile_controller\n\n" + + " - amdca group has the permission to run\n\n" + + " sudo " + CA_SBIN_DIR + "/ca_oprofile_controller\n\n" + "Please use \"ca_user_manager\" to manage CodeAnalyst users."; QMessageBox::critical(this, "CodeAnalyst Error", errMsg); return; @@ -767,14 +768,15 @@ /* 2. Check to make sure that CodeAnalyst service is setup and ready. * otherwise, we will try to start it. */ - if (!m_opIf.codeanalyst_service_status() && !m_opIf.codeanalyst_service_start()) + if (!m_opIf.checkOprofileDriverStatus() && !m_opIf.loadOprofileDriver()) { QMessageBox::critical (this, "Error starting profile", - "Checking CodeAnalyst service (/etc/init.d/codeanalyst status)\n" - "returns failure, and an attempt to start CodeAnalyst service\n" - "(/etc/init.d/codeanalyst start) also failed.\n." + "Checking OProfile driver (/dev/oprofile) returns failure\n" + " and an attempt to load the driver also failed.\n." "CodeAnalyst will not be able to run profile.\n\n." - "Please make sure to start the service as root.\n." + "Please make sure :\n" + " - The user is a member of group amdca\n." + " - OProfle driver is installed and can be started properly\n." ); return; } @@ -896,21 +898,21 @@ // check if driver is ok if (!m_opIf.checkMuxSupportInDriver() || m_opIf.getNumEventCounters() == MAX_EVENTNUM) { - QMessageBox::warning(NULL, "CodeAnalyst Warning",QString("Warning:\n\n") + - + "Current CodeAnalyst Kernel Module does not support event multiplexing.\n" - + "CodeAnalyst will start profile only with events in the first group.\n\n" - + "Please update the CodeAnalyst Kernel Module in order to profile more than " - + "one event group."); + QMessageBox::warning(this, "CodeAnalyst Warning",QString("Warning:\n\n") + + + "Current CodeAnalyst Kernel Module does not support event multiplexing.\n" + + "CodeAnalyst will start profile only with events in the first group.\n\n" + + "Please update the CodeAnalyst Kernel Module in order to profile more than " + + "one event group."); static_cast <EBP_OPTIONS *>(m_pSession)->countEventGroups = 1; } // check if daemon is ok if (!m_opIf.checkMuxSupportInDaemon()) { - QMessageBox::warning(NULL, "CodeAnalyst Warning",QString("Warning:\n\n") + - + "Current OProfile daemon does not support event multiplexing.\n" - + "CodeAnalyst will start profile only with events in the first group.\n\n" - + "Please use CodeAnalyst provided OProfile in order to profile more than " - + "one event group."); + QMessageBox::warning(this, "CodeAnalyst Warning",QString("Warning:\n\n") + + + "Current OProfile daemon does not support event multiplexing.\n" + + "CodeAnalyst will start profile only with events in the first group.\n\n" + + "Please use CodeAnalyst provided OProfile in order to profile more than " + + "one event group."); static_cast <EBP_OPTIONS *>(m_pSession)->countEventGroups = 1; } } @@ -2748,13 +2750,21 @@ if (oie_rt == OIE_OK) { if(m_pSession->Trigger == EVENT_TRIGGER) - oie_rt = m_opIf.do_start_daemon (novmlinux, vmlinux_dir, - buffer_size, watershed_size, cpu_buf_size, - ca_active_profiling, pEventSession->msMpxInterval); + oie_rt = m_opIf.do_start_daemon (novmlinux, + vmlinux_dir, + buffer_size, + watershed_size, + cpu_buf_size, + ca_active_profiling, + pEventSession->msMpxInterval); else - oie_rt = m_opIf.do_start_daemon (novmlinux, vmlinux_dir, - buffer_size, watershed_size, cpu_buf_size, - ca_active_profiling,0); + oie_rt = m_opIf.do_start_daemon (novmlinux, + vmlinux_dir, + buffer_size, + watershed_size, + cpu_buf_size, + ca_active_profiling, + 0); } Index: package/src/ca/gui/helperAPI.cpp =================================================================== --- package/src/ca/gui/helperAPI.cpp +++ package/src/ca/gui/helperAPI.cpp @@ -0,0 +1,372 @@ +/* +// CodeAnalyst for Open Source +// Copyright 2002 . 2009 Advanced Micro Devices, Inc. +// You may redistribute this program and/or modify this program under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program is distributed WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED +// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 59 Temple +// Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#include "config.h" +#include "helperAPI.h" + +#include <stdlib.h> +#include <qstring.h> +#include <qstringlist.h> +#include <qfileinfo.h> +#include <qdir.h> +#include <qprocess.h> +#include <qtimer.h> +#include <qmessagebox.h> + +#include <elf.h> + +#define PACKED_DIR_NAME "capacked" + +/* +* folderRemove: +* Recursive contents within the folder and the folder +* itself. +* It is the same code from oprofile_interface.cpp +*/ +bool folderRemove (const QDir & _d) +{ + QDir d = _d; + + QStringList entries = d.entryList(QDir::All|QDir::Hidden); + QStringList::Iterator it = entries.begin(); + + for (; it != entries.end (); ++it) + { + if (*it == "." || *it == "..") + continue; + QFileInfo info (d, *it); + if (info.isDir ()) + { + if (!folderRemove (QDir (info.filePath ()))) + return false; + } + else + { + d.remove (info.filePath ()); + } + } + + QString name = d.dirName (); + + if (!d.cdUp ()) + return false; + + d.rmdir (name); + return true; +} + +void untar_packed_file(QString * packed_path, QString * temp_dir ) +{ + QDir dir; + if (!QFile::exists(*packed_path)) { + return; + } + + srand(time(0)); + temp_dir->sprintf("/tmp/CA%ld/", random()); + dir.mkdir(*temp_dir); + + // todo hook the output to the dialog + // todo use a randomly generated directory + QString command = "tar zxf " + *packed_path + " -C " + *temp_dir; + system(command.data()); +} + + +void mkdir_p(QString & absPath) +{ + QStringList list = QStringList::split("/", absPath); + QStringList::iterator it = list.begin(); + + QString dir_path = "/"; + for (; it != list.end(); ++it) { + dir_path = dir_path + (*it) + "/"; + QDir dir(dir_path); + + if (!dir.exists()) { + if (!dir.mkdir(dir_path)) + qDebug("mkdir failed"); + } + + } +} + + +void copy_files(QFileInfo & info, QString & dest_dir) +{ + // Copy any non-directory file to the new path + QDir dir = QDir(info.filePath()); + dir.setFilter(QDir::Files); + QStringList file_list = dir.entryList(); + QStringList::Iterator itFile = file_list.begin(); + for (; itFile != file_list.end(); ++itFile) { + QFileInfo info(dir, (*itFile)); + + QString command = "cp \"" + info.absFilePath() + "\" \"" + dest_dir + "\""; + + system(command.data()); + } +} + + +void recurse_dirs(QString & parent_dir_str, + QString & dest_dir_str, + QString & subs_dir, + bool prev_dep) +{ + QDir current_dir = QDir(parent_dir_str); + + current_dir.setFilter(QDir::Dirs); + QStringList old_dir_list = current_dir.entryList(); + QStringList::Iterator it = old_dir_list.begin(); + + for (; it != old_dir_list.end(); ++it) { + bool dep = false; + if (*it == "." || *it == "..") + continue; + + QFileInfo info(current_dir, *it); + QString path = info.filePath(); + + QString temp = dest_dir_str + "/" + *it; + + if ((*it).contains("{dep}")) + dep = true; + else if (((*it).contains("{root}") || (*it).contains("{kern}")) + && prev_dep == true) + temp += subs_dir; + else + dep =false; + + mkdir_p(temp); + copy_files(info, temp); + recurse_dirs(path, temp, subs_dir, dep); + } +} + + +unsigned int rename_files(QString * temp_dir, + QString * op_sample_path, + QString * cpuinfo_path, + QString * dispatched_ops_path) +{ + //todo capacked is hard coded right now. + QString top_dir = *temp_dir; + QString op_current_dir_str = *temp_dir + PACKED_DIR_NAME + "/current"; + QDir op_current_dir(op_current_dir_str ); + + // Move the sample file to correct directory structure + // For example: sample files in + // /tmp/CA_982/capacked/current/{root}/bin/basename + // needs to be moved to + // /tmp/CA_982/capacked/current/{root}/tmp/CA_982/capacked/binary/bin/basename/ + + // Since we will be recursing capacked/current directory tree tree + // the new structure is crecated at at capacked/new_current + QString dest_topdir_str = top_dir + "capacked/samples/current/{root}" + + *temp_dir + "capacked/binary"; + + *op_sample_path = top_dir + "capacked/samples/current/"; + + *cpuinfo_path = top_dir + "capacked/cpuinfo"; + + *dispatched_ops_path = top_dir + "capacked/cainfo/dispatched_ops"; + + QString subs_dir = *temp_dir + "capacked/binary/{root}/"; + + // Loop through the original directory structure and create + // correspondent directory under the new directory tree structure + recurse_dirs(op_current_dir_str, dest_topdir_str, subs_dir, false); + + return 0; +} + + +int getBitness(const char * path) +{ + char elf_header[EI_NIDENT]; + FILE *fp; + int ret = -1; + + if (!path) + goto out; + + fp = fopen(path, "r"); + + /** + * The reporting libraries does not return correct path + * of kernel module under 2.6.1. This function will not + * under this situation. + */ + if (NULL == fp) + goto out; + + fread(&elf_header, 16, 1, fp); + if (ferror(fp)) { + fclose (fp); + goto out; + } + fclose(fp); + + if (0 != strncmp(elf_header, ELFMAG, SELFMAG)) + goto out; + + switch (elf_header[EI_CLASS]) { + case ELFCLASS32: + ret = 32; + break; + case ELFCLASS64: + ret = 64; + break; + } +out: + return ret; + +} + + +int ca_exec_command (QStringList & args, + QString & stdOut, + QString & stdErr, + int & status, + bool isBlock) +{ + int rt = -1; + + QProcess * proc = new QProcess(); + if (!proc) + goto out; + + proc->setArguments (args); + +// fprintf(stderr,"ca_exec_command = %s\n", proc->arguments().join(" ").ascii()); + + if(!proc->start ()) { + goto out; + } + + // Since the process being launch are non-blocking daemon, + // sysctl, mknod, etc, just wait for the command to finish + while (proc->isRunning ()) { + if (!isBlock) + break; + } + + // Get exit status/stdOut/stdErr + status = proc->exitStatus(); + stdErr = QString(proc->readStderr()); + stdOut = QString(proc->readStdout()); + + // Check for normal Exit + if (proc->normalExit () && status == 0) + rt = 0; +out: + if (proc) + delete proc; + return rt; +} + + +int ca_exec_sudo_command (QStringList & args, + QString & stdOut, + QString & stdErr, + int & status, + bool isBlock) +{ + int rt = -1; + + QStringList cmd; + cmd.append("sudo"); + cmd.append("-S"); + cmd += args; + + QProcess * proc = new QProcess(); + if (!proc) + goto out; + + proc->setArguments (cmd); + +// fprintf(stderr,"ca_exec_command = %s\n", proc->arguments().join(" ").ascii()); + + if(!proc->start ()) { + goto out; + } + + /* NOTE: + * sudo, should never output to the stderr. + * We consider this error and will just exit out. + */ + while (proc->isRunning ()) { + if (!isBlock) + break; + if (proc->readStderr().size() != 0){ + proc->tryTerminate(); + QTimer::singleShot(1000, proc, SLOT(kill())); + break; + } + } + + // Get exit status/stdOut/stdErr + status = proc->exitStatus(); + stdErr = QString(proc->readStderr()); + stdOut = QString(proc->readStdout()); + + // Check for normal Exit + if (proc->normalExit () && status == 0) + rt = 0; +out: + if (proc) + delete proc; + return rt; +} + + +bool cssConversion(QString cgOutput) +{ + // TODO: [Suravee] Currently we directly call cgreport + // since we want cgprocessing code to be a standalone utility. + // and can eliminate the build dependency. We might want + // to integrate this into the gui in the future. + QString cgreportPath = QString(CA_BIN_DIR) + "/cgreport"; + QString cgFile = QString("/var/lib/oprofile/samples/ca_oprofile.cg"); + + if (!QFile::exists (cgreportPath)) { + QMessageBox::critical(NULL, "CSS Conversion Error", + QString("CodeAnalyst could not process call-stack sampling data.\n") + + "Please install " + cgreportPath + ".\n"); + return false; + } + + if (!QFile::exists (cgFile)) { + QMessageBox::critical(NULL, "CSS Conversion Error", + cgFile + " not found.\n" + + "Please rerun the profile with proper CSS setting.\n"); + return false; + } + + QStringList cmd; + cmd.append(cgreportPath); + cmd.append(QString("-i")); + cmd.append(cgFile); + cmd.append(QString("-o")); + cmd.append(cgOutput + "/callgrind.out"); + + QString stdOut, stdErr; + int status; + return (ca_exec_command(cmd, stdOut, stdErr, status) == 0 + && status == 0); +} Index: package/src/ca/gui/oprofile_interface.h =================================================================== --- package/src/ca/gui/oprofile_interface.h +++ package/src/ca/gui/oprofile_interface.h @@ -63,23 +63,27 @@ class oprofile_interface:QObject { public: oprofile_interface (); - int do_start_daemon (bool novmlinux, - QString & vmlinux_dir, - unsigned int buffer_size, - unsigned int buffer_watershed_size, - unsigned int cpu_buf_size, - profiling_types active_profiling, - unsigned int multiplex_interval); + int do_start_daemon (bool vmlinux, + QString & vmlinux_dir, + unsigned int buffer_size, + unsigned int buffer_watershed_size, + unsigned int cpu_buf_size, + profiling_types active_profiling, + unsigned int multiplex_interval); void set_op_events (op_event_property * properties); void set_op_ibs ( op_ibs_property * properties); + bool set_css(unsigned int cssDepth, + unsigned int cssInterval, + unsigned int cssTgid, + unsigned int cssBitness); void do_dump (); void do_kill_daemon (); void do_pause_daemon (); void do_resume_daemon(); - QString get_kernel_range (); + QString get_kernel_range (QString vmlinux_dir); QString & get_std_err(); bool do_setup (); @@ -90,9 +94,9 @@ public: bool havePermissionToProfile(); - bool codeanalyst_service_start(); + bool loadOprofileDriver(); - bool codeanalyst_service_status(); + bool checkOprofileDriverStatus(); int checkIbsSupportInDaemon(); @@ -104,16 +108,32 @@ public: bool checkMuxSupportInDriver(); + bool checkCssSupportInDaemon(); + + bool checkCssSupportInDriver(); + + static bool set_param (QString field, + unsigned long int value, + QString & stdOut, + QString & stdErr, + int & status); + private: + + bool set_param (QString field, unsigned long int value); + + int exec_command (QStringList & args); + + int exec_sudo_command (QStringList & args); + int do_reset(); - int help_start_daemon (bool novmlinux, + int help_start_daemon (bool vmlinux, QString & vmlinux_dir, profiling_types active_profiling); bool get_daemon_pid(unsigned int &pid); - int exec_command (QStringList & args); bool do_sysctl_setup (unsigned int buffer_size, unsigned int buffer_watershed_size, @@ -125,24 +145,25 @@ private: void generate_op_event_arg (QString & arg); - void do_stop (); + bool set_ctr_param (int event, QString field, unsigned long int value); - bool set_ctr_param (int event, QString field, unsigned long long int value); - - bool set_param (QString field, int value); bool do_ebs_setup(profiling_types active_profiling); bool do_ibs_setup(profiling_types active_profiling); QString simplifyPath(QString path); + + bool is_driver_loaded(); + + bool is_oprofilefs_mounted(); private: - QProcess * m_proc; op_ibs_property * m_pIbsProperties; op_event_property m_EventProperties[MAX_EVENTNUM_MULTIPLEXING]; - QString m_StdErr; - QString m_StdOut; + QString m_stderr; + QString m_stdout; + int m_status; int m_numEventCountersAvailable; bool m_isDaemonStarted; unsigned int m_daemon_pid; Index: package/src/ca/gui/oprofile_interface.cpp =================================================================== --- package/src/ca/gui/oprofile_interface.cpp +++ package/src/ca/gui/oprofile_interface.cpp @@ -40,9 +40,9 @@ #include "application.h" #include "config.h" #include "oprofile_interface.h" -//#include "op_config.h" #include "atuneoptions.h" #include "symbolengine.h" +#include "helperAPI.h" namespace OPROFILE_INTERFACE { @@ -66,7 +66,6 @@ using namespace std; // Constructor oprofile_interface::oprofile_interface () { - m_proc=NULL; m_pIbsProperties = NULL; m_isDaemonStarted = false; m_daemon_pid = 0; @@ -82,11 +81,10 @@ oprofile_interface::oprofile_interface ( int oprofile_interface::do_reset () { QStringList cmd; - cmd.append("sudo"); cmd.append(CA_OPROFILE_CONTROLLER); cmd.append("--reset"); - return exec_command (cmd); + return exec_sudo_command (cmd); } @@ -127,94 +125,15 @@ void oprofile_interface::set_op_ibs ( op } -bool oprofile_interface::codeanalyst_service_start() +int oprofile_interface::exec_sudo_command (QStringList & args) { - bool ret = false; - - QStringList cmd; - - cmd.append ("/etc/init.d/codeanalyst"); - cmd.append ("start"); - - if(exec_command (cmd) == 0) - ret = true; - else - ret = false; - - return ret; -} - - -bool oprofile_interface::codeanalyst_service_status() -{ - bool ret = false; - - QStringList cmd; - - cmd.append ("/etc/init.d/codeanalyst"); - cmd.append ("status"); - - if(exec_command (cmd) == 0) - ret = true; - else - ret = false; - - return ret; + return ca_exec_sudo_command(args, m_stdout, m_stderr, m_status); } int oprofile_interface::exec_command (QStringList & args) { - if (NULL != m_proc) { - delete m_proc; - m_proc = NULL; - } - - m_proc = new QProcess(); - m_proc->setArguments (args); - -#if 0 // DEBUG - fprintf(stderr,"Command = "); - QStringList list = m_proc->arguments(); - QStringList::Iterator it = list.begin(); - while( it != list.end() ) { - fprintf(stderr,"%s ", (*it).data() ); - ++it; - } - fprintf(stderr,"\n"); -#endif - - int rt = 0; - - if(!m_proc->start ()) { - rt = -1; - } - - // Since the process being launch are non-blocking daemon, - // sysctl, mknod, etc, just wait for the command to finish - while (rt == 0 && m_proc->isRunning ()) { - } - - // Check for normal Exit - if (!m_proc->normalExit ()) { - rt = -1; - } - - // Check for exit status - if (m_proc->exitStatus() != 0) { - rt = -1; - } - - m_StdErr = QString(m_proc->readStderr()); - m_StdOut = QString(m_proc->readStdout()); - - // Daemon will exit with normal status, - // event if it failed to start. Must check - // stderr to know the correct exit status. - //if (0 != m_StdErr.length()) - // rt = -1; - - return rt; + return ca_exec_command(args, m_stdout, m_stderr, m_status); } @@ -239,7 +158,7 @@ void oprofile_interface::generate_op_eve } -int oprofile_interface::help_start_daemon (bool novmlinux, +int oprofile_interface::help_start_daemon (bool noVmlinux, QString & vmlinux_dir, profiling_types active_profiling) { @@ -250,7 +169,6 @@ int oprofile_interface::help_start_daemo m_isDaemonStarted = false; QStringList cmd_OPROFILED_START; - cmd_OPROFILED_START.append ("sudo"); cmd_OPROFILED_START.append (CA_OPROFILE_CONTROLLER); // BEGIN CMD LINE APPENDING. @@ -267,8 +185,8 @@ int oprofile_interface::help_start_daemo //******************************************************** // VMLINUX stuff buf = ""; - if (!novmlinux) { - kernel_range = get_kernel_range (); + if (!noVmlinux && QFile::exists(vmlinux_dir)) { + kernel_range = get_kernel_range (vmlinux_dir); buf = "--vmlinux="; buf += vmlinux_dir + " "; opd_args.append (buf); @@ -367,11 +285,7 @@ int oprofile_interface::help_start_daemo cmd_pidof.append(PIDOF); cmd_pidof.append("oprofiled"); - if (exec_command(cmd_pidof) == 0) - { - // m_StdErr = QString("CodeAnalyst detected a running oprofile daemon ") - // + "(oprofiled)\n.Please make sure oprofile daemon is not " - // + "currently running.\n"; + if (exec_command(cmd_pidof) == 0) { rt = -OIE_DAEMON_RUNNING; } @@ -385,16 +299,16 @@ int oprofile_interface::help_start_daemo if( !lockFile.exists ()) { // Starting oprofile daemon - if(exec_command (cmd_OPROFILED_START) == 0) + if(exec_sudo_command (cmd_OPROFILED_START) == 0) { #if _DEBUG_ - fprintf(stderr,"help_start_daemon: stdout = %s\n",m_StdOut.ascii()); - fprintf(stderr,"help_start_daemon: stderr = %s\n",m_StdErr.ascii()); + fprintf(stderr,"help_start_daemon: stdout = %s\n",m_stdout.ascii()); + fprintf(stderr,"help_start_daemon: stderr = %s\n",m_stderr.ascii()); #endif m_isDaemonStarted = true; - m_StdErr = QString("Failed to check ") + LOCK_FILE + m_stderr = QString("Failed to check ") + LOCK_FILE + "\n\nPlease make sure oprofile daemon is not " + "currently running.\n"; rt = -OIE_DAEMON_NOTSTART; @@ -407,7 +321,7 @@ int oprofile_interface::help_start_daemo { if (QFile::exists (LOCK_FILE)) { - m_StdErr = ""; + m_stderr = ""; rt = OIE_OK; break; } else { @@ -421,15 +335,15 @@ int oprofile_interface::help_start_daemo }else{ #if _DEBUG_ - fprintf(stderr,"help_start_daemon: stdout = %s\n",m_StdOut.ascii()); - fprintf(stderr,"help_start_daemon: stderr = %s\n",m_StdErr.ascii()); + fprintf(stderr,"help_start_daemon: stdout = %s\n",m_stdout.ascii()); + fprintf(stderr,"help_start_daemon: stderr = %s\n",m_stderr.ascii()); fprintf(stderr,"help_start_daemon: Failed to start daemon\n"); #endif - m_StdErr = "Failed to start daemon.\n"; + m_stderr = "Failed to start daemon.\n"; rt = -OIE_DAEMON_NOTSTART; } }else{ - m_StdErr = QString("File /var/lib/oprofile/lock exists.\n") + m_stderr = QString("File /var/lib/oprofile/lock exists.\n") + "Please remove this file and make sure oprofile " + "daemon is not currently running.\n"; rt = -OIE_LOCK_EXIST; @@ -444,31 +358,30 @@ int oprofile_interface::help_start_daemo */ if (rt == OIE_OK) { - char wrBuf = '1'; - char rdBuf = '\0'; - QString enable = MOUNT + "/enable"; - QFile enable_file(enable); - if (enable_file.open (IO_ReadWrite)) { - // Write 1 to enable - if (-1 == enable_file.writeBlock (&wrBuf, sizeof (wrBuf))) { - do_kill_daemon(); - m_StdErr = QString("Oprofile Driver error.\n") - + "There was a problem writing to the /dev/oprofile/enable."; - rt = -OIE_DRV; - } + // Write 1 to enable + if (!set_param (QString("enable"),1)) { + do_kill_daemon(); + m_stderr = QString("Oprofile Driver error.\n") + + "There was a problem writing to the /dev/oprofile/enable."; + rt = -OIE_DRV; + } + + QFile enable_file(MOUNT + "/enable"); + if (enable_file.open (IO_ReadOnly)) { + char rdBuf = '\0'; // Read to confirm if ( rt == OIE_OK && -1 == enable_file.readBlock (&rdBuf, sizeof (rdBuf))) { do_kill_daemon(); - m_StdErr = QString("Oprofile Driver error.\n") + m_stderr = QString("Oprofile Driver error.\n") + "There was a problem reading from the /dev/oprofile/enable."; rt = -OIE_DRV; } // Compare Read to Write if( rt == OIE_OK - && rdBuf != wrBuf ) { + && rdBuf != '1' ) { do_kill_daemon(); - m_StdErr = QString("Oprofile Driver error.\n") + m_stderr = QString("Oprofile Driver error.\n") + "There was a problem enabling driver."; rt = -OIE_DRV; } @@ -476,7 +389,7 @@ int oprofile_interface::help_start_daemo enable_file.close (); }else{ do_kill_daemon(); - m_StdErr = QString("Oprofile Driver error.\n") + m_stderr = QString("Oprofile Driver error.\n") + "There was a problem openning /dev/oprofile/enable."; rt = -OIE_DRV; } @@ -510,19 +423,19 @@ bool oprofile_interface::get_daemon_pid( QString & oprofile_interface::get_std_err() { - return m_StdErr; + return m_stderr; } -int oprofile_interface::do_start_daemon (bool novmlinux, - QString & vmlinux_dir, - unsigned int buffer_size, - unsigned int watershed_size, - unsigned int cpu_buf_size, - profiling_types active_profiling, - unsigned int multiplex_interval) +int oprofile_interface::do_start_daemon (bool noVmlinux, + QString & vmlinux_dir, + unsigned int buffer_size, + unsigned int watershed_size, + unsigned int cpu_buf_size, + profiling_types active_profiling, + unsigned int multiplex_interval) { - m_StdErr = ""; + m_stderr = ""; if(!do_sysctl_setup(buffer_size, watershed_size, @@ -531,68 +444,53 @@ int oprofile_interface::do_start_daemon multiplex_interval)) return -OIE_ERR; - return help_start_daemon(novmlinux, vmlinux_dir, active_profiling); + return help_start_daemon(noVmlinux, vmlinux_dir, active_profiling); } -bool oprofile_interface::set_ctr_param (int event, QString field, unsigned long long int value) +bool oprofile_interface::set_ctr_param (int event, QString field, unsigned long int value) { - bool rt = true; - QStringList args; - QString buf; - QString st_event; - QString st_value; + QString fname = QString::number(event) + "/" + field; + return set_param(fname, value); +} - st_event.setNum (event); - st_value.setNum (value); - - QString fname; - fname.sprintf ("%s/%s/%s", MOUNT.data (), st_event.data (), field.data ()); - QFile param_file (fname);; - if (param_file.open (IO_WriteOnly)) - { - if (-1 == param_file.writeBlock (st_value.data (), st_value.length ())) - { - m_StdErr = QString("Cannot write to ") + fname + ".\n"; - rt = false; - } - param_file.close (); - } else { - m_StdErr = QString("Cannot open ") + fname + ".\n"; - rt = false; - } - return rt; +bool oprofile_interface::set_param (QString field, unsigned long int value) +{ + return set_param(field, value, m_stdout, m_stderr, m_status); + } -bool oprofile_interface::set_param (QString field, int value) -{ - bool rt = true; - QStringList args; - QString buf; - QString st_value; - st_value.setNum (value); +bool oprofile_interface::set_param (QString field, + unsigned long int value, + QString & stdOut, + QString & stdErr, + int & status) +{ + QStringList cmd_DEVCONFIG; + cmd_DEVCONFIG.append (CA_OPROFILE_CONTROLLER); + + // BEGIN CMD LINE APPENDING. + QString args; + + // Note: this is a string, we don't need the " for arguments. + args.append ("--dev-config="); + args.append (field); + args.append (":"); + args.append (QString::number(value)); - QString fname; - fname.sprintf ("%s/%s", MOUNT.data (), field.data ()); - QFile param_file (fname);; + cmd_DEVCONFIG.append(args); - if (param_file.open (IO_WriteOnly)) + if(ca_exec_sudo_command (cmd_DEVCONFIG, stdOut, stdErr, status) == -1) { - if (-1 == param_file.writeBlock (st_value.data (), st_value.length ())) - { - m_StdErr = QString("Cannot write to ") + fname + ".\n"; - rt = false; - } - param_file.close (); - - }else { - m_StdErr = QString("Cannot open ") + fname + ".\n"; - rt = false; - } - return rt; + QMessageBox::critical(NULL, "Oprofile Device File Error", + QString("Error:\nca_oprofile_controller could not configure file\n") + + "/dev/oprofile/" + field + " with value " + QString::number(value)); + return false; + } + return true; } @@ -665,19 +563,19 @@ bool oprofile_interface::do_sysctl_setup /* Setting /dev/oprofile/buffer_size */ if(buffer_size != 0 && !set_param("buffer_size", buffer_size)) { - m_StdErr = QString("Cannot configure /dev/oprofile/buffer_size.\n"); + m_stderr = QString("Cannot configure /dev/oprofile/buffer_size.\n"); goto errOut; } /* Setting /dev/oprofile/buffer_watershed */ if(buffer_size != 0 && !set_param("buffer_watershed", watershed_size)) { - m_StdErr = QString("Cannot configure /dev/oprofile/buffer_watershed.\n"); + m_stderr = QString("Cannot configure /dev/oprofile/buffer_watershed.\n"); goto errOut; } /* Setting /dev/oprofile/cpu_buffer_size */ if(cpu_buf_size != 0 && !set_param ("cpu_buffer_size", cpu_buf_size)) { - m_StdErr = QString("Cannot configure /dev/oprofile/cpu_buffer_size.\n"); + m_stderr = QString("Cannot configure /dev/oprofile/cpu_buffer_size.\n"); goto errOut; } @@ -698,7 +596,7 @@ bool oprofile_interface::do_sysctl_setup } else { if(!set_param (MUX_DRIVER_INTERFACE, multiplex_interval)) { /* This usually means driver error */ - m_StdErr = QString("Cannot configure /dev/oprofile/") + m_stderr = QString("Cannot configure /dev/oprofile/") + MUX_DRIVER_INTERFACE +".\n"; goto errOut; } @@ -710,31 +608,31 @@ bool oprofile_interface::do_sysctl_setup /* Initialize all counters */ for (int i = 0; i < m_numEventCountersAvailable; i++) { - m_StdErr = QString("Cannot clear /dev/oprofile/0,1,2,3...\n"); + m_stderr = QString("Cannot clear /dev/oprofile/0,1,2,3...\n"); if(!set_ctr_param (i, QString ("enabled"), 0)) goto errOut; if(!set_ctr_param (i, QString ("event"), 0)) goto errOut; if(!set_ctr_param (i, QString ("count"), 0)) goto errOut; } if (!do_ebs_setup(active_profiling)) { - m_StdErr = QString("Failed to setup driver for EBP.\n"); + m_stderr = QString("Failed to setup driver for EBP.\n"); goto errOut; } if (!do_ibs_setup(active_profiling)) { - m_StdErr = QString("Failed to setup driver for IBS.\n"); + m_stderr = QString("Failed to setup driver for IBS.\n"); goto errOut; } - m_StdErr = ""; + m_stderr = ""; return rt; errOut: - m_StdErr += QString("\nPlease also make sure that :\n") + m_stderr += QString("\nPlease also make sure that :\n") + " 1. /dev/oprofile/... exists.\n" + " 2. User is in the \"amdca\" group.\n\n" + "Otherwise, please do one of the followings:\n" - + " 1. Run \"/etc/init.d/codeanalyst start\" as root.\n" + + " 1. Run \"opcontrol --init\" as root.\n" + " 2. Or reboot the system.\n"; rt = false; return rt; @@ -742,13 +640,12 @@ errOut: } -QString oprofile_interface::get_kernel_range () +QString oprofile_interface::get_kernel_range (QString vmlinux_dir) { char buf[LONG_STR_MAX * 2 + 1]; char buf2[LONG_STR_MAX]; char buf3[LONG_STR_MAX]; CATuneOptions ao; - QString vmlinux_dir = ""; QString range = ""; ObjDump objdump; SymbolEngine symengine; @@ -756,9 +653,7 @@ QString oprofile_interface::get_kernel_r bfd_size_type size = 0; bfd_vma str_addr; - ao.getVmlinuxDir (vmlinux_dir); - - int symengineCode = symengine.open(vmlinux_dir.data ()); + int symengineCode = symengine.open(vmlinux_dir.ascii()); if ((SymbolEngine::OKAY == symengineCode) || (SymbolEngine::NO_SYMBOLS == symengineCode) || @@ -785,10 +680,6 @@ QString oprofile_interface::get_kernel_r */ void oprofile_interface::do_dump () { - char buf = '1'; - QString dump = MOUNT + "/dump"; - QFile dump_file (dump); - QString complete_dump = "/var/lib/oprofile/complete_dump"; QFileInfo complete_dump_info (complete_dump); QDateTime last_dump; @@ -807,13 +698,9 @@ void oprofile_interface::do_dump () //--------------------------- // Write 1 to /dev/oprofile/dump - if ((! dump_file.open (IO_WriteOnly)) - || (-1 == dump_file.writeBlock (&buf, sizeof (buf)))) + if (! set_param ("dump", 1)) QMessageBox::critical(NULL, "Writing error", "There was a problem " "writing a block to the dump"); - - dump_file.close (); - //--------------------------- // Wait for complete_dump to be refresh. @@ -836,31 +723,12 @@ void oprofile_interface::do_dump () } - -void oprofile_interface::do_stop () -{ - QString command; - - command = "echo \"0\">" + MOUNT + "/enable"; - system(command.data()); -} - void oprofile_interface::do_resume_daemon() { /* NOTE: * To Resume, write 1 to /dev/oprofile/enable file */ - char buf = '1'; - QString enable = MOUNT + "/enable"; - QFile enable_file(enable); - if (enable_file.open (IO_WriteOnly)) { - if (-1 == enable_file.writeBlock (&buf, sizeof (buf))) { - QMessageBox::information (NULL, "Writing error", "There was a " - "problem writing a block to the " - "enable"); - } - enable_file.close (); - } + set_param("enable", 1); } @@ -870,36 +738,25 @@ void oprofile_interface::do_pause_daemon /* NOTE: * To Resume, write 0 to /dev/oprofile/enable file */ - char buf = '0'; - QString enable = MOUNT + "/enable"; - QFile enable_file(enable); - if (enable_file.open (IO_WriteOnly)) - { - if (-1 == enable_file.writeBlock (&buf, sizeof (buf))) - { - QMessageBox::information (NULL, "Writing error", "There was a " - "problem writing a block to the " - "enable"); - } - enable_file.close (); - } + set_param("enable", 0); } + bool oprofile_interface::remove_lock_file() { bool rt = false; QStringList cmd_OPROFILE_RMLOCK; - cmd_OPROFILE_RMLOCK.append("sudo"); cmd_OPROFILE_RMLOCK.append(CA_OPROFILE_CONTROLLER); cmd_OPROFILE_RMLOCK.append("--rmlock"); - if (exec_command(cmd_OPROFILE_RMLOCK) == 0) + if (exec_sudo_command(cmd_OPROFILE_RMLOCK) == 0) { rt = true; } return rt; } + /* Note: The logic in this function should be similar to opcontrol script*/ void oprofile_interface::do_kill_daemon () { @@ -914,7 +771,7 @@ void oprofile_interface::do_kill_daemon if (exec_command(cmd_pidof) == 0) { isDaemonRunning = true; - daemonPid = m_StdOut.simplifyWhiteSpace(); + daemonPid = m_stdout.simplifyWhiteSpace(); } /* NOTE: @@ -965,7 +822,9 @@ void oprofile_interface::do_kill_daemon QString("Warning:\n") + "A different Oprofile daemon is running.\n" + "Profile result might be inaccurate.\n" + - "Please rerun the profile"); + "Please rerun the profile ("+ + QString::number(cur_daemon_pid)+","+ + QString::number(m_daemon_pid)+")"); return; } @@ -988,16 +847,14 @@ void oprofile_interface::do_kill_daemon do_pause_daemon(); QStringList cmd_OPROFILED_TERM; - cmd_OPROFILED_TERM.append("sudo"); cmd_OPROFILED_TERM.append(CA_OPROFILE_CONTROLLER); cmd_OPROFILED_TERM.append("--term"); QStringList cmd_OPROFILED_KILL; - cmd_OPROFILED_KILL.append("sudo"); cmd_OPROFILED_KILL.append(CA_OPROFILE_CONTROLLER); cmd_OPROFILED_KILL.append("--kill"); - if(exec_command (cmd_OPROFILED_TERM) == -1) + if(exec_sudo_command (cmd_OPROFILED_TERM) == -1) { QMessageBox::warning(NULL, "Oprofile Daemon Warning", "Warning:\nca_oprofile_controller return error. " @@ -1018,10 +875,10 @@ void oprofile_interface::do_kill_daemon temp.tv_nsec = 0; while (exec_command(cmd_pidof) != -1) { if (0 == i) { - exec_command(cmd_OPROFILED_KILL); + exec_sudo_command(cmd_OPROFILED_KILL); break; } - exec_command(cmd_OPROFILED_TERM); + exec_sudo_command(cmd_OPROFILED_TERM); // fprintf(stderr,"DEBUG: Stopping Daemon count down %d\n",i); nanosleep (&temp, NULL); i--; @@ -1047,6 +904,7 @@ void oprofile_interface::customEvent (QC Q_UNUSED (pCustEvent); } + QString oprofile_interface::simplifyPath(QString path) { QString ret = path; @@ -1055,84 +913,21 @@ QString oprofile_interface::simplifyPath return ret; } + bool oprofile_interface::havePermissionToProfile() { - bool ret = false; - int count; - - // NOTE: We need to parse output of sudo -S -l - // for 3 different cases: - // - // Case root User: - // User root may run the following commands on this host: - // (ALL) ALL - // - // Case Good User: - // User suravee may run the following commands on this host: - // (root) NOPASSWD: /usr/sbin/ca_oprofile_controller - // - // Case Bad User: - // [sudo] password for suravee1: + bool ret = true; - QProcess proc; + /* NOTE + * We use ca_oprofile_controller --help + * to check for permission to run profile. + */ QStringList cmd; - QString line_stdout; - - cmd.append ("sudo"); - cmd.append ("-S"); - cmd.append ("-l"); - proc.setArguments (cmd); - - if(!proc.start ()) { - return ret; - } - - // Wait for the 1 sec for the stdout - count = 2; - timespec temp; - temp.tv_sec = 0; - temp.tv_nsec = FIVE_HUNDRED_MS; - while(proc.isRunning ()) { - count--; - nanosleep (&temp, NULL); - if(proc.canReadLineStdout()) - break; - if(count == 0) { - // Write to stdin to stop - // process gracefully. - proc.writeToStdin(""); - return ret; - } - } - - // Read first line of stdout - line_stdout = QString(proc.readLineStdout()); - - // Handling bad case - if(!line_stdout.startsWith("User ")) { - proc.kill(); - return ret; - } - - // Processing stdout - while( (line_stdout = proc.readLineStdout()) - != QString::null ) - { - // For root user - if(line_stdout.contains("(ALL) ALL")) { - proc.kill(); - ret = true; - break; - } - - // For non-root user - QString tmp = simplifyPath(line_stdout.section(" ",-1)); - - if(tmp == CA_OPROFILE_CONTROLLER) { - proc.kill(); - ret = true; - break; - } + cmd.append (CA_OPROFILE_CONTROLLER); + cmd.append ("--help"); + + if(exec_sudo_command (cmd) == -1) { + ret = false; } return ret; @@ -1233,3 +1028,85 @@ bool oprofile_interface::checkMuxSupport QFile mux_ctrl(QString("/dev/oprofile/")+ MUX_DRIVER_INTERFACE); return ((mux_ctrl.exists())? true: false); } + +bool oprofile_interface::is_driver_loaded() +{ + QString command = QString("grep oprofile /proc/modules 2> /dev/null > /dev/null"); + + return ((system(command.ascii()) == 0)? true: false); +} + + +bool oprofile_interface::is_oprofilefs_mounted() +{ + QString command = QString("grep oprofilefs /etc/mtab 2> /dev/null > /dev/null"); + + return ((system(command.ascii()) == 0)? true: false); + +} + + +bool oprofile_interface::checkOprofileDriverStatus() +{ + bool ret = false; + + // Check if driver is loaded + ret = is_driver_loaded(); + + // Check if OProfile filesystem is mounted + if (ret) ret = is_oprofilefs_mounted(); + + return ret; +} + + +bool oprofile_interface::loadOprofileDriver() +{ + bool ret = true; + QStringList cmd_LOAD; + cmd_LOAD.append (CA_OPROFILE_CONTROLLER); + cmd_LOAD.append ("--load-drv"); + + if(exec_sudo_command (cmd_LOAD) == -1) { + QMessageBox::critical(NULL, "Oprofile Error", + "Error:\nca_oprofile_controller return error. " + "Could not load OProfile driver."); + ret = false; + } + return ret; +} + + +bool oprofile_interface::set_css(unsigned int cssDepth, + unsigned int cssInterval, + unsigned int cssTgid, + unsigned int cssBitness) +{ + if(!set_param ("backtrace_depth" , cssDepth)) goto errOut; + if(!set_param ("backtrace_interval" , cssInterval)) goto errOut; + if(!set_param ("backtrace_tgid" , cssTgid)) goto errOut; + if(!set_param ("backtrace_tgid_bitness" , cssBitness)) goto errOut; + return true; + +errOut: + return false; + +} + +bool oprofile_interface::checkCssSupportInDaemon() +{ + // TODO: [Suravee] This is to be defined + return true; +} + + +bool oprofile_interface::checkCssSupportInDriver() +{ + QFile btDepth (MOUNT + "/backtrace_depth"); + QFile btInterval (MOUNT + "/backtrace_interval"); + QFile btTgid (MOUNT + "/backtrace_tgid"); + QFile btTgidBitness(MOUNT + "/backtrace_tgid_bitness"); + return ((btDepth.exists() + && btInterval.exists() + && btTgid.exists())? true: false); +} Index: package/src/ca/scripts/Uninstall.sh =================================================================== --- package/src/ca/scripts/Uninstall.sh +++ package/src/ca/scripts/Uninstall.sh @@ -4,13 +4,13 @@ AMDCA_GRP=amdca GREP=/bin/grep GROUPDEL="/usr/sbin/groupdel" -ETC="/etc" -INITD="$ETC/init.d" -RCD="$ETC/rc.d" -RC3D="$RCD/rc3.d" -RC5D="$RCD/rc5.d" -CODEANALYST_INIT="$INITD/codeanalyst" -CODEANALYST_LN="S99codeanalyst" +#ETC="/etc" +#INITD="$ETC/init.d" +#RCD="$ETC/rc.d" +#RC3D="$RCD/rc3.d" +#RC5D="$RCD/rc5.d" +#CODEANALYST_INIT="$INITD/codeanalyst" +#CODEANALYST_LN="S99codeanalyst" family10=$PREFIX/share/oprofile/x86-64/family10 family10h=$PREFIX/share/oprofile/x86-64/family10h @@ -66,27 +66,27 @@ # # Stop codeanalyst service # -$CODEANALYST_INIT stop +#$CODEANALYST_INIT stop # # Remove service at runlevel 3 and 5 # -if test -e $RCD; then - print_action "Remove codeanalyst service in $RC3D" - rm -f $RC3D/$CODEANALYST_LN - RETVAL=$?; print_ok_no $RETVAL +#if test -e $RCD; then +# print_action "Remove codeanalyst service in $RC3D" +# rm -f $RC3D/$CODEANALYST_LN +# RETVAL=$?; print_ok_no $RETVAL +# +# print_action "Remove codeanalyst service in $RC5D" +# rm -f $RC5D/$CODEANALYST_LN +# RETVAL=$?; print_ok_no $RETVAL +#fi - print_action "Remove codeanalyst service in $RC5D" - rm -f $RC5D/$CODEANALYST_LN - RETVAL=$?; print_ok_no $RETVAL -fi - # # Remove codeanalyst service # -print_action "Remove $CODEANALYST_INIT script" -rm -f $CODEANALYST_INIT -RETVAL=$?; print_ok_no $RETVAL +#print_action "Remove $CODEANALYST_INIT script" +#rm -f $CODEANALYST_INIT +#RETVAL=$?; print_ok_no $RETVAL # Index: package/src/ca/scripts/Setup.sh =================================================================== --- package/src/ca/scripts/Setup.sh +++ package/src/ca/scripts/Setup.sh @@ -24,11 +24,11 @@ AMDCA_GRP=amdca GROUPADD="/usr/sbin/groupadd -r" LN="/bin/ln -sf" -ETC="/etc" -INITD="$ETC/init.d" -RCD="$ETC/rc.d" -CODEANALYST_INIT="$INITD/codeanalyst" -CODEANALYST_LN="S99codeanalyst" +#ETC="/etc" +#INITD="$ETC/init.d" +#RCD="$ETC/rc.d" +#CODEANALYST_INIT="$INITD/codeanalyst" +#CODEANALYST_LN="S99codeanalyst" family10=$PREFIX/share/oprofile/x86-64/family10 family10h=$PREFIX/share/oprofile/x86-64/family10h @@ -124,39 +124,39 @@ # # Installing codeanalyst service # -print_action "Install codeanalyst service." -if [ -f scripts/codeanalyst ] ; then - install -m 755 scripts/codeanalyst $INITD - RETVAL=$?; print_ok_no $RETVAL -else - print_error "scripts/codeanalyst not found." -fi +#print_action "Install codeanalyst service." +#if [ -f scripts/codeanalyst ] ; then +# install -m 755 scripts/codeanalyst $INITD +# RETVAL=$?; print_ok_no $RETVAL +#else +# print_error "scripts/codeanalyst not found." +#fi # # Installing service at runlevel 3 and 5 # -if test -e $RCD/rc3.d ; then - # SUSE and REDHAT - RC3D="$RCD/rc3.d" - RC5D="$RCD/rc5.d" -else if test -e $ETC/rc3.d ; then - # UBUNTU - RC3D="$ETC/rc3.d" - RC5D="$ETC/rc5.d" -fi fi +#if test -e $RCD/rc3.d ; then +# # SUSE and REDHAT +# RC3D="$RCD/rc3.d" +# RC5D="$RCD/rc5.d" +#else if test -e $ETC/rc3.d ; then +# # UBUNTU +# RC3D="$ETC/rc3.d" +# RC5D="$ETC/rc5.d" +#fi fi -print_action "Install codeanalyst service in $RC3D" -$LN $CODEANALYST_INIT $RC3D/$CODEANALYST_LN -RETVAL=$?; print_ok_no $RETVAL +#print_action "Install codeanalyst service in $RC3D" +#$LN $CODEANALYST_INIT $RC3D/$CODEANALYST_LN +#RETVAL=$?; print_ok_no $RETVAL -print_action "Install codeanalyst service in $RC5D" -$LN $CODEANALYST_INIT $RC5D/$CODEANALYST_LN -RETVAL=$?; print_ok_no $RETVAL +#print_action "Install codeanalyst service in $RC5D" +#$LN $CODEANALYST_INIT $RC5D/$CODEANALYST_LN +#RETVAL=$?; print_ok_no $RETVAL # # Restart codeanalyst service # -$CODEANALYST_INIT restart +#$CODEANALYST_INIT restart echo "* Post-Install Setup Finished." Index: package/src/ca/Makefile.am =================================================================== --- package/src/ca/Makefile.am +++ package/src/ca/Makefile.am @@ -4,7 +4,6 @@ diffgui \ utils \ scripts - #ca_opflat install-exec-hook: @if test -e "scripts/Setup.sh"; then \ Index: package/CAInstaller.sh =================================================================== --- package/CAInstaller.sh +++ package/CAInstaller.sh @@ -482,6 +482,34 @@ fi echo "" } + +loadCAKM() +{ + echo ".... Load OProfile Kernel Module" + grep oprofilefs /proc/filesystems > /dev/null + if test "$?" -ne 0; then + modprobe oprofile + if test "$?" != "0"; then + # couldn't load the module + return 1 + fi + grep oprofile /proc/modules > /dev/null + if test "$?" != "0"; then + # didn't find module + return 1 + fi + grep oprofilefs /proc/filesystems >/dev/null + if test "$?" -ne 0; then + # filesystem still not around + return 1 + fi + fi + mkdir /dev/oprofile > /dev/null 2>&1 + grep oprofilefs /etc/mtab >/dev/null + if test "$?" -ne 0; then + mount -t oprofilefs nodev /dev/oprofile >/dev/null + fi +} #------------------------------------------------------------------------------- # CONFIGURATION @@ -576,13 +604,7 @@ # uninstallCAKM ./src/cakm/mod_install.sh -r -n checkErrorOut - /sbin/lsmod | grep oprofile - if test "$?" = "0"; then - echo ".... Unload CA Kernel Module." - /etc/init.d/codeanalyst stop - fi - echo ".... Load CA Kernel Module." - /etc/init.d/codeanalyst start + loadCAKM fi
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor