• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "include/private/dvr/performance_client.h"
2 
3 #include <sys/types.h>
4 
5 #include <pdx/default_transport/client_channel_factory.h>
6 #include <pdx/rpc/remote_method.h>
7 #include <pdx/rpc/string_wrapper.h>
8 #include <private/dvr/performance_rpc.h>
9 
10 using android::pdx::rpc::WrapString;
11 
12 namespace android {
13 namespace dvr {
14 
PerformanceClient(int * error)15 PerformanceClient::PerformanceClient(int* error)
16     : BASE(pdx::default_transport::ClientChannelFactory::Create(
17           PerformanceRPC::kClientPath)) {
18   if (error)
19     *error = Client::error();
20 }
21 
SetCpuPartition(pid_t task_id,const std::string & partition)22 int PerformanceClient::SetCpuPartition(pid_t task_id,
23                                        const std::string& partition) {
24   if (task_id == 0)
25     task_id = gettid();
26 
27   return ReturnStatusOrError(
28       InvokeRemoteMethod<PerformanceRPC::SetCpuPartition>(task_id, partition));
29 }
30 
SetCpuPartition(pid_t task_id,const char * partition)31 int PerformanceClient::SetCpuPartition(pid_t task_id, const char* partition) {
32   if (task_id == 0)
33     task_id = gettid();
34 
35   return ReturnStatusOrError(
36       InvokeRemoteMethod<PerformanceRPC::SetCpuPartition>(
37           task_id, WrapString(partition)));
38 }
39 
SetSchedulerPolicy(pid_t task_id,const std::string & scheduler_policy)40 int PerformanceClient::SetSchedulerPolicy(pid_t task_id,
41                                           const std::string& scheduler_policy) {
42   if (task_id == 0)
43     task_id = gettid();
44 
45   return ReturnStatusOrError(
46       InvokeRemoteMethod<PerformanceRPC::SetSchedulerPolicy>(task_id,
47                                                              scheduler_policy));
48 }
49 
SetSchedulerPolicy(pid_t task_id,const char * scheduler_policy)50 int PerformanceClient::SetSchedulerPolicy(pid_t task_id,
51                                           const char* scheduler_policy) {
52   if (task_id == 0)
53     task_id = gettid();
54 
55   return ReturnStatusOrError(
56       InvokeRemoteMethod<PerformanceRPC::SetSchedulerPolicy>(
57           task_id, WrapString(scheduler_policy)));
58 }
59 
SetSchedulerClass(pid_t task_id,const std::string & scheduler_class)60 int PerformanceClient::SetSchedulerClass(pid_t task_id,
61                                          const std::string& scheduler_class) {
62   if (task_id == 0)
63     task_id = gettid();
64 
65   return ReturnStatusOrError(
66       InvokeRemoteMethod<PerformanceRPC::SetSchedulerClass>(task_id,
67                                                             scheduler_class));
68 }
69 
SetSchedulerClass(pid_t task_id,const char * scheduler_class)70 int PerformanceClient::SetSchedulerClass(pid_t task_id,
71                                          const char* scheduler_class) {
72   if (task_id == 0)
73     task_id = gettid();
74 
75   return ReturnStatusOrError(
76       InvokeRemoteMethod<PerformanceRPC::SetSchedulerClass>(
77           task_id, WrapString(scheduler_class)));
78 }
79 
GetCpuPartition(pid_t task_id,std::string * partition_out)80 int PerformanceClient::GetCpuPartition(pid_t task_id,
81                                        std::string* partition_out) {
82   if (partition_out == nullptr)
83     return -EINVAL;
84 
85   if (task_id == 0)
86     task_id = gettid();
87 
88   auto status = InvokeRemoteMethodInPlace<PerformanceRPC::GetCpuPartition>(
89       partition_out, task_id);
90   return status ? 0 : -status.error();
91 }
92 
GetCpuPartition(pid_t task_id,char * partition_out,std::size_t size)93 int PerformanceClient::GetCpuPartition(pid_t task_id, char* partition_out,
94                                        std::size_t size) {
95   if (partition_out == nullptr)
96     return -EINVAL;
97 
98   if (task_id == 0)
99     task_id = gettid();
100 
101   auto wrapper = WrapString(partition_out, size);
102   auto status = InvokeRemoteMethodInPlace<PerformanceRPC::GetCpuPartition>(
103       &wrapper, task_id);
104   if (!status)
105     return -status.error();
106 
107   if (wrapper.size() < size)
108     partition_out[wrapper.size()] = '\0';
109 
110   return 0;
111 }
112 
113 }  // namespace dvr
114 }  // namespace android
115 
dvrSetCpuPartition(pid_t task_id,const char * partition)116 extern "C" int dvrSetCpuPartition(pid_t task_id, const char* partition) {
117   int error;
118   if (auto client = android::dvr::PerformanceClient::Create(&error))
119     return client->SetCpuPartition(task_id, partition);
120   else
121     return error;
122 }
123 
dvrSetSchedulerPolicy(pid_t task_id,const char * scheduler_policy)124 extern "C" int dvrSetSchedulerPolicy(pid_t task_id,
125                                      const char* scheduler_policy) {
126   int error;
127   if (auto client = android::dvr::PerformanceClient::Create(&error))
128     return client->SetSchedulerPolicy(task_id, scheduler_policy);
129   else
130     return error;
131 }
132 
dvrSetSchedulerClass(pid_t task_id,const char * scheduler_class)133 extern "C" int dvrSetSchedulerClass(pid_t task_id,
134                                     const char* scheduler_class) {
135   int error;
136   if (auto client = android::dvr::PerformanceClient::Create(&error))
137     return client->SetSchedulerClass(task_id, scheduler_class);
138   else
139     return error;
140 }
141 
dvrGetCpuPartition(pid_t task_id,char * partition,size_t size)142 extern "C" int dvrGetCpuPartition(pid_t task_id, char* partition, size_t size) {
143   int error;
144   if (auto client = android::dvr::PerformanceClient::Create(&error))
145     return client->GetCpuPartition(task_id, partition, size);
146   else
147     return error;
148 }
149