NCBI C++ ToolKit
blast_usage_report.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id:
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Amelia Fong
27  *
28  */
29 
30 /** @file blast_usage_report.cpp
31  * BLAST usage report api
32  */
33 
34 #include <ncbi_pch.hpp>
36 #include <corelib/ncbifile.hpp>
37 
38 #ifndef SKIP_DOXYGEN_PROCESSING
40 USING_SCOPE(blast);
41 #endif
42 
43 static const string kNcbiAppName="standalone-blast";
44 static const string kIdFile="/sys/class/dmi/id/sys_vendor";
45 
47 {
48  char * blast_docker = getenv("BLAST_DOCKER");
49  if(blast_docker != NULL){
50  AddParam(eDocker, true);
51  }
52 
53  CFile id_file(kIdFile);
54  if(id_file.Exists()){
55  CNcbiIfstream s(id_file.GetPath().c_str(), IOS_BASE::in);
56  string line;
57  NcbiGetlineEOL(s, line);
58  NStr::ToUpper(line);
59  if (line.find("GOOGLE") != NPOS) {
60  AddParam(eGCP, true);
61  }
62  else if (line.find("AMAZON")!= NPOS){
63  AddParam(eAWS, true);
64  }
65  }
66 
67  char* elb_job_id = getenv("BLAST_ELB_JOB_ID");
68  if(elb_job_id != NULL){
69  string j_id(elb_job_id);
70  AddParam(eELBJobId, j_id);
71  }
72  char* elb_batch_num = getenv("BLAST_ELB_BATCH_NUM");
73  if(elb_batch_num != NULL){
74  int bn = NStr::StringToInt(CTempString(elb_batch_num), NStr::fConvErr_NoThrow);
76  }
77  char* elb_version = getenv("BLAST_ELB_VERSION");
78  if(elb_version != NULL){
79  string ev(elb_version);
80  AddParam(eELBVersion, ev);
81  }
82 }
83 
85 {
88  x_CheckRunEnv();
89 }
90 
92 {
93  if (IsEnabled()) {
94  Send(m_Params);
95  Wait();
96  Finish();
97  }
98 }
99 
101 {
102  string retval;
103  switch (p) {
104  case eApp: retval.assign("ncbi_app"); break;
105  case eVersion: retval.assign("version"); break;
106  case eProgram: retval.assign("program"); break;
107  case eTask: retval.assign("task"); break;
108  case eExitStatus: retval.assign("exit_status"); break;
109  case eRunTime: retval.assign("run_time"); break;
110  case eDBName: retval.assign("db_name"); break;
111  case eDBLength: retval.assign("db_length"); break;
112  case eDBNumSeqs: retval.assign("db_num_seqs"); break;
113  case eDBDate: retval.assign("db_date"); break;
114  case eBl2seq: retval.assign("bl2seq"); break;
115  case eNumSubjects: retval.assign("num_subjects"); break;
116  case eSubjectsLength: retval.assign("subjects_length"); break;
117  case eNumQueries: retval.assign("num_queries"); break;
118  case eTotalQueryLength: retval.assign("queries_length"); break;
119  case eEvalueThreshold: retval.assign("evalue_threshold"); break;
120  case eNumThreads: retval.assign("num_threads"); break;
121  case eHitListSize: retval.assign("hitlist_size"); break;
122  case eOutputFmt: retval.assign("output_fmt"); break;
123  case eTaxIdList: retval.assign("taxidlist"); break;
124  case eNegTaxIdList: retval.assign("negative_taxidlist"); break;
125  case eGIList: retval.assign("gilist"); break;
126  case eNegGIList: retval.assign("negative_gilist"); break;
127  case eSeqIdList: retval.assign("seqidlist"); break;
128  case eNegSeqIdList: retval.assign("negative_seqidlist"); break;
129  case eIPGList: retval.assign("ipglist"); break;
130  case eNegIPGList: retval.assign("negative_ipglist"); break;
131  case eMaskAlgo: retval.assign("mask_algo"); break;
132  case eCompBasedStats: retval.assign("comp_based_stats"); break;
133  case eRange: retval.assign("range"); break;
134  case eMTMode: retval.assign("mt_mode"); break;
135  case eNumQueryBatches: retval.assign("num_query_batches"); break;
136  case eNumErrStatus: retval.assign("num_error_status"); break;
137  case ePSSMInput: retval.assign("pssm_input"); break;
138  case eConverged: retval.assign("converged"); break;
139  case eArchiveInput: retval.assign("archive"); break;
140  case eRIDInput: retval.assign("rid"); break;
141  case eDBInfo: retval.assign("db_info"); break;
142  case eDBTaxInfo: retval.assign("db_tax_info"); break;
143  case eDBEntry: retval.assign("db_entry"); break;
144  case eDBDumpAll: retval.assign("db_entry_all"); break;
145  case eDBType: retval.assign("db_type"); break;
146  case eInputType: retval.assign("input_type"); break;
147  case eParseSeqIDs: retval.assign("parse_seqids"); break;
148  case eSeqType: retval.assign("seq_type"); break;
149  case eDBTest: retval.assign("db_test"); break;
150  case eDBAliasMode: retval.assign("db_alias_mode"); break;
151  case eDocker: retval.assign("docker"); break;
152  case eGCP: retval.assign("gcp"); break;
153  case eAWS: retval.assign("aws"); break;
154  case eELBJobId: retval.assign("elb_job_id"); break;
155  case eELBBatchNum: retval.assign("elb_batch_num"); break;
156  case eSRA: retval.assign("sra"); break;
157  case eELBVersion: retval.assign("elb_version"); break;
158  default:
159  LOG_POST(Warning <<"Invalid usage params: " << (int)p);
160  abort();
161  break;
162  }
163  return retval;
164 }
165 
167 {
168  if (IsEnabled()){
169  string t = x_EUsageParmsToString(p);
171  }
172 }
173 
174 void CBlastUsageReport::AddParam(EUsageParams p, const string & val)
175 {
176  if (IsEnabled()) {
177  string t = x_EUsageParmsToString(p);
178  m_Params.Add(t, val);
179  }
180 }
181 
182 void CBlastUsageReport::AddParam(EUsageParams p, const double & val)
183 {
184  if (IsEnabled()) {
185  string t = x_EUsageParmsToString(p);
186  m_Params.Add(t, val);
187  }
188 }
189 
191 {
192  char * blast_usage_env = getenv("BLAST_USAGE_REPORT");
193  if(blast_usage_env != NULL){
194  bool enable = NStr::StringToBool(blast_usage_env);
195  if (!enable) {
196  SetEnabled(false);
198  LOG_POST(Info <<"Phone home disabled");
199  return ;
200  }
201  }
202 
203  CNcbiIstrstream empty_stream(kEmptyStr);
205  if (registry->HasEntry("BLAST", "BLAST_USAGE_REPORT")) {
206  bool enable = NStr::StringToBool(registry->Get("BLAST", "BLAST_USAGE_REPORT"));
207  if (!enable) {
208  SetEnabled(false);
210  LOG_POST(Info <<"Phone home disabled by config setting");
211  return ;
212  }
213  }
215  SetEnabled(true);
216  LOG_POST(Info <<"Phone home enabled");
217 }
218 
220 {
221  if (IsEnabled()) {
222  string t = x_EUsageParmsToString(p);
223  m_Params.Add(t, val);
224  }
225 
226 }
227 
229 {
230  if (IsEnabled()) {
231  string t = x_EUsageParmsToString(p);
232  m_Params.Add(t, val);
233  }
234 
235 }
USING_SCOPE(blast)
static const string kNcbiAppName
static const string kIdFile
USING_NCBI_SCOPE
BLAST usage report api.
string x_EUsageParmsToString(EUsageParams p)
CUsageReportParameters m_Params
void AddParam(EUsageParams p, int val)
CFile –.
Definition: ncbifile.hpp:1604
CNcbiRegistry –.
Definition: ncbireg.hpp:913
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
static CMemoryRegistry registry
Definition: cn3d_tools.cpp:81
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
const string & GetPath(void) const
Get entry path.
Definition: ncbifile.hpp:3910
virtual bool Exists(void) const
Check existence of file.
Definition: ncbifile.hpp:4038
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
virtual const string & Get(const string &section, const string &name, TFlags flags=0) const
Get the parameter value.
Definition: ncbireg.cpp:262
virtual bool HasEntry(const string &section, const string &name=kEmptyStr, TFlags flags=0) const
Definition: ncbireg.cpp:290
@ fWithNcbirc
Include .ncbirc (used only by CNcbiReg.)
Definition: ncbireg.hpp:93
void Finish(void)
Finish reporting for the current reporting object.
void Send(void)
Report usage statistics (asynchronously), default parameters.
void SetEnabled(bool enable=true)
Enable or disable usage reporter (current instance only).
void Wait(void)
Wait until all queued jobs starts to process and queue is empty.
CUsageReportParameters & Add(const string &name, const string &value)
Add argument Name must contain only alphanumeric chars or '_'.
static void SetEnabled(bool enable=true)
Enable or disable usage statistics reporting globally for all reporters.
bool IsEnabled(void)
Indicates whether application usage statistics collection is enabled for a current reporter instance.
CNcbiIstream & NcbiGetlineEOL(CNcbiIstream &is, string &str, string::size_type *count=NULL)
Read from "is" to "str" the next line (taking into account platform specifics of End-of-Line)
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
static bool StringToBool(const CTempString str)
Convert string to bool.
Definition: ncbistr.cpp:2821
#define kEmptyStr
Definition: ncbistr.hpp:123
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
#define NPOS
Definition: ncbistr.hpp:133
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static string & ToUpper(string &str)
Convert string to upper case – string& version.
Definition: ncbistr.cpp:424
@ fConvErr_NoThrow
Do not throw an exception on error.
Definition: ncbistr.hpp:285
EIPRangeType t
Definition: ncbi_localip.c:101
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
std::istream & in(std::istream &in_, double &x_)
void abort()
Modified on Wed Apr 17 13:10:09 2024 by modify_doxy.py rev. 669887