Browse Source

Add profiling information and split of the "get_elements_typed_by"

Yentl Van Tendeloo 8 years ago
parent
commit
210814e12e
3 changed files with 31 additions and 6 deletions
  1. 1 4
      bootstrap/object_operations.alc
  2. 29 2
      bootstrap/typing.alc
  3. 1 0
      interface/HUTN/includes/typing.alh

+ 1 - 4
bootstrap/object_operations.alc

@@ -17,12 +17,9 @@ Element function allInstances(model : Element, type_name : String):
 		result = set_create()
 		accepted = get_subclasses(model["metamodel"], type_name)
 
-		Element dict_mapping
-		dict_mapping = get_type_mapping_as_dict(model)
-
 		while (set_len(accepted) > 0):
 			class = set_pop(accepted)
-			set_merge(result, reverseKeyLookupMulti(dict_mapping, class))
+			set_merge(result, elements_typed_by(model, class))
 		return result!
 	else:
 		log("No such type in the metamodel: " + type_name)

+ 29 - 2
bootstrap/typing.alc

@@ -9,6 +9,9 @@ Void function set_type_mapping(model : Element, type_mapping : Element):
 	return!
 
 Element function get_type_mapping_as_dict(model : Element):
+	Float start
+	start = time()
+
 	Element dict
 	Element keys
 	String key
@@ -29,13 +32,18 @@ Element function get_type_mapping_as_dict(model : Element):
 			// So add it
 			dict_add_fast(dict, rev_model[cast_id2s(read_edge_src(model["type_mapping"][key]))], rev_metamodel[cast_id2s(read_edge_dst(model["type_mapping"][key]))])
 
+	log("get_type_mapping_as_dict : 0.0 : " + cast_v2s(time() - start))
 	return dict!
 
 String function read_type(model : Element, name : String):
+	Float start
+	start = time()
+
 	Element m_element
 	Element link
 	Integer nr
 	Element mm_element
+	Element result
 
 	if (dict_in(model["model"], name)):
 		m_element = model["model"][name]
@@ -50,14 +58,19 @@ String function read_type(model : Element, name : String):
 					// Now follow the edge to the type
 					mm_element = read_edge_dst(link)
 
-					return reverseKeyLookup(model["metamodel"]["model"], mm_element)!
+					result = reverseKeyLookup(model["metamodel"]["model"], mm_element)
+					log("read_type : 0.0 : " + cast_v2s(time() - start))
+					return result!
 			nr = nr - 1
 
 	// Nothing found, so it must not be typed at all
+	log("read_type : 0.0 : " + cast_v2s(time() - start))
 	return ""!
 
 Void function retype(model : Element, element : String, type : String):
 	// Remove previous type
+	Float start
+	start = time()
 	remove_type(model, element)
 
 	// Add element of the model
@@ -73,7 +86,8 @@ Void function retype(model : Element, element : String, type : String):
 	Element new_edge
 	new_edge = create_edge(model["model"][element], type_entry)
 	dict_add_fast(model["type_mapping"], cast_id2s(new_edge), new_edge)
-
+	
+	log("retype : 0.0 : " + cast_v2s(time() - start))
 	return!
 
 Void function new_type_mapping(model : Element):
@@ -85,10 +99,23 @@ Void function new_type_mapping(model : Element):
 	return !
 
 Void function remove_type(model : Element, name : String):
+	Float start
+	start = time()
 	String elem
 
 	elem = cast_id2s(model["model"][name])
 	if (dict_in(model["type_mapping"], elem)):
 		dict_delete(model["type_mapping"], elem)
 
+	log("remove_type : 0.0 : " + cast_v2s(time() - start))
 	return !
+
+Element function elements_typed_by(model : Element, type_name : String):
+	Float start
+	Element result
+	start = time()
+
+	result = reverseKeyLookupMulti(get_type_mapping_as_dict(model), type_name)
+
+	log("elements_typed_by : 0.0 : " + cast_v2s(time() - start))
+	return result!

+ 1 - 0
interface/HUTN/includes/typing.alh

@@ -5,3 +5,4 @@ Void function new_type_mapping(model : Element)
 Void function remove_type(model : Element, name : String)
 Void function set_type_mapping(model : Element, type_mapping : Element)
 Element function get_type_mapping(model : Element)
+Element function elements_typed_by(model : Element, type_name : String)