CONFIG['MYSQL']['database'] = os.getenv("BUILDMONITOR_NAME")
print '[CONFIG] mysql - load getenv.\n'
+ print CONFIG
+
+
test_data = os.getenv('file0')
if test_data:
- f = open( 'file0', 'r')
+ f = open('file0', 'r')
TEST_DATA = unicode_to_str(json.loads(f.read()))
f.close()
else:
sys.exit( "[Error] TRBS_DATA is empty!\n" )
- print '[TEST_DATA] load TRBS_DATA.\n'
+ print '[TEST_DATA] load TEST_DATA.\n'
print '===========[ TEST DATA ]===========\n'
print TEST_DATA
-
# Connect MySQL
MYSQL['connection'] = MySQLdb.connect( host =CONFIG['MYSQL']['host'],
user =CONFIG['MYSQL']['user'],
MYSQL['query']['insert_application_info'] = "INSERT INTO application_info (name, app_id, pkg_id, app_type) SELECT '%s', '%s', '%s', '%s' FROM DUAL WHERE NOT EXISTS ( SELECT * FROM application_info WHERE app_id='%s' AND pkg_id='%s' );" % (pkg_id, app_id, pkg_id, app_type, app_id, pkg_id)
mysql_excute_query(MYSQL['connection'], MYSQL['cursor'], MYSQL['query']['insert_application_info'])
- # get launching_performance_test_id
+ # get launching_performance_test_id
# MYSQL['query']['select_launching_performance_test'] = "SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name = 'launching_performance_test' AND table_schema = DATABASE( ) ;"
# mysql_excute_query(MYSQL['connection'], MYSQL['cursor'], MYSQL['query']['select_launching_performance_test'])
# launching_performance_test_id = MYSQL['cursor'].fetchone()['AUTO_INCREMENT']
MYSQL['query']['insert_launching_performance_test'] = "INSERT INTO launching_performance_test (build_image_id, average_time, test_date) SELECT %s, %s, FROM_UNIXTIME(UNIX_TIMESTAMP()) FROM DUAL WHERE NOT EXISTS ( SELECT * FROM launching_performance_test WHERE build_image_id=%s AND average_time=%s );" % (build_image_id, average_time, build_image_id, average_time)
# MYSQL['query']['insert_launching_performance_test'] = "INSERT INTO launching_performance_test (build_image_id, average_time, test_date) VALUES (%s, %s, FROM_UNIXTIME(UNIX_TIMESTAMP()) );" % (build_image_id, average_time)
mysql_excute_query(MYSQL['connection'], MYSQL['cursor'], MYSQL['query']['insert_launching_performance_test'])
-
- # get launching_performance_test_id
+
+ # get launching_performance_test_id
MYSQL['query']['select_launching_performance_test'] = "SELECT id FROM launching_performance_test WHERE build_image_id=%s AND average_time=%s;" % (build_image_id, average_time)
mysql_excute_query(MYSQL['connection'], MYSQL['cursor'], MYSQL['query']['select_launching_performance_test'])
launching_performance_test_id = MYSQL['cursor'].fetchone()['id']
app_info_ids[row['app_id']] = row['id']
row = MYSQL['cursor'].fetchone()
print 'app_info_ids: ', app_info_ids
-
+
launching_performance_list = TEST_DATA['launching_performance']
for launching_performance in launching_performance_list:
# application_info_id = MYSQL['cursor'].fetchone()['id']
# print "[Write] application_info id =", application_info_id
- MYSQL['query']['insert_launching_performance'] = "INSERT INTO launching_performance (launching_performance_test_id, build_image_id, application_info_id, launching_time) VALUES (%s, %s, %s, %s);" % (launching_performance_test_id, build_image_id, application_info_id, launching_time)
+ MYSQL['query']['insert_launching_performance'] = "INSERT INTO launching_performance (launching_performance_test_id, build_image_id, application_info_id, launching_time) SELECT %s, %s, %s, %s FROM DUAL WHERE NOT EXISTS ( SELECT * FROM launching_performance WHERE launching_performance_test_id=%s AND application_info_id=%s );" % (launching_performance_test_id, build_image_id, application_info_id, launching_time, launching_performance_test_id, application_info_id)
+# MYSQL['query']['insert_launching_performance'] = "INSERT INTO launching_performance (launching_performance_test_id, build_image_id, application_info_id, launching_time) VALUES (%s, %s, %s, %s);" % (launching_performance_test_id, build_image_id, application_info_id, launching_time)
mysql_excute_query(MYSQL['connection'], MYSQL['cursor'], MYSQL['query']['insert_launching_performance'])
-
+
+ ### insert memory usage data ###
+ # get launching_memory_usage_test_id
+# MYSQL['query']['select_launching_memory_usage_test'] = "SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name = 'launching_memory_usage_test' AND table_schema = DATABASE( ) ;"
+# mysql_excute_query(MYSQL['connection'], MYSQL['cursor'], MYSQL['query']['select_launching_memory_usage_test'])
+# launching_memory_usage_test_id = MYSQL['cursor'].fetchone()['AUTO_INCREMENT']
+# print "[Write] launching_memory_usage_test id =", launching_memory_usage_test_id
+
+ # insert launching_memory_usage_test
+ memory_usage_sum = TEST_DATA['memory_sum']
+ app_count = TEST_DATA['memory_count']
+ average_memory_usage = memory_usage_sum / app_count
+ MYSQL['query']['insert_launching_memory_usage_test'] = "INSERT INTO launching_memory_usage_test (build_image_id, average_memory_usage, memory_usage_sum, app_count, test_date) SELECT %s, %s, %s, %s, FROM_UNIXTIME(UNIX_TIMESTAMP()) FROM DUAL WHERE NOT EXISTS ( SELECT * FROM launching_memory_usage_test WHERE build_image_id=%s AND average_memory_usage=%s );" % (build_image_id, average_memory_usage, memory_usage_sum, app_count, build_image_id, average_memory_usage)
+ mysql_excute_query(MYSQL['connection'], MYSQL['cursor'], MYSQL['query']['insert_launching_memory_usage_test'])
+
+ # get launching_memory_usage_test_id
+ MYSQL['query']['select_launching_memory_usage_test'] = "SELECT id FROM launching_memory_usage_test WHERE build_image_id=%s AND average_memory_usage=%s;" % (build_image_id, average_memory_usage)
+ mysql_excute_query(MYSQL['connection'], MYSQL['cursor'], MYSQL['query']['select_launching_memory_usage_test'])
+ launching_memory_usage_test_id = MYSQL['cursor'].fetchone()['id']
+ print "[Write] launching_memory_usage_test id =", launching_memory_usage_test_id
+
+
+ # insert launching memory usage and insert launching memory object
+ launching_memory_list = TEST_DATA['memory_performance']
+ for launching_memory in launching_memory_list:
+ usage = launching_memory['usage']
+ pss = launching_memory['pss']
+ memory_3d = launching_memory['3d']
+ gem = launching_memory['gem']
+ app_id = launching_memory['app_id']
+ pkg_id = launching_memory['pkg_id']
+ application_info_id = app_info_ids[app_id]
+
+ MYSQL['query']['select_launching_memory_usage'] = "SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name = 'launching_memory_usage' AND table_schema = DATABASE( ) ;"
+ mysql_excute_query(MYSQL['connection'], MYSQL['cursor'], MYSQL['query']['select_launching_memory_usage'])
+ launching_memory_usage_id = MYSQL['cursor'].fetchone()['AUTO_INCREMENT']
+
+ MYSQL['query']['insert_launching_memory_usage'] = "INSERT INTO launching_memory_usage (launching_memory_usage_test_id, build_image_id, application_info_id, memory_usage, pss, 3d, gem) SELECT %s, %s, %s, %s, %s, %s, %s FROM DUAL WHERE NOT EXISTS ( SELECT * FROM launching_memory_usage WHERE launching_memory_usage_test_id=%s AND application_info_id=%s );" % (launching_memory_usage_test_id, build_image_id, application_info_id, usage, pss, memory_3d, gem, launching_memory_usage_test_id, application_info_id)
+# MYSQL['query']['insert_launching_memory_usage'] = "INSERT INTO launching_memory_usage (launching_memory_usage_test_id, build_image_id, application_info_id, memory_usage, pss, 3d, gem) VALUES (%s, %s, %s, %s, %s, %s, %s);" % (launching_memory_usage_test_id, build_image_id, application_info_id, usage, pss, memory_3d, gem)
+ mysql_excute_query(MYSQL['connection'], MYSQL['cursor'], MYSQL['query']['insert_launching_memory_usage'])
+
+ object_memory_list = launching_memory['app_memory_list']
+ for object_memory in object_memory_list:
+ object_name = object_memory['object_name']
+ pcode_pdata = object_memory['pcode_pdata']
+
+ MYSQL['query']['insert_launching_memory_object'] = "INSERT INTO launching_memory_object (launching_memory_usage_test_id, launching_memory_usage_id, build_image_id, application_info_id, object_name, pcode_pdata) VALUES (%s, %s, %s, %s, '%s', %s);" % (launching_memory_usage_test_id, launching_memory_usage_id, build_image_id, application_info_id, object_name, pcode_pdata)
+ mysql_excute_query(MYSQL['connection'], MYSQL['cursor'], MYSQL['query']['insert_launching_memory_object'])
+
MYSQL['cursor'].close()
MYSQL['connection'].close()