~ubuntu-branches/ubuntu/vivid/slurm-llnl/vivid

« back to all changes in this revision

Viewing changes to src/sacct/sacct_stat.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2009-09-24 23:28:15 UTC
  • mfrom: (1.1.11 upstream) (3.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090924232815-enh65jn32q1ebg07
Tags: 2.0.5-1
* New upstream release 
* Changed dependecy from lib-mysqlclient15 to lib-mysqlclient 
* Added Default-Start for runlevel 2 and 4 and $remote_fs requirement in
  init.d scripts (Closes: #541252)
* Postinst checks for wrong runlevels 2 and 4 links
* Upgraded to standard version 3.8.3
* Add lintian overrides for missing slurm-llnl-configurator.html in doc
  base registration
* modified postrm scripts to ignore pkill return value in order to avoid
  postrm failure when no slurm process is running
* Checking for slurmctld.pid before cancelling running and pending
  jobs during package removal 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************\
2
 
 *  sacct_stat.c - stat slurmd for percise job information
3
 
 *
4
 
 *  $Id: options.c 7541 2006-03-18 01:44:58Z da $
5
 
 *****************************************************************************
6
 
 *  Copyright (C) 2006 The Regents of the University of California.
7
 
 *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
8
 
 *  Written by Danny Auble <da@llnl.gov>.
9
 
 *  LLNL-CODE-402394.
10
 
 *  
11
 
 *  This file is part of SLURM, a resource management program.
12
 
 *  For details, see <http://www.llnl.gov/linux/slurm/>.
13
 
 *  
14
 
 *  SLURM is free software; you can redistribute it and/or modify it under
15
 
 *  the terms of the GNU General Public License as published by the Free
16
 
 *  Software Foundation; either version 2 of the License, or (at your option)
17
 
 *  any later version.
18
 
 *
19
 
 *  In addition, as a special exception, the copyright holders give permission 
20
 
 *  to link the code of portions of this program with the OpenSSL library under
21
 
 *  certain conditions as described in each individual source file, and 
22
 
 *  distribute linked combinations including the two. You must obey the GNU 
23
 
 *  General Public License in all respects for all of the code used other than 
24
 
 *  OpenSSL. If you modify file(s) with this exception, you may extend this 
25
 
 *  exception to your version of the file(s), but you are not obligated to do 
26
 
 *  so. If you do not wish to do so, delete this exception statement from your
27
 
 *  version.  If you delete this exception statement from all source files in 
28
 
 *  the program, then also delete it here.
29
 
 *  
30
 
 *  SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
31
 
 *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
32
 
 *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
33
 
 *  details.
34
 
 *  
35
 
 *  You should have received a copy of the GNU General Public License along
36
 
 *  with SLURM; if not, write to the Free Software Foundation, Inc.,
37
 
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
38
 
\*****************************************************************************/
39
 
 
40
 
#include "sacct.h"
41
 
#include <pthread.h>
42
 
#include "src/common/forward.h"
43
 
#include "src/common/slurm_auth.h"
44
 
 
45
 
jobacct_step_rec_t step;
46
 
        
47
 
int thr_finished = 0;
48
 
        
49
 
void *_stat_thread(void *args);
50
 
int _sacct_query(slurm_step_layout_t *step_layout, uint32_t job_id, 
51
 
                 uint32_t step_id);
52
 
int _process_results();
53
 
 
54
 
 
55
 
int _sacct_query(slurm_step_layout_t *step_layout, uint32_t job_id,
56
 
                 uint32_t step_id)
57
 
{
58
 
        slurm_msg_t msg;
59
 
        stat_jobacct_msg_t r;
60
 
        stat_jobacct_msg_t *jobacct_msg = NULL;
61
 
        ListIterator itr;
62
 
        List ret_list = NULL;
63
 
        sacct_t temp_sacct;
64
 
        ret_data_info_t *ret_data_info = NULL;
65
 
        int rc = SLURM_SUCCESS;
66
 
        int ntasks = 0;
67
 
        int tot_tasks = 0;
68
 
        debug("getting the stat of job %d on %d nodes", 
69
 
              job_id, step_layout->node_cnt);
70
 
 
71
 
        memset(&temp_sacct, 0, sizeof(sacct_t));
72
 
        temp_sacct.min_cpu = (float)NO_VAL;
73
 
        memset(&step.sacct, 0, sizeof(sacct_t));
74
 
        step.sacct.min_cpu = (float)NO_VAL;
75
 
 
76
 
        step.stepid = step_id;
77
 
        step.nodes = step_layout->node_list;
78
 
        step.stepname = NULL;
79
 
        step.state = JOB_RUNNING;
80
 
        slurm_msg_t_init(&msg);
81
 
        /* Common message contents */
82
 
        r.job_id      = job_id;
83
 
        r.step_id     = step_id;
84
 
        r.jobacct     = jobacct_gather_g_create(NULL);
85
 
        msg.msg_type        = MESSAGE_STAT_JOBACCT;
86
 
        msg.data            = &r;
87
 
        
88
 
        
89
 
        ret_list = slurm_send_recv_msgs(step_layout->node_list, &msg, 0, false);
90
 
        if (!ret_list) {
91
 
                error("got an error no list returned");
92
 
                goto cleanup;
93
 
        }
94
 
        
95
 
        itr = list_iterator_create(ret_list);           
96
 
        while((ret_data_info = list_next(itr))) {
97
 
                switch (ret_data_info->type) {
98
 
                case MESSAGE_STAT_JOBACCT:
99
 
                        jobacct_msg = (stat_jobacct_msg_t *)
100
 
                                ret_data_info->data;
101
 
                        if(jobacct_msg) {
102
 
                                debug2("got it back for job %d", 
103
 
                                       jobacct_msg->job_id);
104
 
                                jobacct_gather_g_2_sacct(
105
 
                                        &temp_sacct, 
106
 
                                        jobacct_msg->jobacct);
107
 
                                ntasks += jobacct_msg->num_tasks;
108
 
                                aggregate_sacct(&step.sacct, &temp_sacct);
109
 
                        }
110
 
                        break;
111
 
                case RESPONSE_SLURM_RC:
112
 
                        rc = slurm_get_return_code(ret_data_info->type, 
113
 
                                                   ret_data_info->data);
114
 
                        error("there was an error with the request rc = %s", 
115
 
                              slurm_strerror(rc));
116
 
                        break;
117
 
                default:
118
 
                        rc = slurm_get_return_code(ret_data_info->type, 
119
 
                                                   ret_data_info->data);
120
 
                        error("unknown return given %d rc = %s", 
121
 
                              ret_data_info->type, slurm_strerror(rc));
122
 
                        break;
123
 
                }
124
 
        }
125
 
        list_iterator_destroy(itr);
126
 
        list_destroy(ret_list);
127
 
 
128
 
        tot_tasks += ntasks;            
129
 
cleanup:
130
 
        
131
 
        if(tot_tasks) {
132
 
                step.sacct.ave_rss *= 1024;
133
 
                step.sacct.max_rss *= 1024;
134
 
                step.sacct.ave_vsize *= 1024;
135
 
                step.sacct.max_vsize *= 1024;
136
 
 
137
 
                step.sacct.ave_cpu /= tot_tasks;
138
 
                step.sacct.ave_cpu /= 100;
139
 
                step.sacct.min_cpu /= 100;
140
 
                step.sacct.ave_rss /= tot_tasks;
141
 
                step.sacct.ave_vsize /= tot_tasks;
142
 
                step.sacct.ave_pages /= tot_tasks;
143
 
        }
144
 
        jobacct_gather_g_destroy(r.jobacct);    
145
 
        return SLURM_SUCCESS;
146
 
}
147
 
 
148
 
int _process_results()
149
 
{
150
 
        print_fields(JOBSTEP, &step);
151
 
        return SLURM_SUCCESS;
152
 
}
153
 
 
154
 
int sacct_stat(uint32_t jobid, uint32_t stepid)
155
 
{
156
 
        slurm_msg_t req_msg;
157
 
        slurm_msg_t resp_msg;
158
 
        job_step_id_msg_t req;
159
 
        slurm_step_layout_t *step_layout = NULL;
160
 
        int rc = SLURM_SUCCESS;
161
 
 
162
 
        slurm_msg_t_init(&req_msg);
163
 
        slurm_msg_t_init(&resp_msg);
164
 
        debug("requesting info for job %u.%u", jobid, stepid);
165
 
        req.job_id = jobid;
166
 
        req.step_id = stepid;
167
 
        req_msg.msg_type = REQUEST_STEP_LAYOUT;
168
 
        req_msg.data     = &req;
169
 
        
170
 
        if (slurm_send_recv_controller_msg(&req_msg, &resp_msg) < 0) {
171
 
                return SLURM_ERROR;
172
 
        }
173
 
                
174
 
        switch (resp_msg.msg_type) {
175
 
        case RESPONSE_STEP_LAYOUT:
176
 
                step_layout = (slurm_step_layout_t *)resp_msg.data;
177
 
                break;
178
 
        case RESPONSE_SLURM_RC:
179
 
                rc = ((return_code_msg_t *) resp_msg.data)->return_code;
180
 
                slurm_free_return_code_msg(resp_msg.data);      
181
 
                printf("problem getting job: %s\n", slurm_strerror(rc));
182
 
                slurm_seterrno_ret(rc);
183
 
                break;
184
 
        default:
185
 
                slurm_seterrno_ret(SLURM_UNEXPECTED_MSG_ERROR);
186
 
                break;
187
 
        }
188
 
                
189
 
        if(!step_layout) {
190
 
                error("didn't get the job record rc = %s", slurm_strerror(rc));
191
 
                return rc;
192
 
        }
193
 
 
194
 
        _sacct_query(step_layout, jobid, stepid);
195
 
        
196
 
        _process_results();
197
 
        
198
 
        slurm_step_layout_destroy(step_layout); 
199
 
        
200
 
        return rc;
201
 
}