blob: 5c59dcfc8f8d11344c02cef9e1fb3e9c4304f7dc [file] [log] [blame]
Namhyung Kim12864b32012-04-26 14:15:22 +09001/*
2 * Helper functions for handling target threads/cpus
3 *
4 * Copyright (C) 2012, LG Electronics, Namhyung Kim <namhyung.kim@lge.com>
5 *
6 * Released under the GPL v2.
7 */
8
9#include "target.h"
10#include "debug.h"
11
12
Namhyung Kim60bbdda2012-05-07 14:09:00 +090013enum perf_target_errno perf_target__validate(struct perf_target *target)
Namhyung Kim12864b32012-04-26 14:15:22 +090014{
Namhyung Kim60bbdda2012-05-07 14:09:00 +090015 enum perf_target_errno ret = PERF_ERRNO_TARGET__SUCCESS;
16
Namhyung Kim12864b32012-04-26 14:15:22 +090017 if (target->pid)
18 target->tid = target->pid;
19
20 /* CPU and PID are mutually exclusive */
21 if (target->tid && target->cpu_list) {
Namhyung Kim12864b32012-04-26 14:15:22 +090022 target->cpu_list = NULL;
Namhyung Kim60bbdda2012-05-07 14:09:00 +090023 if (ret == PERF_ERRNO_TARGET__SUCCESS)
24 ret = PERF_ERRNO_TARGET__PID_OVERRIDE_CPU;
Namhyung Kim12864b32012-04-26 14:15:22 +090025 }
26
27 /* UID and PID are mutually exclusive */
28 if (target->tid && target->uid_str) {
Namhyung Kim12864b32012-04-26 14:15:22 +090029 target->uid_str = NULL;
Namhyung Kim60bbdda2012-05-07 14:09:00 +090030 if (ret == PERF_ERRNO_TARGET__SUCCESS)
31 ret = PERF_ERRNO_TARGET__PID_OVERRIDE_UID;
Namhyung Kim12864b32012-04-26 14:15:22 +090032 }
33
34 /* UID and CPU are mutually exclusive */
35 if (target->uid_str && target->cpu_list) {
Namhyung Kim12864b32012-04-26 14:15:22 +090036 target->cpu_list = NULL;
Namhyung Kim60bbdda2012-05-07 14:09:00 +090037 if (ret == PERF_ERRNO_TARGET__SUCCESS)
38 ret = PERF_ERRNO_TARGET__UID_OVERRIDE_CPU;
Namhyung Kim12864b32012-04-26 14:15:22 +090039 }
40
Namhyung Kim60bbdda2012-05-07 14:09:00 +090041 /* PID and SYSTEM are mutually exclusive */
42 if (target->tid && target->system_wide) {
Namhyung Kim12864b32012-04-26 14:15:22 +090043 target->system_wide = false;
Namhyung Kim60bbdda2012-05-07 14:09:00 +090044 if (ret == PERF_ERRNO_TARGET__SUCCESS)
45 ret = PERF_ERRNO_TARGET__PID_OVERRIDE_SYSTEM;
Namhyung Kim12864b32012-04-26 14:15:22 +090046 }
Namhyung Kim60bbdda2012-05-07 14:09:00 +090047
48 /* UID and SYSTEM are mutually exclusive */
49 if (target->uid_str && target->system_wide) {
50 target->system_wide = false;
51 if (ret == PERF_ERRNO_TARGET__SUCCESS)
52 ret = PERF_ERRNO_TARGET__UID_OVERRIDE_SYSTEM;
53 }
54
55 return ret;
Namhyung Kim12864b32012-04-26 14:15:22 +090056}